1
1
import { PowerSavingsManager } from "nativescript-task-dispatcher/internal/tasks/schedulers/time-based/android/alarms/power-savings-manager.android" ;
2
- import { createOsForegroundActivityMock } from "~/tests/internal/tasks/schedulers/time-based/android/index" ;
3
- import { Utils } from "@nativescript/core" ;
4
- import {
5
- createSavingsDeactivationIntent
6
- } from "nativescript-task-dispatcher/internal/tasks/schedulers/time-based/android/intents.android" ;
2
+ import { createOsForegroundActivityMock , isSdkBelow } from "./index" ;
3
+ import { Utils } from "@nativescript/core" ;
4
+ import { createSavingsDeactivationIntent } from "nativescript-task-dispatcher/internal/tasks/schedulers/time-based/android/intents.android" ;
7
5
8
6
describe ( "Power savings manager" , ( ) => {
9
7
if ( typeof android === "undefined" ) {
@@ -14,31 +12,43 @@ describe("Power savings manager", () => {
14
12
const foregroundActivityMock = createOsForegroundActivityMock ( ) ;
15
13
16
14
beforeEach ( ( ) => {
17
- spyOn ( powerManagerMock , "isIgnoringBatteryOptimizations" ) . and . returnValue ( false ) ;
15
+ spyOn (
16
+ powerManagerMock ,
17
+ "isIgnoringBatteryOptimizations"
18
+ ) . and . returnValue ( false ) ;
18
19
spyOn ( foregroundActivityMock , "startActivity" ) ;
19
20
} ) ;
20
21
21
- it ( "checks if power savings are enabled" , ( ) => {
22
- const powerSavingsManager = new PowerSavingsManager ( powerManagerMock ) ;
22
+ it ( "savings are disabled by default when api level is lower than 23" , ( ) => {
23
+ const powerSavingsManager = new PowerSavingsManager (
24
+ powerManagerMock ,
25
+ 22
26
+ ) ;
23
27
24
28
const areDisabled = powerSavingsManager . areDisabled ( ) ;
25
29
26
- expect ( areDisabled ) . toBeFalse ( ) ;
30
+ expect ( areDisabled ) . toBeTruthy ( ) ;
27
31
expect (
28
32
powerManagerMock . isIgnoringBatteryOptimizations
29
- ) . toHaveBeenCalled ( ) ;
33
+ ) . not . toHaveBeenCalled ( ) ;
30
34
} ) ;
31
35
32
- it ( "returns true by default when api level is lower than 23" , ( ) => {
33
- const powerSavingsManager = new PowerSavingsManager ( powerManagerMock , 22 ) ;
36
+ it ( "checks if power savings are enabled" , ( ) => {
37
+ if ( isSdkBelow ( 23 ) ) return ;
38
+
39
+ const powerSavingsManager = new PowerSavingsManager ( powerManagerMock ) ;
34
40
35
41
const areDisabled = powerSavingsManager . areDisabled ( ) ;
36
42
37
- expect ( areDisabled ) . toBeTruthy ( ) ;
38
- expect ( powerManagerMock . isIgnoringBatteryOptimizations ) . not . toHaveBeenCalled ( ) ;
43
+ expect ( areDisabled ) . toBeFalse ( ) ;
44
+ expect (
45
+ powerManagerMock . isIgnoringBatteryOptimizations
46
+ ) . toHaveBeenCalled ( ) ;
39
47
} ) ;
40
48
41
49
it ( "requests to disable savings when it has to" , ( ) => {
50
+ if ( isSdkBelow ( 23 ) ) return ;
51
+
42
52
const powerSavingsManager = new PowerSavingsManager (
43
53
powerManagerMock ,
44
54
android . os . Build . VERSION . SDK_INT ,
0 commit comments