Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[battery] Remove deprecated isSupported #7206

Merged
merged 3 commits into from May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
152 changes: 74 additions & 78 deletions apps/test-suite/tests/Battery.js
@@ -1,100 +1,96 @@
import { Platform } from '@unimodules/core';
import * as Battery from 'expo-battery';
import * as Device from 'expo-device';
import { Platform } from '@unimodules/core';

export const name = 'Battery';

export async function test({ describe, it, expect, jasmine }) {
const isExpectedToSupport = Device.isDevice || Platform.OS === 'android';

describe(`isAvailableAsync`, () => {
it(
isExpectedToSupport
? `should be true for Android or iOS devices`
: `should be false on iOS simulator`,
async () => {
expect(await Battery.isAvailableAsync()).toEqual(isExpectedToSupport);
}
);
});

describe(`isSupported (deprecated)`, () => {
it('should be equal to the result of isAvailableAsync()', async () => {
expect(await Battery.isAvailableAsync()).toEqual(Battery.isSupported);
describe('Battery', async () => {
describe(`isAvailableAsync`, () => {
it(
isExpectedToSupport
? `should be true for Android or iOS devices`
: `should be false on iOS simulator`,
async () => {
expect(await Battery.isAvailableAsync()).toEqual(isExpectedToSupport);
}
);
});
});

const isAvailable = await Battery.isAvailableAsync();
const isAvailable = await Battery.isAvailableAsync();

if (isAvailable) {
describe(`getBatteryLevelAsync()`, () => {
it(`returns a number between 0 and 1`, async () => {
let batteryLevel = await Battery.getBatteryLevelAsync();
expect(batteryLevel).toEqual(jasmine.any(Number));
expect(batteryLevel).toBeLessThanOrEqual(1);
expect(batteryLevel).toBeGreaterThan(0);
if (isAvailable) {
describe(`getBatteryLevelAsync()`, () => {
it(`returns a number between 0 and 1`, async () => {
let batteryLevel = await Battery.getBatteryLevelAsync();
expect(batteryLevel).toEqual(jasmine.any(Number));
expect(batteryLevel).toBeLessThanOrEqual(1);
expect(batteryLevel).toBeGreaterThan(0);
});
});
});
describe(`getBatteryState()`, () => {
it(`returns a valid BatteryState enum value`, async () => {
const batteryState = await Battery.getBatteryStateAsync();
expect(
[
Battery.BatteryState.CHARGING,
Battery.BatteryState.FULL,
Battery.BatteryState.UNPLUGGED,
].includes(batteryState)
).toBe(true);
describe(`getBatteryState()`, () => {
it(`returns a valid BatteryState enum value`, async () => {
const batteryState = await Battery.getBatteryStateAsync();
expect(
[
Battery.BatteryState.CHARGING,
Battery.BatteryState.FULL,
Battery.BatteryState.UNPLUGGED,
].includes(batteryState)
).toBe(true);
});
});
});
describe(`isLowPowerModeEnabledAsync()`, () => {
it(`returns a boolean low power mode`, async () => {
const lowPowerMode = await Battery.isLowPowerModeEnabledAsync();
expect(lowPowerMode).toEqual(jasmine.any(Boolean));
describe(`isLowPowerModeEnabledAsync()`, () => {
it(`returns a boolean low power mode`, async () => {
const lowPowerMode = await Battery.isLowPowerModeEnabledAsync();
expect(lowPowerMode).toEqual(jasmine.any(Boolean));
});
});
});
describe(`getPowerStateAsync()`, () => {
it(`returns a valid PowerState object`, async () => {
const powerState = await Battery.getPowerStateAsync();
expect(powerState).toEqual(
jasmine.objectContaining({
batteryLevel: jasmine.any(Number),
batteryState: jasmine.any(Number),
lowPowerMode: jasmine.any(Boolean),
})
);
describe(`getPowerStateAsync()`, () => {
it(`returns a valid PowerState object`, async () => {
const powerState = await Battery.getPowerStateAsync();
expect(powerState).toEqual(
jasmine.objectContaining({
batteryLevel: jasmine.any(Number),
batteryState: jasmine.any(Number),
lowPowerMode: jasmine.any(Boolean),
})
);
});
});
});

describe(`Event listeners`, () => {
// TODO(Bacon) Add detox & spies
// TODO: check that events don't get fired after we unsubscribe
// but we currently don't have a way to programmatically set battery statuses
describe(`Event listeners`, () => {
// TODO(Bacon) Add detox & spies
// TODO: check that events don't get fired after we unsubscribe
// but we currently don't have a way to programmatically set battery statuses

it(`addLowPowerModeListener() registers`, () => {
const listener = Battery.addLowPowerModeListener(({ lowPowerMode }) => {
console.log('powerMode changed!', lowPowerMode);
it(`addLowPowerModeListener() registers`, () => {
const listener = Battery.addLowPowerModeListener(({ lowPowerMode }) => {
console.log('powerMode changed!', lowPowerMode);
});
// TODO: Invoke callback somehow
expect(listener).toBeDefined();
listener.remove();
});
// TODO: Invoke callback somehow
expect(listener).toBeDefined();
listener.remove();
});
it(`addBatteryStateListener() registers`, () => {
const listener = Battery.addBatteryStateListener(({ batteryState }) => {
console.log('batteryState changed!', batteryState);
it(`addBatteryStateListener() registers`, () => {
const listener = Battery.addBatteryStateListener(({ batteryState }) => {
console.log('batteryState changed!', batteryState);
});
// TODO: Invoke callback somehow
expect(listener).toBeDefined();
listener.remove();
});
// TODO: Invoke callback somehow
expect(listener).toBeDefined();
listener.remove();
});
it(`addBatteryLevelListener() registers`, () => {
const listener = Battery.addBatteryLevelListener(({ batteryLevel }) => {
console.log('batteryLevel changed!', batteryLevel);
it(`addBatteryLevelListener() registers`, () => {
const listener = Battery.addBatteryLevelListener(({ batteryLevel }) => {
console.log('batteryLevel changed!', batteryLevel);
});
// TODO: Invoke callback somehow
expect(listener).toBeDefined();
listener.remove();
});
// TODO: Invoke callback somehow
expect(listener).toBeDefined();
listener.remove();
});
});
}
}
});
}
2 changes: 2 additions & 0 deletions packages/expo-battery/CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@

### 🛠 Breaking changes

- Removed deprecated `isSupported` method. ([#7206](https://github.com/expo/expo/pull/7206) by [@bbarthec](https://github.com/bbarthec))

### 🎉 New features

### 🐛 Bug fixes
4 changes: 0 additions & 4 deletions packages/expo-battery/build/Battery.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 1 addition & 16 deletions packages/expo-battery/build/Battery.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-battery/build/Battery.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 1 addition & 21 deletions packages/expo-battery/src/Battery.ts
@@ -1,4 +1,4 @@
import { EventEmitter, Subscription, deprecate } from '@unimodules/core';
import { EventEmitter, Subscription } from '@unimodules/core';

import {
BatteryLevelEvent,
Expand All @@ -14,26 +14,6 @@ import ExpoBattery from './ExpoBattery';

const BatteryEventEmitter = new EventEmitter(ExpoBattery);

/**
* Deprecated
*/
export declare const isSupported: boolean;
if (typeof module !== 'undefined' && module.exports) {
Object.defineProperties(module.exports, {
isSupported: {
enumerable: true,
get() {
deprecate('expo-battery', 'Battery.isSupported', {
replacement: 'Battery.isAvailableAsync',
currentVersion: require('../package.json').version,
versionToRemove: '3.0.0',
});
return (ExpoBattery && ExpoBattery.isSupported) || false;
},
},
});
}

export async function isAvailableAsync(): Promise<boolean> {
return Promise.resolve((ExpoBattery && ExpoBattery.isSupported) || false);
}
Expand Down