@ray-js/lamp-schedule-core 1.0.0-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +565 -0
- package/lib/config/dpCodes.d.ts +27 -0
- package/lib/config/dpCodes.js +30 -0
- package/lib/config/index.d.ts +2 -0
- package/lib/config/index.js +2 -0
- package/lib/config/rhythms/defaultValue.d.ts +18 -0
- package/lib/config/rhythms/defaultValue.js +72 -0
- package/lib/config/rhythms/index.d.ts +10 -0
- package/lib/config/rhythms/index.js +35 -0
- package/lib/conflict/ConflictResolver.d.ts +2 -0
- package/lib/conflict/ConflictResolver.js +284 -0
- package/lib/conflict/__test__/ConflictResolver.test.d.ts +1 -0
- package/lib/conflict/__test__/ConflictResolver.test.js +183 -0
- package/lib/conflict/__test__/index.test.d.ts +1 -0
- package/lib/conflict/__test__/index.test.js +385 -0
- package/lib/conflict/__test__/scheduleDataManager.test.d.ts +1 -0
- package/lib/conflict/__test__/scheduleDataManager.test.js +170 -0
- package/lib/conflict/__test__/transform.test.d.ts +1 -0
- package/lib/conflict/__test__/transform.test.js +454 -0
- package/lib/conflict/__test__/updateDeviceDp.d.ts +1 -0
- package/lib/conflict/__test__/updateDeviceDp.js +114 -0
- package/lib/conflict/index.d.ts +42 -0
- package/lib/conflict/index.js +103 -0
- package/lib/conflict/scheduleDataManager.d.ts +12 -0
- package/lib/conflict/scheduleDataManager.js +79 -0
- package/lib/conflict/transform.d.ts +71 -0
- package/lib/conflict/transform.js +251 -0
- package/lib/conflict/type.d.ts +55 -0
- package/lib/conflict/type.js +17 -0
- package/lib/conflict/updateDeviceDp.d.ts +1 -0
- package/lib/conflict/updateDeviceDp.js +41 -0
- package/lib/constant/index.d.ts +5 -0
- package/lib/constant/index.js +5 -0
- package/lib/context/index.d.ts +3 -0
- package/lib/context/index.js +3 -0
- package/lib/context/rhythms/actions.d.ts +20 -0
- package/lib/context/rhythms/actions.js +52 -0
- package/lib/context/rhythms/index.d.ts +5 -0
- package/lib/context/rhythms/index.js +51 -0
- package/lib/context/rhythms/reducer.d.ts +24 -0
- package/lib/context/rhythms/reducer.js +38 -0
- package/lib/context/schedule/actions.d.ts +7 -0
- package/lib/context/schedule/actions.js +51 -0
- package/lib/context/schedule/context.d.ts +6 -0
- package/lib/context/schedule/context.js +52 -0
- package/lib/context/schedule/index.d.ts +1 -0
- package/lib/context/schedule/index.js +1 -0
- package/lib/context/schedule/reducer.d.ts +16 -0
- package/lib/context/schedule/reducer.js +104 -0
- package/lib/context/schedule/type.d.ts +41 -0
- package/lib/context/schedule/type.js +11 -0
- package/lib/context/timer/actions.d.ts +8 -0
- package/lib/context/timer/actions.js +52 -0
- package/lib/context/timer/context.d.ts +10 -0
- package/lib/context/timer/context.js +53 -0
- package/lib/context/timer/index.d.ts +1 -0
- package/lib/context/timer/index.js +1 -0
- package/lib/context/timer/reducer.d.ts +15 -0
- package/lib/context/timer/reducer.js +70 -0
- package/lib/context/timer/type.d.ts +46 -0
- package/lib/context/timer/type.js +24 -0
- package/lib/dpParser/README.md +63 -0
- package/lib/dpParser/__test__/cycle.test.d.ts +1 -0
- package/lib/dpParser/__test__/cycle.test.js +258 -0
- package/lib/dpParser/__test__/random.test.d.ts +1 -0
- package/lib/dpParser/__test__/random.test.js +211 -0
- package/lib/dpParser/__test__/rhythms.test.d.ts +1 -0
- package/lib/dpParser/__test__/rhythms.test.js +71 -0
- package/lib/dpParser/__test__/rtcTimer.test.d.ts +1 -0
- package/lib/dpParser/__test__/rtcTimer.test.js +235 -0
- package/lib/dpParser/__test__/sleep.test.d.ts +1 -0
- package/lib/dpParser/__test__/sleep.test.js +71 -0
- package/lib/dpParser/__test__/sleepCommon.test.d.ts +1 -0
- package/lib/dpParser/__test__/sleepCommon.test.js +197 -0
- package/lib/dpParser/__test__/timerReport.test.d.ts +1 -0
- package/lib/dpParser/__test__/timerReport.test.js +100 -0
- package/lib/dpParser/__test__/wakeup.test.d.ts +1 -0
- package/lib/dpParser/__test__/wakeup.test.js +69 -0
- package/lib/dpParser/__test__/wakeupCommon.test.d.ts +1 -0
- package/lib/dpParser/__test__/wakeupCommon.test.js +131 -0
- package/lib/dpParser/cycle/index.d.ts +15 -0
- package/lib/dpParser/cycle/index.js +134 -0
- package/lib/dpParser/index.d.ts +23 -0
- package/lib/dpParser/index.js +43 -0
- package/lib/dpParser/random/index.d.ts +15 -0
- package/lib/dpParser/random/index.js +127 -0
- package/lib/dpParser/rhythms.d.ts +41 -0
- package/lib/dpParser/rhythms.js +116 -0
- package/lib/dpParser/rtcTimer.d.ts +17 -0
- package/lib/dpParser/rtcTimer.js +300 -0
- package/lib/dpParser/sleep/index.d.ts +9 -0
- package/lib/dpParser/sleep/index.js +29 -0
- package/lib/dpParser/sleep/sleepCommon.d.ts +11 -0
- package/lib/dpParser/sleep/sleepCommon.js +117 -0
- package/lib/dpParser/sleep/sleepSigmesh.d.ts +0 -0
- package/lib/dpParser/sleep/sleepSigmesh.js +101 -0
- package/lib/dpParser/timerReport.d.ts +11 -0
- package/lib/dpParser/timerReport.js +43 -0
- package/lib/dpParser/utils.d.ts +27 -0
- package/lib/dpParser/utils.js +53 -0
- package/lib/dpParser/wakeup/index.d.ts +10 -0
- package/lib/dpParser/wakeup/index.js +34 -0
- package/lib/dpParser/wakeup/wakeupCommon.d.ts +11 -0
- package/lib/dpParser/wakeup/wakeupCommon.js +106 -0
- package/lib/dpParser/wakeup/wakeupSigmesh.d.ts +15 -0
- package/lib/dpParser/wakeup/wakeupSigmesh.js +86 -0
- package/lib/hooks/__test__/useCommon.test.d.ts +1 -0
- package/lib/hooks/__test__/useCommon.test.js +72 -0
- package/lib/hooks/__test__/useCountdownDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useCountdownDp.test.js +82 -0
- package/lib/hooks/__test__/useCycleDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useCycleDp.test.js +92 -0
- package/lib/hooks/__test__/useRandomDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useRandomDp.test.js +88 -0
- package/lib/hooks/__test__/useRhythmsDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useRhythmsDp.test.js +81 -0
- package/lib/hooks/__test__/useSleepDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useSleepDp.test.js +127 -0
- package/lib/hooks/__test__/useTimeFlush.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimeFlush.test.js +109 -0
- package/lib/hooks/__test__/useTimerDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerDp.test.js +79 -0
- package/lib/hooks/__test__/useTimerOperate.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperate.test.js +286 -0
- package/lib/hooks/__test__/useTimerOperateCloud.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperateCloud.test.js +190 -0
- package/lib/hooks/__test__/useTimerOperateLocal.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperateLocal.test.js +216 -0
- package/lib/hooks/__test__/useTimerReportDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerReportDp.test.js +93 -0
- package/lib/hooks/__test__/useTimerSupport.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerSupport.test.js +110 -0
- package/lib/hooks/__test__/useWakeUpDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useWakeUpDp.test.js +129 -0
- package/lib/hooks/useBaseLightDp.d.ts +21 -0
- package/lib/hooks/useBaseLightDp.js +165 -0
- package/lib/hooks/useCommon.d.ts +29 -0
- package/lib/hooks/useCommon.js +59 -0
- package/lib/hooks/useCommonSupport.d.ts +25 -0
- package/lib/hooks/useCommonSupport.js +241 -0
- package/lib/hooks/useCountdownDp.d.ts +13 -0
- package/lib/hooks/useCountdownDp.js +28 -0
- package/lib/hooks/useCountdownSupport.d.ts +9 -0
- package/lib/hooks/useCountdownSupport.js +13 -0
- package/lib/hooks/useCycleDp.d.ts +7 -0
- package/lib/hooks/useCycleDp.js +21 -0
- package/lib/hooks/useCycleSupport.d.ts +12 -0
- package/lib/hooks/useCycleSupport.js +16 -0
- package/lib/hooks/useRandomDp.d.ts +7 -0
- package/lib/hooks/useRandomDp.js +21 -0
- package/lib/hooks/useRandomSupport.d.ts +12 -0
- package/lib/hooks/useRandomSupport.js +16 -0
- package/lib/hooks/useRhythmsDp.d.ts +7 -0
- package/lib/hooks/useRhythmsDp.js +23 -0
- package/lib/hooks/useSleepDp.d.ts +6 -0
- package/lib/hooks/useSleepDp.js +21 -0
- package/lib/hooks/useSleepSupport.d.ts +8 -0
- package/lib/hooks/useSleepSupport.js +13 -0
- package/lib/hooks/useTimeFlush.d.ts +8 -0
- package/lib/hooks/useTimeFlush.js +31 -0
- package/lib/hooks/useTimerDp.d.ts +5 -0
- package/lib/hooks/useTimerDp.js +25 -0
- package/lib/hooks/useTimerFlushList.d.ts +11 -0
- package/lib/hooks/useTimerFlushList.js +53 -0
- package/lib/hooks/useTimerOperate.d.ts +68 -0
- package/lib/hooks/useTimerOperate.js +403 -0
- package/lib/hooks/useTimerOperateCloud.d.ts +31 -0
- package/lib/hooks/useTimerOperateCloud.js +233 -0
- package/lib/hooks/useTimerOperateLocal.d.ts +40 -0
- package/lib/hooks/useTimerOperateLocal.js +310 -0
- package/lib/hooks/useTimerReportDp.d.ts +15 -0
- package/lib/hooks/useTimerReportDp.js +48 -0
- package/lib/hooks/useTimerSupport.d.ts +13 -0
- package/lib/hooks/useTimerSupport.js +38 -0
- package/lib/hooks/useWakeUpDp.d.ts +6 -0
- package/lib/hooks/useWakeUpDp.js +21 -0
- package/lib/hooks/useWakeUpSupport.d.ts +8 -0
- package/lib/hooks/useWakeUpSupport.js +13 -0
- package/lib/hooks/useWakeupDp.d.ts +6 -0
- package/lib/hooks/useWakeupDp.js +21 -0
- package/lib/hooks/useWakeupSupport.d.ts +8 -0
- package/lib/hooks/useWakeupSupport.js +13 -0
- package/lib/i18n/index.d.ts +142 -0
- package/lib/i18n/index.js +7 -0
- package/lib/i18n/rhythms.d.ts +73 -0
- package/lib/i18n/rhythms.js +72 -0
- package/lib/i18n/strings.d.ts +73 -0
- package/lib/i18n/strings.js +6 -0
- package/lib/index.d.ts +51 -0
- package/lib/index.js +64 -0
- package/lib/types/countdown.d.ts +3 -0
- package/lib/types/countdown.js +1 -0
- package/lib/types/cycle.d.ts +22 -0
- package/lib/types/cycle.js +1 -0
- package/lib/types/global.d.ts +9 -0
- package/lib/types/index.d.ts +331 -0
- package/lib/types/index.js +76 -0
- package/lib/types/random.d.ts +20 -0
- package/lib/types/random.js +1 -0
- package/lib/types/rhythms.d.ts +79 -0
- package/lib/types/rhythms.js +15 -0
- package/lib/types/sleep.d.ts +36 -0
- package/lib/types/sleep.js +1 -0
- package/lib/types/timer.d.ts +107 -0
- package/lib/types/timer.js +1 -0
- package/lib/types/wakeup.d.ts +38 -0
- package/lib/types/wakeup.js +1 -0
- package/lib/utils/ScheduleCache.d.ts +19 -0
- package/lib/utils/ScheduleCache.js +39 -0
- package/lib/utils/ScheduleCloudProperty.d.ts +75 -0
- package/lib/utils/ScheduleCloudProperty.js +220 -0
- package/lib/utils/ScheduleDataSync.d.ts +82 -0
- package/lib/utils/ScheduleDataSync.js +127 -0
- package/lib/utils/ScheduleEmit.d.ts +67 -0
- package/lib/utils/ScheduleEmit.js +61 -0
- package/lib/utils/ScheduleLogger.d.ts +19 -0
- package/lib/utils/ScheduleLogger.js +71 -0
- package/lib/utils/ScheduleSupport.d.ts +131 -0
- package/lib/utils/ScheduleSupport.js +373 -0
- package/lib/utils/ScheduleUtils.d.ts +12 -0
- package/lib/utils/ScheduleUtils.js +51 -0
- package/lib/utils/__test__/ScheduleCloudProperty.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleCloudProperty.test.js +320 -0
- package/lib/utils/__test__/ScheduleSupport.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleSupport.test.js +211 -0
- package/lib/utils/__test__/ScheduleUtils.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleUtils.test.js +119 -0
- package/lib/utils/__test__/common.test.d.ts +1 -0
- package/lib/utils/__test__/common.test.js +147 -0
- package/lib/utils/__test__/storage.test.d.ts +1 -0
- package/lib/utils/__test__/storage.test.js +98 -0
- package/lib/utils/__test__/time.test.d.ts +1 -0
- package/lib/utils/__test__/time.test.js +146 -0
- package/lib/utils/common.d.ts +23 -0
- package/lib/utils/common.js +109 -0
- package/lib/utils/dpState.d.ts +5 -0
- package/lib/utils/dpState.js +27 -0
- package/lib/utils/getCachedSystemInfo.d.ts +39 -0
- package/lib/utils/getCachedSystemInfo.js +20 -0
- package/lib/utils/isInIDE.d.ts +1 -0
- package/lib/utils/isInIDE.js +5 -0
- package/lib/utils/storage.d.ts +5 -0
- package/lib/utils/storage.js +32 -0
- package/lib/utils/time.d.ts +40 -0
- package/lib/utils/time.js +84 -0
- package/package.json +78 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import { renderHook, act } from '@testing-library/react-hooks';
|
|
3
|
+
import { useTimerAdd, useTimerAddWithFlush, useTimerUpdate, useTimerRemove, useTimerUpdateStatus } from '../useTimerOperate';
|
|
4
|
+
import { useSupportLocalTimer } from '../useTimerSupport';
|
|
5
|
+
import { useSupport } from '../useCommonSupport';
|
|
6
|
+
import { useTimerDp } from '../useTimerDp';
|
|
7
|
+
import { useTimerListFlush } from '../useTimeFlush';
|
|
8
|
+
import * as useTimerOperateLocal from '../useTimerOperateLocal';
|
|
9
|
+
import * as useTimerOperateCloud from '../useTimerOperateCloud';
|
|
10
|
+
import { CLOUD_TIMER_CATEGORY } from '../../constant';
|
|
11
|
+
import { getTimerState } from '../../context/timer';
|
|
12
|
+
|
|
13
|
+
// Mock dependencies
|
|
14
|
+
jest.mock('../useTimerSupport');
|
|
15
|
+
jest.mock('../useCommonSupport');
|
|
16
|
+
jest.mock('../useTimerDp');
|
|
17
|
+
jest.mock('../useTimeFlush');
|
|
18
|
+
jest.mock('../useTimerOperateCloud');
|
|
19
|
+
jest.mock('../useTimerOperateLocal');
|
|
20
|
+
jest.mock('../../context/timer', () => ({
|
|
21
|
+
getTimerState: jest.fn()
|
|
22
|
+
}));
|
|
23
|
+
const mockTimer = {
|
|
24
|
+
timerId: '1',
|
|
25
|
+
time: '12:00',
|
|
26
|
+
loops: '1,2,3',
|
|
27
|
+
status: true,
|
|
28
|
+
dps: {},
|
|
29
|
+
aliasName: 'Test Timer',
|
|
30
|
+
isAppPush: false
|
|
31
|
+
};
|
|
32
|
+
describe('useTimerOperate Hooks', () => {
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
jest.clearAllMocks();
|
|
35
|
+
useSupportLocalTimer.mockReturnValue({
|
|
36
|
+
isSupport: true,
|
|
37
|
+
isReady: true
|
|
38
|
+
});
|
|
39
|
+
useSupport.mockReturnValue({
|
|
40
|
+
isGroupDevice: () => false
|
|
41
|
+
});
|
|
42
|
+
useTimerDp.mockReturnValue({
|
|
43
|
+
updateDp: jest.fn()
|
|
44
|
+
});
|
|
45
|
+
useTimerListFlush.mockReturnValue({
|
|
46
|
+
flushTimerList: jest.fn(),
|
|
47
|
+
isReady: true
|
|
48
|
+
});
|
|
49
|
+
getTimerState.mockReturnValue({
|
|
50
|
+
rtcTimerList: [mockTimer]
|
|
51
|
+
});
|
|
52
|
+
useTimerOperateLocal.useLocalTimerAdd.mockReturnValue({
|
|
53
|
+
isLoading: false,
|
|
54
|
+
isSupportLocalTimer: true,
|
|
55
|
+
addTimer: jest.fn().mockResolvedValue(true)
|
|
56
|
+
});
|
|
57
|
+
useTimerOperateLocal.useLocalTimerUpdate.mockReturnValue({
|
|
58
|
+
isLoading: false,
|
|
59
|
+
isSupportLocalTimer: true,
|
|
60
|
+
updateTimer: jest.fn().mockResolvedValue(true)
|
|
61
|
+
});
|
|
62
|
+
useTimerOperateLocal.useLocalTimerRemove.mockReturnValue({
|
|
63
|
+
isLoading: false,
|
|
64
|
+
isSupportLocalTimer: true,
|
|
65
|
+
removeTimer: jest.fn().mockResolvedValue(true)
|
|
66
|
+
});
|
|
67
|
+
useTimerOperateLocal.useLocalTimerList.mockReturnValue({
|
|
68
|
+
isLoading: false,
|
|
69
|
+
isSupportLocalTimer: true,
|
|
70
|
+
getTimerList: jest.fn().mockResolvedValue({
|
|
71
|
+
timers: []
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
useTimerOperateLocal.useLocalTimerUpdateStatus.mockReturnValue({
|
|
75
|
+
isLoading: false,
|
|
76
|
+
isSupportLocalTimer: true,
|
|
77
|
+
updateTimerStatus: jest.fn().mockResolvedValue(true)
|
|
78
|
+
});
|
|
79
|
+
useTimerOperateCloud.useCloudTimerAdd.mockReturnValue({
|
|
80
|
+
isLoading: false,
|
|
81
|
+
isSupportLocalTimer: true,
|
|
82
|
+
addTimer: jest.fn().mockResolvedValue(true)
|
|
83
|
+
});
|
|
84
|
+
useTimerOperateCloud.useCloudTimerUpdate.mockReturnValue({
|
|
85
|
+
isLoading: false,
|
|
86
|
+
isSupportLocalTimer: true,
|
|
87
|
+
updateTimer: jest.fn().mockResolvedValue(true)
|
|
88
|
+
});
|
|
89
|
+
useTimerOperateCloud.useCloudTimerRemove.mockReturnValue({
|
|
90
|
+
isLoading: false,
|
|
91
|
+
isSupportLocalTimer: true,
|
|
92
|
+
removeTimer: jest.fn().mockResolvedValue(true)
|
|
93
|
+
});
|
|
94
|
+
useTimerOperateCloud.useCloudTimerList.mockReturnValue({
|
|
95
|
+
isLoading: false,
|
|
96
|
+
isSupportLocalTimer: true,
|
|
97
|
+
getTimerList: jest.fn().mockResolvedValue({
|
|
98
|
+
timers: []
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
useTimerOperateCloud.useCloudTimerUpdateStatus.mockReturnValue({
|
|
102
|
+
isLoading: false,
|
|
103
|
+
isSupportLocalTimer: true,
|
|
104
|
+
updateTimerStatus: jest.fn().mockResolvedValue(true)
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe('useTimerAdd', () => {
|
|
108
|
+
it('should handle local timer addition when supported', async () => {
|
|
109
|
+
const mockUpdateDp = jest.fn();
|
|
110
|
+
useTimerDp.mockReturnValue({
|
|
111
|
+
updateDp: mockUpdateDp
|
|
112
|
+
});
|
|
113
|
+
const {
|
|
114
|
+
result
|
|
115
|
+
} = renderHook(() => useTimerAdd());
|
|
116
|
+
await result.current.addTimer({
|
|
117
|
+
time: '12:00',
|
|
118
|
+
loops: '1111111',
|
|
119
|
+
dps: {
|
|
120
|
+
power: true
|
|
121
|
+
},
|
|
122
|
+
aliasName: 'Test Timer',
|
|
123
|
+
isAppPush: true
|
|
124
|
+
}, CLOUD_TIMER_CATEGORY);
|
|
125
|
+
expect(mockUpdateDp).toHaveBeenCalled();
|
|
126
|
+
});
|
|
127
|
+
it('should handle cloud timer addition when local timer not supported', async () => {
|
|
128
|
+
useSupportLocalTimer.mockReturnValue({
|
|
129
|
+
isSupport: false,
|
|
130
|
+
isReady: true
|
|
131
|
+
});
|
|
132
|
+
const {
|
|
133
|
+
result
|
|
134
|
+
} = renderHook(() => useTimerAdd());
|
|
135
|
+
const mockTimer = {
|
|
136
|
+
time: '12:00',
|
|
137
|
+
loops: '1111111',
|
|
138
|
+
dps: {
|
|
139
|
+
power: true
|
|
140
|
+
},
|
|
141
|
+
aliasName: 'Test Timer',
|
|
142
|
+
isAppPush: true
|
|
143
|
+
};
|
|
144
|
+
await act(async () => {
|
|
145
|
+
await result.current.addTimer(mockTimer, CLOUD_TIMER_CATEGORY);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Verify cloud timer addition was called
|
|
149
|
+
expect(result.current.isLoading).toBeDefined();
|
|
150
|
+
});
|
|
151
|
+
it('should add timer', async () => {
|
|
152
|
+
const {
|
|
153
|
+
result
|
|
154
|
+
} = renderHook(() => useTimerAdd());
|
|
155
|
+
const response = await result.current.addTimer(mockTimer, CLOUD_TIMER_CATEGORY);
|
|
156
|
+
expect(response).toBeTruthy();
|
|
157
|
+
});
|
|
158
|
+
it('should add cloud timer when device is in group', async () => {
|
|
159
|
+
useSupport.mockReturnValue({
|
|
160
|
+
isGroupDevice: () => true
|
|
161
|
+
});
|
|
162
|
+
const {
|
|
163
|
+
result
|
|
164
|
+
} = renderHook(() => useTimerAdd());
|
|
165
|
+
await result.current.addTimer(mockTimer, CLOUD_TIMER_CATEGORY);
|
|
166
|
+
expect(useTimerOperateCloud.useCloudTimerAdd).toHaveBeenCalled();
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
describe('useTimerAddWithFlush', () => {
|
|
170
|
+
it('should add timer and flush list', async () => {
|
|
171
|
+
const mockFlushTimerList = jest.fn();
|
|
172
|
+
jest.fn().mockResolvedValue({
|
|
173
|
+
timers: []
|
|
174
|
+
});
|
|
175
|
+
useTimerListFlush.mockReturnValue({
|
|
176
|
+
flushTimerList: mockFlushTimerList,
|
|
177
|
+
isReady: true
|
|
178
|
+
});
|
|
179
|
+
const {
|
|
180
|
+
result
|
|
181
|
+
} = renderHook(() => useTimerAddWithFlush());
|
|
182
|
+
const mockTimer = {
|
|
183
|
+
time: '12:00',
|
|
184
|
+
loops: '1111111',
|
|
185
|
+
dps: {
|
|
186
|
+
power: true
|
|
187
|
+
},
|
|
188
|
+
aliasName: 'Test Timer',
|
|
189
|
+
isAppPush: true
|
|
190
|
+
};
|
|
191
|
+
await act(async () => {
|
|
192
|
+
await result.current.addTimerWithFlush(mockTimer);
|
|
193
|
+
});
|
|
194
|
+
expect(mockFlushTimerList).toHaveBeenCalled();
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
describe('useTimerUpdate', () => {
|
|
198
|
+
it('should handle local timer update when supported', async () => {
|
|
199
|
+
const mockUpdateDp = jest.fn();
|
|
200
|
+
useTimerDp.mockReturnValue({
|
|
201
|
+
updateDp: mockUpdateDp
|
|
202
|
+
});
|
|
203
|
+
const {
|
|
204
|
+
result
|
|
205
|
+
} = renderHook(() => useTimerUpdate());
|
|
206
|
+
const mockTimer = {
|
|
207
|
+
timerId: '1',
|
|
208
|
+
time: '12:00',
|
|
209
|
+
loops: '1111111',
|
|
210
|
+
dps: {
|
|
211
|
+
power: true
|
|
212
|
+
},
|
|
213
|
+
aliasName: 'Test Timer',
|
|
214
|
+
isAppPush: true
|
|
215
|
+
};
|
|
216
|
+
await act(async () => {
|
|
217
|
+
await result.current.updateTimer(mockTimer, _objectSpread(_objectSpread({}, mockTimer), {}, {
|
|
218
|
+
status: false
|
|
219
|
+
}));
|
|
220
|
+
});
|
|
221
|
+
expect(mockUpdateDp).toHaveBeenCalled();
|
|
222
|
+
});
|
|
223
|
+
it('should update cloud timer when device is in group', async () => {
|
|
224
|
+
useSupport.mockReturnValue({
|
|
225
|
+
isGroupDevice: () => true
|
|
226
|
+
});
|
|
227
|
+
const {
|
|
228
|
+
result
|
|
229
|
+
} = renderHook(() => useTimerUpdate());
|
|
230
|
+
await result.current.updateTimer(mockTimer, _objectSpread(_objectSpread({}, mockTimer), {}, {
|
|
231
|
+
status: false
|
|
232
|
+
}));
|
|
233
|
+
expect(useTimerOperateCloud.useCloudTimerUpdate).toHaveBeenCalled();
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
describe('useTimerRemove', () => {
|
|
237
|
+
it('should handle local timer removal when supported', async () => {
|
|
238
|
+
const mockUpdateDp = jest.fn();
|
|
239
|
+
useTimerDp.mockReturnValue({
|
|
240
|
+
updateDp: mockUpdateDp
|
|
241
|
+
});
|
|
242
|
+
const {
|
|
243
|
+
result
|
|
244
|
+
} = renderHook(() => useTimerRemove());
|
|
245
|
+
await act(async () => {
|
|
246
|
+
await result.current.removeTimer('1');
|
|
247
|
+
});
|
|
248
|
+
expect(mockUpdateDp).toHaveBeenCalled();
|
|
249
|
+
});
|
|
250
|
+
it('should remove cloud timer when device is in group', async () => {
|
|
251
|
+
useSupport.mockReturnValue({
|
|
252
|
+
isGroupDevice: () => true
|
|
253
|
+
});
|
|
254
|
+
const {
|
|
255
|
+
result
|
|
256
|
+
} = renderHook(() => useTimerRemove());
|
|
257
|
+
await result.current.removeTimer('1');
|
|
258
|
+
expect(useTimerOperateCloud.useCloudTimerRemove).toHaveBeenCalled();
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
describe('useTimerUpdateStatus', () => {
|
|
262
|
+
it('should handle local timer status update when supported', async () => {
|
|
263
|
+
const mockUpdateDp = jest.fn();
|
|
264
|
+
useTimerDp.mockReturnValue({
|
|
265
|
+
updateDp: mockUpdateDp
|
|
266
|
+
});
|
|
267
|
+
const {
|
|
268
|
+
result
|
|
269
|
+
} = renderHook(() => useTimerUpdateStatus());
|
|
270
|
+
await act(async () => {
|
|
271
|
+
await result.current.updateTimerStatus('1', true);
|
|
272
|
+
});
|
|
273
|
+
expect(mockUpdateDp).toHaveBeenCalled();
|
|
274
|
+
});
|
|
275
|
+
it('should update cloud timer status when device is in group', async () => {
|
|
276
|
+
useSupport.mockReturnValue({
|
|
277
|
+
isGroupDevice: () => true
|
|
278
|
+
});
|
|
279
|
+
const {
|
|
280
|
+
result
|
|
281
|
+
} = renderHook(() => useTimerUpdateStatus());
|
|
282
|
+
await result.current.updateTimerStatus('1', true);
|
|
283
|
+
expect(useTimerOperateCloud.useCloudTimerUpdateStatus).toHaveBeenCalled();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { renderHook, act } from '@testing-library/react-hooks';
|
|
2
|
+
import { device } from '@ray-js/ray';
|
|
3
|
+
import { useCloudTimerAdd, useCloudTimerUpdate, useCloudTimerRemove, useCloudTimerList, useCloudTimerUpdateStatus } from '../useTimerOperateCloud';
|
|
4
|
+
import { CLOUD_TIMER_CATEGORY } from '../../constant';
|
|
5
|
+
// Mock dependencies
|
|
6
|
+
jest.mock('@ray-js/ray', () => ({
|
|
7
|
+
device: {
|
|
8
|
+
addTimer: jest.fn().mockImplementation(_ref => {
|
|
9
|
+
let {
|
|
10
|
+
success
|
|
11
|
+
} = _ref;
|
|
12
|
+
return success({
|
|
13
|
+
timerId: '1',
|
|
14
|
+
id: '1'
|
|
15
|
+
});
|
|
16
|
+
}),
|
|
17
|
+
removeTimer: jest.fn().mockImplementation(_ref2 => {
|
|
18
|
+
let {
|
|
19
|
+
success
|
|
20
|
+
} = _ref2;
|
|
21
|
+
return success();
|
|
22
|
+
}),
|
|
23
|
+
updateTimer: jest.fn().mockImplementation(_ref3 => {
|
|
24
|
+
let {
|
|
25
|
+
success
|
|
26
|
+
} = _ref3;
|
|
27
|
+
return success();
|
|
28
|
+
}),
|
|
29
|
+
syncTimerTask: jest.fn().mockImplementation(_ref4 => {
|
|
30
|
+
let {
|
|
31
|
+
success
|
|
32
|
+
} = _ref4;
|
|
33
|
+
return success({
|
|
34
|
+
timers: []
|
|
35
|
+
});
|
|
36
|
+
}),
|
|
37
|
+
updateTimerStatus: jest.fn().mockImplementation(_ref5 => {
|
|
38
|
+
let {
|
|
39
|
+
success
|
|
40
|
+
} = _ref5;
|
|
41
|
+
return success();
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
jest.mock('../../utils/ScheduleCache', () => ({
|
|
46
|
+
devIdOrGroupIdCache: {
|
|
47
|
+
get: jest.fn().mockReturnValue({
|
|
48
|
+
devId: 'test-device-id',
|
|
49
|
+
groupId: 'test-group-id'
|
|
50
|
+
}),
|
|
51
|
+
set: jest.fn()
|
|
52
|
+
},
|
|
53
|
+
getScheduleCache: jest.fn()
|
|
54
|
+
}));
|
|
55
|
+
describe('useTimerOperateCloud Hooks', () => {
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
jest.clearAllMocks();
|
|
58
|
+
});
|
|
59
|
+
describe('useCloudTimerAdd', () => {
|
|
60
|
+
it('should add cloud timer successfully', async () => {
|
|
61
|
+
const mockTimer = {
|
|
62
|
+
time: '12:00',
|
|
63
|
+
loops: '1111111',
|
|
64
|
+
dps: {
|
|
65
|
+
power: true
|
|
66
|
+
},
|
|
67
|
+
aliasName: 'Test Timer',
|
|
68
|
+
isAppPush: true
|
|
69
|
+
};
|
|
70
|
+
const {
|
|
71
|
+
result
|
|
72
|
+
} = renderHook(() => useCloudTimerAdd(false));
|
|
73
|
+
await act(async () => {
|
|
74
|
+
await result.current.addTimer(mockTimer, CLOUD_TIMER_CATEGORY);
|
|
75
|
+
});
|
|
76
|
+
expect(device.addTimer).toHaveBeenCalledWith({
|
|
77
|
+
category: CLOUD_TIMER_CATEGORY,
|
|
78
|
+
groupId: 'test-group-id',
|
|
79
|
+
timer: expect.objectContaining({
|
|
80
|
+
time: '12:00',
|
|
81
|
+
loops: '1111111'
|
|
82
|
+
}),
|
|
83
|
+
success: expect.any(Function),
|
|
84
|
+
fail: expect.any(Function)
|
|
85
|
+
});
|
|
86
|
+
}, 10000);
|
|
87
|
+
it('should handle add timer error', async () => {
|
|
88
|
+
const mockError = new Error('Add failed');
|
|
89
|
+
device.addTimer.mockImplementation(_ref6 => {
|
|
90
|
+
let {
|
|
91
|
+
fail
|
|
92
|
+
} = _ref6;
|
|
93
|
+
fail(mockError);
|
|
94
|
+
});
|
|
95
|
+
const {
|
|
96
|
+
result
|
|
97
|
+
} = renderHook(() => useCloudTimerAdd(false));
|
|
98
|
+
const mockTimer = {
|
|
99
|
+
time: '12:00',
|
|
100
|
+
loops: '1111111',
|
|
101
|
+
dps: {
|
|
102
|
+
power: true
|
|
103
|
+
},
|
|
104
|
+
aliasName: 'Test Timer',
|
|
105
|
+
isAppPush: true
|
|
106
|
+
};
|
|
107
|
+
await expect(act(async () => {
|
|
108
|
+
await result.current.addTimer(mockTimer, CLOUD_TIMER_CATEGORY);
|
|
109
|
+
})).rejects.toThrow('Add failed');
|
|
110
|
+
}, 10000);
|
|
111
|
+
});
|
|
112
|
+
describe('useCloudTimerUpdate', () => {
|
|
113
|
+
it('should update cloud timer successfully', async () => {
|
|
114
|
+
const mockTimer = {
|
|
115
|
+
timerId: '1',
|
|
116
|
+
time: '12:00',
|
|
117
|
+
loops: '1111111',
|
|
118
|
+
dps: {
|
|
119
|
+
power: true
|
|
120
|
+
},
|
|
121
|
+
aliasName: 'Test Timer',
|
|
122
|
+
isAppPush: true
|
|
123
|
+
};
|
|
124
|
+
const {
|
|
125
|
+
result
|
|
126
|
+
} = renderHook(() => useCloudTimerUpdate(false));
|
|
127
|
+
await act(async () => {
|
|
128
|
+
await result.current.updateTimer(mockTimer);
|
|
129
|
+
});
|
|
130
|
+
expect(device.updateTimer).toHaveBeenCalledWith({
|
|
131
|
+
groupId: 'test-group-id',
|
|
132
|
+
timer: expect.objectContaining({
|
|
133
|
+
timerId: '1',
|
|
134
|
+
time: '12:00'
|
|
135
|
+
}),
|
|
136
|
+
success: expect.any(Function),
|
|
137
|
+
fail: expect.any(Function)
|
|
138
|
+
});
|
|
139
|
+
}, 10000);
|
|
140
|
+
});
|
|
141
|
+
describe('useCloudTimerRemove', () => {
|
|
142
|
+
it('should remove cloud timer successfully', async () => {
|
|
143
|
+
const {
|
|
144
|
+
result
|
|
145
|
+
} = renderHook(() => useCloudTimerRemove(false));
|
|
146
|
+
await act(async () => {
|
|
147
|
+
await result.current.removeTimer('1');
|
|
148
|
+
});
|
|
149
|
+
expect(device.removeTimer).toHaveBeenCalledWith({
|
|
150
|
+
groupId: 'test-group-id',
|
|
151
|
+
timerId: '1',
|
|
152
|
+
success: expect.any(Function),
|
|
153
|
+
fail: expect.any(Function)
|
|
154
|
+
});
|
|
155
|
+
}, 10000);
|
|
156
|
+
});
|
|
157
|
+
describe('useCloudTimerList', () => {
|
|
158
|
+
it('should get cloud timer list successfully', async () => {
|
|
159
|
+
const {
|
|
160
|
+
result
|
|
161
|
+
} = renderHook(() => useCloudTimerList(false));
|
|
162
|
+
await act(async () => {
|
|
163
|
+
await result.current.getTimerList();
|
|
164
|
+
});
|
|
165
|
+
expect(device.syncTimerTask).toHaveBeenCalledWith({
|
|
166
|
+
groupId: 'test-group-id',
|
|
167
|
+
category: CLOUD_TIMER_CATEGORY,
|
|
168
|
+
success: expect.any(Function),
|
|
169
|
+
fail: expect.any(Function)
|
|
170
|
+
});
|
|
171
|
+
}, 10000);
|
|
172
|
+
});
|
|
173
|
+
describe('useCloudTimerUpdateStatus', () => {
|
|
174
|
+
it('should update cloud timer status successfully', async () => {
|
|
175
|
+
const {
|
|
176
|
+
result
|
|
177
|
+
} = renderHook(() => useCloudTimerUpdateStatus(false));
|
|
178
|
+
await act(async () => {
|
|
179
|
+
await result.current.updateTimerStatus('1', true);
|
|
180
|
+
});
|
|
181
|
+
expect(device.updateTimerStatus).toHaveBeenCalledWith({
|
|
182
|
+
groupId: 'test-group-id',
|
|
183
|
+
timerId: '1',
|
|
184
|
+
status: true,
|
|
185
|
+
success: expect.any(Function),
|
|
186
|
+
fail: expect.any(Function)
|
|
187
|
+
});
|
|
188
|
+
}, 10000);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { renderHook, act } from '@testing-library/react-hooks';
|
|
2
|
+
import { useLocalTimerAdd, useLocalTimerUpdate, useLocalTimerRemove, useLocalTimerList, useLocalTimerUpdateStatus } from '../useTimerOperateLocal';
|
|
3
|
+
import { useLocalTimerCloudProperty } from '../../utils/ScheduleCloudProperty';
|
|
4
|
+
import { LOCAL_TIMER_CATEGORY } from '../../constant';
|
|
5
|
+
import { getTimerState } from '../../context/timer/';
|
|
6
|
+
|
|
7
|
+
// Mock dependencies
|
|
8
|
+
jest.mock('../../utils/ScheduleCache', () => ({
|
|
9
|
+
devIdOrGroupIdCache: {
|
|
10
|
+
get: jest.fn().mockReturnValue({
|
|
11
|
+
devId: 'test-device-id',
|
|
12
|
+
groupId: 'test-group-id'
|
|
13
|
+
}),
|
|
14
|
+
set: jest.fn()
|
|
15
|
+
},
|
|
16
|
+
getScheduleCache: jest.fn()
|
|
17
|
+
}));
|
|
18
|
+
jest.mock('../../context/timer/', () => ({
|
|
19
|
+
getTimerState: jest.fn() // 直接模拟返回值
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
// Mock ray functions
|
|
23
|
+
jest.mock('@ray-js/ray', () => ({
|
|
24
|
+
offDpDataChange: jest.fn(),
|
|
25
|
+
onDpDataChange: jest.fn()
|
|
26
|
+
}));
|
|
27
|
+
jest.mock('../../utils/ScheduleCloudProperty', () => ({
|
|
28
|
+
useLocalTimerCloudProperty: jest.fn().mockReturnValue({
|
|
29
|
+
set: jest.fn().mockResolvedValue(true),
|
|
30
|
+
update: jest.fn().mockResolvedValue(true),
|
|
31
|
+
remove: jest.fn().mockResolvedValue(true),
|
|
32
|
+
updateStatus: jest.fn().mockResolvedValue(true),
|
|
33
|
+
getAll: jest.fn().mockResolvedValue({
|
|
34
|
+
properties: {}
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
}));
|
|
38
|
+
describe('useTimerOperateLocal Hooks', () => {
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
jest.clearAllMocks();
|
|
41
|
+
});
|
|
42
|
+
describe('useLocalTimerAdd', () => {
|
|
43
|
+
it('should add local timer successfully', async () => {
|
|
44
|
+
const mockSet = jest.fn().mockResolvedValue(true);
|
|
45
|
+
useLocalTimerCloudProperty.mockReturnValue({
|
|
46
|
+
set: mockSet
|
|
47
|
+
});
|
|
48
|
+
const {
|
|
49
|
+
result
|
|
50
|
+
} = renderHook(() => useLocalTimerAdd(true));
|
|
51
|
+
const mockTimer = {
|
|
52
|
+
time: '12:00',
|
|
53
|
+
loops: '1111111',
|
|
54
|
+
dps: {
|
|
55
|
+
power: true
|
|
56
|
+
},
|
|
57
|
+
aliasName: 'Test Timer',
|
|
58
|
+
isAppPush: true
|
|
59
|
+
};
|
|
60
|
+
await act(async () => {
|
|
61
|
+
await result.current.addTimer(mockTimer);
|
|
62
|
+
});
|
|
63
|
+
expect(mockSet).toHaveBeenCalledWith(mockTimer, undefined);
|
|
64
|
+
expect(result.current.isLoading).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
it('should handle add timer error', async () => {
|
|
67
|
+
const mockSet = jest.fn().mockRejectedValue(new Error('Add failed'));
|
|
68
|
+
useLocalTimerCloudProperty.mockReturnValue({
|
|
69
|
+
set: mockSet
|
|
70
|
+
});
|
|
71
|
+
const {
|
|
72
|
+
result
|
|
73
|
+
} = renderHook(() => useLocalTimerAdd(true));
|
|
74
|
+
const mockTimer = {
|
|
75
|
+
time: '12:00',
|
|
76
|
+
loops: '1111111',
|
|
77
|
+
dps: {
|
|
78
|
+
power: true
|
|
79
|
+
},
|
|
80
|
+
aliasName: 'Test Timer',
|
|
81
|
+
isAppPush: true
|
|
82
|
+
};
|
|
83
|
+
await expect(act(async () => {
|
|
84
|
+
await result.current.addTimer(mockTimer);
|
|
85
|
+
})).rejects.toThrow('Add failed');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe('useLocalTimerUpdate', () => {
|
|
89
|
+
it('should update local timer successfully', async () => {
|
|
90
|
+
const mockUpdate = jest.fn().mockResolvedValue(true);
|
|
91
|
+
useLocalTimerCloudProperty.mockReturnValue({
|
|
92
|
+
update: mockUpdate
|
|
93
|
+
});
|
|
94
|
+
const {
|
|
95
|
+
result
|
|
96
|
+
} = renderHook(() => useLocalTimerUpdate(true));
|
|
97
|
+
const mockTimer = {
|
|
98
|
+
timerId: '1',
|
|
99
|
+
time: '12:00',
|
|
100
|
+
loops: '1111111',
|
|
101
|
+
dps: {
|
|
102
|
+
power: true
|
|
103
|
+
},
|
|
104
|
+
aliasName: 'Test Timer',
|
|
105
|
+
isAppPush: true
|
|
106
|
+
};
|
|
107
|
+
await act(async () => {
|
|
108
|
+
await result.current.updateTimer(mockTimer);
|
|
109
|
+
});
|
|
110
|
+
expect(mockUpdate).toHaveBeenCalledWith(mockTimer);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('useLocalTimerRemove', () => {
|
|
114
|
+
it('should remove local timer successfully', async () => {
|
|
115
|
+
const mockRemove = jest.fn().mockResolvedValue(true);
|
|
116
|
+
useLocalTimerCloudProperty.mockReturnValue({
|
|
117
|
+
remove: mockRemove
|
|
118
|
+
});
|
|
119
|
+
const {
|
|
120
|
+
result
|
|
121
|
+
} = renderHook(() => useLocalTimerRemove(true));
|
|
122
|
+
await act(async () => {
|
|
123
|
+
await result.current.removeTimer('1');
|
|
124
|
+
});
|
|
125
|
+
expect(mockRemove).toHaveBeenCalledWith('1');
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('useLocalTimerList', () => {
|
|
129
|
+
it('should get local timer list successfully', async () => {
|
|
130
|
+
const mockGetAll = jest.fn().mockResolvedValue({
|
|
131
|
+
properties: {
|
|
132
|
+
[`${LOCAL_TIMER_CATEGORY}_1`]: JSON.stringify({
|
|
133
|
+
time: '12:00',
|
|
134
|
+
loops: '1111111',
|
|
135
|
+
status: true,
|
|
136
|
+
dps: {
|
|
137
|
+
power: true
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
useLocalTimerCloudProperty.mockReturnValue({
|
|
143
|
+
getAll: mockGetAll
|
|
144
|
+
});
|
|
145
|
+
const {
|
|
146
|
+
result
|
|
147
|
+
} = renderHook(() => useLocalTimerList(true));
|
|
148
|
+
await act(async () => {
|
|
149
|
+
const response = await result.current.getTimerList();
|
|
150
|
+
expect(response.timers).toHaveLength(1);
|
|
151
|
+
expect(response.timers[0]).toHaveProperty('timerId', '1');
|
|
152
|
+
expect(response.timers[0]).toHaveProperty('time', '12:00');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
it('should handle invalid timer data', async () => {
|
|
156
|
+
const mockGetAll = jest.fn().mockResolvedValue({
|
|
157
|
+
properties: {
|
|
158
|
+
[`${LOCAL_TIMER_CATEGORY}_1`]: 'invalid_json',
|
|
159
|
+
[`${LOCAL_TIMER_CATEGORY}_2`]: '1',
|
|
160
|
+
[`${LOCAL_TIMER_CATEGORY}_3`]: 'null'
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
useLocalTimerCloudProperty.mockReturnValue({
|
|
164
|
+
getAll: mockGetAll
|
|
165
|
+
});
|
|
166
|
+
const {
|
|
167
|
+
result
|
|
168
|
+
} = renderHook(() => useLocalTimerList(true));
|
|
169
|
+
await act(async () => {
|
|
170
|
+
const response = await result.current.getTimerList();
|
|
171
|
+
expect(response.timers).toHaveLength(0);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
it('should get empty timer list when no timers exist', async () => {
|
|
175
|
+
const mockGetAll = jest.fn().mockResolvedValue({
|
|
176
|
+
properties: {}
|
|
177
|
+
});
|
|
178
|
+
useLocalTimerCloudProperty.mockReturnValue({
|
|
179
|
+
getAll: mockGetAll
|
|
180
|
+
});
|
|
181
|
+
const {
|
|
182
|
+
result
|
|
183
|
+
} = renderHook(() => useLocalTimerList(false));
|
|
184
|
+
await act(async () => {
|
|
185
|
+
const response = await result.current.getTimerList();
|
|
186
|
+
expect(response.timers).toHaveLength(0);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
describe('useLocalTimerUpdateStatus', () => {
|
|
191
|
+
it('should update timer status successfully', async () => {
|
|
192
|
+
const mockUpdateStatus = jest.fn().mockResolvedValue(true);
|
|
193
|
+
useLocalTimerCloudProperty.mockReturnValue({
|
|
194
|
+
updateStatus: mockUpdateStatus
|
|
195
|
+
});
|
|
196
|
+
getTimerState.mockReturnValue({
|
|
197
|
+
rtcTimerList: [{
|
|
198
|
+
timerId: '1',
|
|
199
|
+
time: '12:00',
|
|
200
|
+
loops: '1111111',
|
|
201
|
+
dps: {
|
|
202
|
+
power: true
|
|
203
|
+
}
|
|
204
|
+
}]
|
|
205
|
+
});
|
|
206
|
+
const {
|
|
207
|
+
result
|
|
208
|
+
} = renderHook(() => useLocalTimerUpdateStatus(true));
|
|
209
|
+
await act(async () => {
|
|
210
|
+
await result.current.updateTimerStatus('1', true);
|
|
211
|
+
});
|
|
212
|
+
expect(mockUpdateStatus).toHaveBeenCalledWith('1', true);
|
|
213
|
+
expect(result.current.isLoading).toBe(false);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|