@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.
Files changed (246) hide show
  1. package/README.md +565 -0
  2. package/lib/config/dpCodes.d.ts +27 -0
  3. package/lib/config/dpCodes.js +30 -0
  4. package/lib/config/index.d.ts +2 -0
  5. package/lib/config/index.js +2 -0
  6. package/lib/config/rhythms/defaultValue.d.ts +18 -0
  7. package/lib/config/rhythms/defaultValue.js +72 -0
  8. package/lib/config/rhythms/index.d.ts +10 -0
  9. package/lib/config/rhythms/index.js +35 -0
  10. package/lib/conflict/ConflictResolver.d.ts +2 -0
  11. package/lib/conflict/ConflictResolver.js +284 -0
  12. package/lib/conflict/__test__/ConflictResolver.test.d.ts +1 -0
  13. package/lib/conflict/__test__/ConflictResolver.test.js +183 -0
  14. package/lib/conflict/__test__/index.test.d.ts +1 -0
  15. package/lib/conflict/__test__/index.test.js +385 -0
  16. package/lib/conflict/__test__/scheduleDataManager.test.d.ts +1 -0
  17. package/lib/conflict/__test__/scheduleDataManager.test.js +170 -0
  18. package/lib/conflict/__test__/transform.test.d.ts +1 -0
  19. package/lib/conflict/__test__/transform.test.js +454 -0
  20. package/lib/conflict/__test__/updateDeviceDp.d.ts +1 -0
  21. package/lib/conflict/__test__/updateDeviceDp.js +114 -0
  22. package/lib/conflict/index.d.ts +42 -0
  23. package/lib/conflict/index.js +103 -0
  24. package/lib/conflict/scheduleDataManager.d.ts +12 -0
  25. package/lib/conflict/scheduleDataManager.js +79 -0
  26. package/lib/conflict/transform.d.ts +71 -0
  27. package/lib/conflict/transform.js +251 -0
  28. package/lib/conflict/type.d.ts +55 -0
  29. package/lib/conflict/type.js +17 -0
  30. package/lib/conflict/updateDeviceDp.d.ts +1 -0
  31. package/lib/conflict/updateDeviceDp.js +41 -0
  32. package/lib/constant/index.d.ts +5 -0
  33. package/lib/constant/index.js +5 -0
  34. package/lib/context/index.d.ts +3 -0
  35. package/lib/context/index.js +3 -0
  36. package/lib/context/rhythms/actions.d.ts +20 -0
  37. package/lib/context/rhythms/actions.js +52 -0
  38. package/lib/context/rhythms/index.d.ts +5 -0
  39. package/lib/context/rhythms/index.js +51 -0
  40. package/lib/context/rhythms/reducer.d.ts +24 -0
  41. package/lib/context/rhythms/reducer.js +38 -0
  42. package/lib/context/schedule/actions.d.ts +7 -0
  43. package/lib/context/schedule/actions.js +51 -0
  44. package/lib/context/schedule/context.d.ts +6 -0
  45. package/lib/context/schedule/context.js +52 -0
  46. package/lib/context/schedule/index.d.ts +1 -0
  47. package/lib/context/schedule/index.js +1 -0
  48. package/lib/context/schedule/reducer.d.ts +16 -0
  49. package/lib/context/schedule/reducer.js +104 -0
  50. package/lib/context/schedule/type.d.ts +41 -0
  51. package/lib/context/schedule/type.js +11 -0
  52. package/lib/context/timer/actions.d.ts +8 -0
  53. package/lib/context/timer/actions.js +52 -0
  54. package/lib/context/timer/context.d.ts +10 -0
  55. package/lib/context/timer/context.js +53 -0
  56. package/lib/context/timer/index.d.ts +1 -0
  57. package/lib/context/timer/index.js +1 -0
  58. package/lib/context/timer/reducer.d.ts +15 -0
  59. package/lib/context/timer/reducer.js +70 -0
  60. package/lib/context/timer/type.d.ts +46 -0
  61. package/lib/context/timer/type.js +24 -0
  62. package/lib/dpParser/README.md +63 -0
  63. package/lib/dpParser/__test__/cycle.test.d.ts +1 -0
  64. package/lib/dpParser/__test__/cycle.test.js +258 -0
  65. package/lib/dpParser/__test__/random.test.d.ts +1 -0
  66. package/lib/dpParser/__test__/random.test.js +211 -0
  67. package/lib/dpParser/__test__/rhythms.test.d.ts +1 -0
  68. package/lib/dpParser/__test__/rhythms.test.js +71 -0
  69. package/lib/dpParser/__test__/rtcTimer.test.d.ts +1 -0
  70. package/lib/dpParser/__test__/rtcTimer.test.js +235 -0
  71. package/lib/dpParser/__test__/sleep.test.d.ts +1 -0
  72. package/lib/dpParser/__test__/sleep.test.js +71 -0
  73. package/lib/dpParser/__test__/sleepCommon.test.d.ts +1 -0
  74. package/lib/dpParser/__test__/sleepCommon.test.js +197 -0
  75. package/lib/dpParser/__test__/timerReport.test.d.ts +1 -0
  76. package/lib/dpParser/__test__/timerReport.test.js +100 -0
  77. package/lib/dpParser/__test__/wakeup.test.d.ts +1 -0
  78. package/lib/dpParser/__test__/wakeup.test.js +69 -0
  79. package/lib/dpParser/__test__/wakeupCommon.test.d.ts +1 -0
  80. package/lib/dpParser/__test__/wakeupCommon.test.js +131 -0
  81. package/lib/dpParser/cycle/index.d.ts +15 -0
  82. package/lib/dpParser/cycle/index.js +134 -0
  83. package/lib/dpParser/index.d.ts +23 -0
  84. package/lib/dpParser/index.js +43 -0
  85. package/lib/dpParser/random/index.d.ts +15 -0
  86. package/lib/dpParser/random/index.js +127 -0
  87. package/lib/dpParser/rhythms.d.ts +41 -0
  88. package/lib/dpParser/rhythms.js +116 -0
  89. package/lib/dpParser/rtcTimer.d.ts +17 -0
  90. package/lib/dpParser/rtcTimer.js +300 -0
  91. package/lib/dpParser/sleep/index.d.ts +9 -0
  92. package/lib/dpParser/sleep/index.js +29 -0
  93. package/lib/dpParser/sleep/sleepCommon.d.ts +11 -0
  94. package/lib/dpParser/sleep/sleepCommon.js +117 -0
  95. package/lib/dpParser/sleep/sleepSigmesh.d.ts +0 -0
  96. package/lib/dpParser/sleep/sleepSigmesh.js +101 -0
  97. package/lib/dpParser/timerReport.d.ts +11 -0
  98. package/lib/dpParser/timerReport.js +43 -0
  99. package/lib/dpParser/utils.d.ts +27 -0
  100. package/lib/dpParser/utils.js +53 -0
  101. package/lib/dpParser/wakeup/index.d.ts +10 -0
  102. package/lib/dpParser/wakeup/index.js +34 -0
  103. package/lib/dpParser/wakeup/wakeupCommon.d.ts +11 -0
  104. package/lib/dpParser/wakeup/wakeupCommon.js +106 -0
  105. package/lib/dpParser/wakeup/wakeupSigmesh.d.ts +15 -0
  106. package/lib/dpParser/wakeup/wakeupSigmesh.js +86 -0
  107. package/lib/hooks/__test__/useCommon.test.d.ts +1 -0
  108. package/lib/hooks/__test__/useCommon.test.js +72 -0
  109. package/lib/hooks/__test__/useCountdownDp.test.d.ts +1 -0
  110. package/lib/hooks/__test__/useCountdownDp.test.js +82 -0
  111. package/lib/hooks/__test__/useCycleDp.test.d.ts +1 -0
  112. package/lib/hooks/__test__/useCycleDp.test.js +92 -0
  113. package/lib/hooks/__test__/useRandomDp.test.d.ts +1 -0
  114. package/lib/hooks/__test__/useRandomDp.test.js +88 -0
  115. package/lib/hooks/__test__/useRhythmsDp.test.d.ts +1 -0
  116. package/lib/hooks/__test__/useRhythmsDp.test.js +81 -0
  117. package/lib/hooks/__test__/useSleepDp.test.d.ts +1 -0
  118. package/lib/hooks/__test__/useSleepDp.test.js +127 -0
  119. package/lib/hooks/__test__/useTimeFlush.test.d.ts +1 -0
  120. package/lib/hooks/__test__/useTimeFlush.test.js +109 -0
  121. package/lib/hooks/__test__/useTimerDp.test.d.ts +1 -0
  122. package/lib/hooks/__test__/useTimerDp.test.js +79 -0
  123. package/lib/hooks/__test__/useTimerOperate.test.d.ts +1 -0
  124. package/lib/hooks/__test__/useTimerOperate.test.js +286 -0
  125. package/lib/hooks/__test__/useTimerOperateCloud.test.d.ts +1 -0
  126. package/lib/hooks/__test__/useTimerOperateCloud.test.js +190 -0
  127. package/lib/hooks/__test__/useTimerOperateLocal.test.d.ts +1 -0
  128. package/lib/hooks/__test__/useTimerOperateLocal.test.js +216 -0
  129. package/lib/hooks/__test__/useTimerReportDp.test.d.ts +1 -0
  130. package/lib/hooks/__test__/useTimerReportDp.test.js +93 -0
  131. package/lib/hooks/__test__/useTimerSupport.test.d.ts +1 -0
  132. package/lib/hooks/__test__/useTimerSupport.test.js +110 -0
  133. package/lib/hooks/__test__/useWakeUpDp.test.d.ts +1 -0
  134. package/lib/hooks/__test__/useWakeUpDp.test.js +129 -0
  135. package/lib/hooks/useBaseLightDp.d.ts +21 -0
  136. package/lib/hooks/useBaseLightDp.js +165 -0
  137. package/lib/hooks/useCommon.d.ts +29 -0
  138. package/lib/hooks/useCommon.js +59 -0
  139. package/lib/hooks/useCommonSupport.d.ts +25 -0
  140. package/lib/hooks/useCommonSupport.js +241 -0
  141. package/lib/hooks/useCountdownDp.d.ts +13 -0
  142. package/lib/hooks/useCountdownDp.js +28 -0
  143. package/lib/hooks/useCountdownSupport.d.ts +9 -0
  144. package/lib/hooks/useCountdownSupport.js +13 -0
  145. package/lib/hooks/useCycleDp.d.ts +7 -0
  146. package/lib/hooks/useCycleDp.js +21 -0
  147. package/lib/hooks/useCycleSupport.d.ts +12 -0
  148. package/lib/hooks/useCycleSupport.js +16 -0
  149. package/lib/hooks/useRandomDp.d.ts +7 -0
  150. package/lib/hooks/useRandomDp.js +21 -0
  151. package/lib/hooks/useRandomSupport.d.ts +12 -0
  152. package/lib/hooks/useRandomSupport.js +16 -0
  153. package/lib/hooks/useRhythmsDp.d.ts +7 -0
  154. package/lib/hooks/useRhythmsDp.js +23 -0
  155. package/lib/hooks/useSleepDp.d.ts +6 -0
  156. package/lib/hooks/useSleepDp.js +21 -0
  157. package/lib/hooks/useSleepSupport.d.ts +8 -0
  158. package/lib/hooks/useSleepSupport.js +13 -0
  159. package/lib/hooks/useTimeFlush.d.ts +8 -0
  160. package/lib/hooks/useTimeFlush.js +31 -0
  161. package/lib/hooks/useTimerDp.d.ts +5 -0
  162. package/lib/hooks/useTimerDp.js +25 -0
  163. package/lib/hooks/useTimerFlushList.d.ts +11 -0
  164. package/lib/hooks/useTimerFlushList.js +53 -0
  165. package/lib/hooks/useTimerOperate.d.ts +68 -0
  166. package/lib/hooks/useTimerOperate.js +403 -0
  167. package/lib/hooks/useTimerOperateCloud.d.ts +31 -0
  168. package/lib/hooks/useTimerOperateCloud.js +233 -0
  169. package/lib/hooks/useTimerOperateLocal.d.ts +40 -0
  170. package/lib/hooks/useTimerOperateLocal.js +310 -0
  171. package/lib/hooks/useTimerReportDp.d.ts +15 -0
  172. package/lib/hooks/useTimerReportDp.js +48 -0
  173. package/lib/hooks/useTimerSupport.d.ts +13 -0
  174. package/lib/hooks/useTimerSupport.js +38 -0
  175. package/lib/hooks/useWakeUpDp.d.ts +6 -0
  176. package/lib/hooks/useWakeUpDp.js +21 -0
  177. package/lib/hooks/useWakeUpSupport.d.ts +8 -0
  178. package/lib/hooks/useWakeUpSupport.js +13 -0
  179. package/lib/hooks/useWakeupDp.d.ts +6 -0
  180. package/lib/hooks/useWakeupDp.js +21 -0
  181. package/lib/hooks/useWakeupSupport.d.ts +8 -0
  182. package/lib/hooks/useWakeupSupport.js +13 -0
  183. package/lib/i18n/index.d.ts +142 -0
  184. package/lib/i18n/index.js +7 -0
  185. package/lib/i18n/rhythms.d.ts +73 -0
  186. package/lib/i18n/rhythms.js +72 -0
  187. package/lib/i18n/strings.d.ts +73 -0
  188. package/lib/i18n/strings.js +6 -0
  189. package/lib/index.d.ts +51 -0
  190. package/lib/index.js +64 -0
  191. package/lib/types/countdown.d.ts +3 -0
  192. package/lib/types/countdown.js +1 -0
  193. package/lib/types/cycle.d.ts +22 -0
  194. package/lib/types/cycle.js +1 -0
  195. package/lib/types/global.d.ts +9 -0
  196. package/lib/types/index.d.ts +331 -0
  197. package/lib/types/index.js +76 -0
  198. package/lib/types/random.d.ts +20 -0
  199. package/lib/types/random.js +1 -0
  200. package/lib/types/rhythms.d.ts +79 -0
  201. package/lib/types/rhythms.js +15 -0
  202. package/lib/types/sleep.d.ts +36 -0
  203. package/lib/types/sleep.js +1 -0
  204. package/lib/types/timer.d.ts +107 -0
  205. package/lib/types/timer.js +1 -0
  206. package/lib/types/wakeup.d.ts +38 -0
  207. package/lib/types/wakeup.js +1 -0
  208. package/lib/utils/ScheduleCache.d.ts +19 -0
  209. package/lib/utils/ScheduleCache.js +39 -0
  210. package/lib/utils/ScheduleCloudProperty.d.ts +75 -0
  211. package/lib/utils/ScheduleCloudProperty.js +220 -0
  212. package/lib/utils/ScheduleDataSync.d.ts +82 -0
  213. package/lib/utils/ScheduleDataSync.js +127 -0
  214. package/lib/utils/ScheduleEmit.d.ts +67 -0
  215. package/lib/utils/ScheduleEmit.js +61 -0
  216. package/lib/utils/ScheduleLogger.d.ts +19 -0
  217. package/lib/utils/ScheduleLogger.js +71 -0
  218. package/lib/utils/ScheduleSupport.d.ts +131 -0
  219. package/lib/utils/ScheduleSupport.js +373 -0
  220. package/lib/utils/ScheduleUtils.d.ts +12 -0
  221. package/lib/utils/ScheduleUtils.js +51 -0
  222. package/lib/utils/__test__/ScheduleCloudProperty.test.d.ts +1 -0
  223. package/lib/utils/__test__/ScheduleCloudProperty.test.js +320 -0
  224. package/lib/utils/__test__/ScheduleSupport.test.d.ts +1 -0
  225. package/lib/utils/__test__/ScheduleSupport.test.js +211 -0
  226. package/lib/utils/__test__/ScheduleUtils.test.d.ts +1 -0
  227. package/lib/utils/__test__/ScheduleUtils.test.js +119 -0
  228. package/lib/utils/__test__/common.test.d.ts +1 -0
  229. package/lib/utils/__test__/common.test.js +147 -0
  230. package/lib/utils/__test__/storage.test.d.ts +1 -0
  231. package/lib/utils/__test__/storage.test.js +98 -0
  232. package/lib/utils/__test__/time.test.d.ts +1 -0
  233. package/lib/utils/__test__/time.test.js +146 -0
  234. package/lib/utils/common.d.ts +23 -0
  235. package/lib/utils/common.js +109 -0
  236. package/lib/utils/dpState.d.ts +5 -0
  237. package/lib/utils/dpState.js +27 -0
  238. package/lib/utils/getCachedSystemInfo.d.ts +39 -0
  239. package/lib/utils/getCachedSystemInfo.js +20 -0
  240. package/lib/utils/isInIDE.d.ts +1 -0
  241. package/lib/utils/isInIDE.js +5 -0
  242. package/lib/utils/storage.d.ts +5 -0
  243. package/lib/utils/storage.js +32 -0
  244. package/lib/utils/time.d.ts +40 -0
  245. package/lib/utils/time.js +84 -0
  246. package/package.json +78 -0
@@ -0,0 +1,92 @@
1
+ import { renderHook, act } from '@testing-library/react-hooks';
2
+ import { useCycleDp } from '../useCycleDp';
3
+ import { useBaseLightDp } from '../useBaseLightDp';
4
+ import { scheduleDpCodes } from '../../config/dpCodes';
5
+ import { getCycleParser } from '../../dpParser/cycle';
6
+ // Mock dependencies
7
+ jest.mock('../useBaseLightDp');
8
+ jest.mock('../../dpParser/cycle');
9
+ describe('useCycleDp', () => {
10
+ const mockCycleData = {
11
+ version: 1,
12
+ length: 1,
13
+ nodes: [{
14
+ onOff: true,
15
+ channel: 1,
16
+ loops: '0000000',
17
+ startTime: 28800,
18
+ // 08:00
19
+ startTimeDuration: 3600,
20
+ // 1小时
21
+ endTime: 64800,
22
+ // 18:00
23
+ endTimeDuration: 3600,
24
+ // 1小时
25
+ index: 0,
26
+ color: {
27
+ hue: 0,
28
+ saturation: 100,
29
+ value: 100,
30
+ brightness: 100,
31
+ temperature: 5000
32
+ }
33
+ }]
34
+ };
35
+ const mockParser = {
36
+ formatter: jest.fn(),
37
+ parser: jest.fn()
38
+ };
39
+ beforeEach(() => {
40
+ jest.clearAllMocks();
41
+ useBaseLightDp.mockReturnValue({
42
+ dpValue: JSON.stringify(mockCycleData),
43
+ updateDp: jest.fn()
44
+ });
45
+ getCycleParser.mockReturnValue(mockParser);
46
+ mockParser.formatter.mockImplementation(data => data);
47
+ mockParser.parser.mockImplementation(data => JSON.parse(data));
48
+ });
49
+ it('should return correct initial values', () => {
50
+ const {
51
+ result
52
+ } = renderHook(() => useCycleDp());
53
+ expect(result.current.dpValue).toEqual(mockCycleData);
54
+ expect(typeof result.current.updateDp).toBe('function');
55
+ });
56
+ it('should call updateDp with formatted data', () => {
57
+ const mockUpdateDp = jest.fn();
58
+ useBaseLightDp.mockReturnValue({
59
+ dpValue: JSON.stringify(mockCycleData),
60
+ updateDp: mockUpdateDp
61
+ });
62
+ const {
63
+ result
64
+ } = renderHook(() => useCycleDp());
65
+ act(() => {
66
+ result.current.updateDp(mockCycleData);
67
+ });
68
+ expect(mockParser.formatter).toHaveBeenCalledWith(mockCycleData);
69
+ expect(mockUpdateDp).toHaveBeenCalledWith(mockCycleData);
70
+ });
71
+ it('should parse string dpValue correctly', () => {
72
+ const stringDpValue = JSON.stringify(mockCycleData);
73
+ useBaseLightDp.mockReturnValue({
74
+ dpValue: stringDpValue,
75
+ updateDp: jest.fn()
76
+ });
77
+ const {
78
+ result
79
+ } = renderHook(() => useCycleDp());
80
+ expect(mockParser.parser).toHaveBeenCalledWith(stringDpValue);
81
+ expect(result.current.dpValue).toEqual(mockCycleData);
82
+ });
83
+ it('should use correct dpCode', () => {
84
+ renderHook(() => useCycleDp());
85
+ expect(useBaseLightDp).toHaveBeenCalledWith(scheduleDpCodes.CYCLE_TIMING);
86
+ });
87
+ it('should handle custom dpCode', () => {
88
+ const customDpCode = scheduleDpCodes.CYCLE_TIMING;
89
+ renderHook(() => useCycleDp(customDpCode));
90
+ expect(useBaseLightDp).toHaveBeenCalledWith(customDpCode);
91
+ });
92
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,88 @@
1
+ import { renderHook, act } from '@testing-library/react-hooks';
2
+ import { useRandomDp } from '../useRandomDp';
3
+ import { useBaseLightDp } from '../useBaseLightDp';
4
+ import { scheduleDpCodes } from '../../config/dpCodes';
5
+ import { getRandomParser } from '../../dpParser/random';
6
+ // Mock dependencies
7
+ jest.mock('../useBaseLightDp');
8
+ jest.mock('../../dpParser/random');
9
+ describe('useRandomDp', () => {
10
+ const mockRandomData = {
11
+ version: 1,
12
+ length: 1,
13
+ nodes: [{
14
+ onOff: true,
15
+ channel: 1,
16
+ loops: '0000000',
17
+ startTime: 28800,
18
+ // 08:00
19
+ endTime: 64800,
20
+ // 18:00
21
+ index: 0,
22
+ color: {
23
+ hue: 0,
24
+ saturation: 100,
25
+ value: 100,
26
+ brightness: 100,
27
+ temperature: 5000
28
+ }
29
+ }]
30
+ };
31
+ const mockParser = {
32
+ formatter: jest.fn(),
33
+ parser: jest.fn()
34
+ };
35
+ beforeEach(() => {
36
+ jest.clearAllMocks();
37
+ useBaseLightDp.mockReturnValue({
38
+ dpValue: JSON.stringify(mockRandomData),
39
+ updateDp: jest.fn()
40
+ });
41
+ getRandomParser.mockReturnValue(mockParser);
42
+ mockParser.formatter.mockImplementation(data => data);
43
+ mockParser.parser.mockImplementation(data => JSON.parse(data));
44
+ });
45
+ it('should return correct initial values', () => {
46
+ const {
47
+ result
48
+ } = renderHook(() => useRandomDp());
49
+ expect(result.current.dpValue).toEqual(mockRandomData);
50
+ expect(typeof result.current.updateDp).toBe('function');
51
+ });
52
+ it('should call updateDp with formatted data', () => {
53
+ const mockUpdateDp = jest.fn();
54
+ useBaseLightDp.mockReturnValue({
55
+ dpValue: JSON.stringify(mockRandomData),
56
+ updateDp: mockUpdateDp
57
+ });
58
+ const {
59
+ result
60
+ } = renderHook(() => useRandomDp());
61
+ act(() => {
62
+ result.current.updateDp(mockRandomData);
63
+ });
64
+ expect(mockParser.formatter).toHaveBeenCalledWith(mockRandomData);
65
+ expect(mockUpdateDp).toHaveBeenCalledWith(mockRandomData);
66
+ });
67
+ it('should parse string dpValue correctly', () => {
68
+ const stringDpValue = JSON.stringify(mockRandomData);
69
+ useBaseLightDp.mockReturnValue({
70
+ dpValue: stringDpValue,
71
+ updateDp: jest.fn()
72
+ });
73
+ const {
74
+ result
75
+ } = renderHook(() => useRandomDp());
76
+ expect(mockParser.parser).toHaveBeenCalledWith(stringDpValue);
77
+ expect(result.current.dpValue).toEqual(mockRandomData);
78
+ });
79
+ it('should use correct dpCode', () => {
80
+ renderHook(() => useRandomDp());
81
+ expect(useBaseLightDp).toHaveBeenCalledWith(scheduleDpCodes.RANDOM_TIMING);
82
+ });
83
+ it('should handle custom dpCode', () => {
84
+ const customDpCode = scheduleDpCodes.RANDOM_TIMING;
85
+ renderHook(() => useRandomDp(customDpCode));
86
+ expect(useBaseLightDp).toHaveBeenCalledWith(customDpCode);
87
+ });
88
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import { renderHook, act } from '@testing-library/react-hooks';
2
+ import { useRhythmsDp } from '../useRhythmsDp';
3
+ import { useBaseLightDp } from '../useBaseLightDp';
4
+ import { scheduleDpCodes } from '../../config/dpCodes';
5
+ import { rhythmParser } from '../../dpParser/rhythms';
6
+ // Mock dependencies
7
+ jest.mock('../useBaseLightDp');
8
+ jest.mock('../../dpParser/rhythms');
9
+ describe('useRhythmsDp', () => {
10
+ const mockRhythmData = {
11
+ version: 1,
12
+ power: true,
13
+ mode: 1,
14
+ weeks: [0, 1, 2, 3, 4, 5, 6],
15
+ number: 1,
16
+ rhythms: [{
17
+ power: true,
18
+ hour: 8,
19
+ minute: 0,
20
+ hue: 0,
21
+ saturation: 100,
22
+ value: 100,
23
+ brightness: 100,
24
+ temperature: 5000,
25
+ icon: 'sun',
26
+ name: '日出'
27
+ }]
28
+ };
29
+ beforeEach(() => {
30
+ jest.clearAllMocks();
31
+ useBaseLightDp.mockReturnValue({
32
+ dpValue: mockRhythmData,
33
+ updateDp: jest.fn()
34
+ });
35
+ rhythmParser.formatter.mockImplementation(data => data);
36
+ rhythmParser.parser.mockImplementation(data => data);
37
+ });
38
+ it('should return correct initial values', () => {
39
+ const {
40
+ result
41
+ } = renderHook(() => useRhythmsDp());
42
+ expect(result.current.dpValue).toEqual(mockRhythmData);
43
+ expect(typeof result.current.updateDp).toBe('function');
44
+ });
45
+ it('should call updateDp with formatted data', () => {
46
+ const mockUpdateDp = jest.fn();
47
+ useBaseLightDp.mockReturnValue({
48
+ dpValue: mockRhythmData,
49
+ updateDp: mockUpdateDp
50
+ });
51
+ const {
52
+ result
53
+ } = renderHook(() => useRhythmsDp());
54
+ act(() => {
55
+ result.current.updateDp(mockRhythmData);
56
+ });
57
+ expect(rhythmParser.formatter).toHaveBeenCalledWith(mockRhythmData);
58
+ expect(mockUpdateDp).toHaveBeenCalledWith(mockRhythmData);
59
+ });
60
+ it('should parse string dpValue correctly', () => {
61
+ const stringDpValue = JSON.stringify(mockRhythmData);
62
+ useBaseLightDp.mockReturnValue({
63
+ dpValue: stringDpValue,
64
+ updateDp: jest.fn()
65
+ });
66
+ const {
67
+ result
68
+ } = renderHook(() => useRhythmsDp());
69
+ expect(rhythmParser.parser).toHaveBeenCalledWith(stringDpValue);
70
+ expect(result.current.dpValue).toEqual(JSON.stringify(mockRhythmData));
71
+ });
72
+ it('should use correct dpCode', () => {
73
+ renderHook(() => useRhythmsDp());
74
+ expect(useBaseLightDp).toHaveBeenCalledWith(scheduleDpCodes.RHYTHM_MODE);
75
+ });
76
+ it('should handle custom dpCode', () => {
77
+ const customDpCode = scheduleDpCodes.RHYTHM_MODE;
78
+ renderHook(() => useRhythmsDp(customDpCode));
79
+ expect(useBaseLightDp).toHaveBeenCalledWith(customDpCode);
80
+ });
81
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,127 @@
1
+ import { renderHook, act } from '@testing-library/react-hooks';
2
+ import { useSleepDp } from '../useSleepDp';
3
+ import { useBaseLightDp } from '../useBaseLightDp';
4
+ import { scheduleDpCodes } from '../../config/dpCodes';
5
+ import { getSleepParser } from '../../dpParser/sleep';
6
+ // Mock dependencies
7
+ jest.mock('../useBaseLightDp');
8
+ jest.mock('../../dpParser/sleep');
9
+ describe('useSleepDp', () => {
10
+ const mockSleepData = {
11
+ version: 1,
12
+ length: 1,
13
+ nodes: [{
14
+ onOff: true,
15
+ loops: '0000000',
16
+ step: 1,
17
+ hour: 22,
18
+ minute: 0,
19
+ hue: 0,
20
+ saturation: 100,
21
+ value: 100,
22
+ brightness: 100,
23
+ temperature: 5000,
24
+ index: 0,
25
+ time: '22:00'
26
+ }]
27
+ };
28
+ const mockSleepDataSigmesh = {
29
+ version: 1,
30
+ dataMode: '01',
31
+ length: 1,
32
+ nodes: [{
33
+ onOff: true,
34
+ loops: '0000000',
35
+ step: 1,
36
+ hour: 22,
37
+ minute: 0,
38
+ brightness: 100,
39
+ temperature: 5000,
40
+ index: 0,
41
+ time: '22:00'
42
+ }]
43
+ };
44
+ const mockParser = {
45
+ formatter: jest.fn(),
46
+ parser: jest.fn()
47
+ };
48
+ beforeEach(() => {
49
+ jest.clearAllMocks();
50
+ useBaseLightDp.mockReturnValue({
51
+ dpValue: mockSleepData,
52
+ updateDp: jest.fn()
53
+ });
54
+ getSleepParser.mockReturnValue(mockParser);
55
+ mockParser.formatter.mockImplementation(data => data);
56
+ mockParser.parser.mockImplementation(data => data);
57
+ });
58
+ it('should return correct initial values with TSleepData', () => {
59
+ const {
60
+ result
61
+ } = renderHook(() => useSleepDp());
62
+ expect(result.current.dpValue).toEqual(mockSleepData);
63
+ expect(typeof result.current.updateDp).toBe('function');
64
+ });
65
+ it('should return correct initial values with TSleepDataSigmesh', () => {
66
+ useBaseLightDp.mockReturnValue({
67
+ dpValue: mockSleepDataSigmesh,
68
+ updateDp: jest.fn()
69
+ });
70
+ const {
71
+ result
72
+ } = renderHook(() => useSleepDp());
73
+ expect(result.current.dpValue).toEqual(mockSleepDataSigmesh);
74
+ expect(typeof result.current.updateDp).toBe('function');
75
+ });
76
+ it('should call updateDp with formatted data for TSleepData', () => {
77
+ const mockUpdateDp = jest.fn();
78
+ useBaseLightDp.mockReturnValue({
79
+ dpValue: mockSleepData,
80
+ updateDp: mockUpdateDp
81
+ });
82
+ const {
83
+ result
84
+ } = renderHook(() => useSleepDp());
85
+ act(() => {
86
+ result.current.updateDp(mockSleepData);
87
+ });
88
+ expect(mockParser.formatter).toHaveBeenCalledWith(mockSleepData);
89
+ expect(mockUpdateDp).toHaveBeenCalledWith(mockSleepData);
90
+ });
91
+ it('should call updateDp with formatted data for TSleepDataSigmesh', () => {
92
+ const mockUpdateDp = jest.fn();
93
+ useBaseLightDp.mockReturnValue({
94
+ dpValue: mockSleepDataSigmesh,
95
+ updateDp: mockUpdateDp
96
+ });
97
+ const {
98
+ result
99
+ } = renderHook(() => useSleepDp());
100
+ act(() => {
101
+ result.current.updateDp(mockSleepDataSigmesh);
102
+ });
103
+ expect(mockParser.formatter).toHaveBeenCalledWith(mockSleepDataSigmesh);
104
+ expect(mockUpdateDp).toHaveBeenCalledWith(mockSleepDataSigmesh);
105
+ });
106
+ it('should parse string dpValue correctly', () => {
107
+ const stringDpValue = JSON.stringify(mockSleepData);
108
+ useBaseLightDp.mockReturnValue({
109
+ dpValue: stringDpValue,
110
+ updateDp: jest.fn()
111
+ });
112
+ const {
113
+ result
114
+ } = renderHook(() => useSleepDp());
115
+ expect(mockParser.parser).toHaveBeenCalledWith(stringDpValue);
116
+ expect(result.current.dpValue).toEqual(JSON.stringify(mockSleepData));
117
+ });
118
+ it('should use correct dpCode', () => {
119
+ renderHook(() => useSleepDp());
120
+ expect(useBaseLightDp).toHaveBeenCalledWith(scheduleDpCodes.SLEEP_MODE);
121
+ });
122
+ it('should handle custom dpCode', () => {
123
+ const customDpCode = 'custom_dp_code';
124
+ renderHook(() => useSleepDp(customDpCode));
125
+ expect(useBaseLightDp).toHaveBeenCalledWith(customDpCode);
126
+ });
127
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,109 @@
1
+ import { renderHook } from '@testing-library/react-hooks';
2
+ import { useTimerContext, useTimerListFlush } from '../useTimeFlush';
3
+ import { TimerContext } from '../../context/timer/context';
4
+ import { useSupportLocalTimer } from '../useTimerSupport';
5
+ // Mock dependencies
6
+ jest.mock('../useTimerSupport');
7
+ jest.mock('../../context/timer/context', () => ({
8
+ TimerContext: {
9
+ _currentValue: {}
10
+ }
11
+ }));
12
+ describe('useTimeFlush Hooks', () => {
13
+ beforeEach(() => {
14
+ jest.clearAllMocks();
15
+ });
16
+ describe('useTimerContext', () => {
17
+ it('should return timer context', () => {
18
+ const mockContext = {
19
+ state: {},
20
+ dispatch: jest.fn(),
21
+ actions: {
22
+ flushRtcTimerList: jest.fn(),
23
+ flushCloudTimerList: jest.fn()
24
+ }
25
+ };
26
+ TimerContext._currentValue = mockContext;
27
+ const {
28
+ result
29
+ } = renderHook(() => useTimerContext());
30
+ expect(result.current).toEqual(mockContext);
31
+ });
32
+ });
33
+ describe('useTimerListFlush', () => {
34
+ it('should flush local timer list when local timer is supported', () => {
35
+ const mockDispatch = jest.fn();
36
+ const mockActions = {
37
+ flushRtcTimerList: jest.fn(),
38
+ flushCloudTimerList: jest.fn()
39
+ };
40
+ useSupportLocalTimer.mockReturnValue({
41
+ isSupport: true,
42
+ isReady: true
43
+ });
44
+ TimerContext._currentValue = {
45
+ dispatch: mockDispatch,
46
+ actions: mockActions
47
+ };
48
+ const {
49
+ result
50
+ } = renderHook(() => useTimerListFlush());
51
+ const mockTimerList = [{
52
+ timerId: '1',
53
+ time: '12:00',
54
+ loops: '1111111',
55
+ status: true,
56
+ dps: {
57
+ power: true
58
+ },
59
+ aliasName: 'Test Timer',
60
+ isAppPush: true
61
+ }];
62
+ result.current.flushTimerList(mockTimerList);
63
+ expect(mockDispatch).toHaveBeenCalledWith(mockActions.flushRtcTimerList(mockTimerList));
64
+ expect(mockActions.flushCloudTimerList).not.toHaveBeenCalled();
65
+ });
66
+ it('should flush cloud timer list when local timer is not supported', () => {
67
+ const mockDispatch = jest.fn();
68
+ const mockActions = {
69
+ flushRtcTimerList: jest.fn(),
70
+ flushCloudTimerList: jest.fn()
71
+ };
72
+ useSupportLocalTimer.mockReturnValue({
73
+ isSupport: false,
74
+ isReady: true
75
+ });
76
+ TimerContext._currentValue = {
77
+ dispatch: mockDispatch,
78
+ actions: mockActions
79
+ };
80
+ const {
81
+ result
82
+ } = renderHook(() => useTimerListFlush());
83
+ const mockTimerList = [{
84
+ timerId: '1',
85
+ time: '12:00',
86
+ loops: '1111111',
87
+ status: true,
88
+ dps: {
89
+ power: true
90
+ },
91
+ aliasName: 'Test Timer',
92
+ isAppPush: true
93
+ }];
94
+ result.current.flushTimerList(mockTimerList);
95
+ expect(mockDispatch).toHaveBeenCalledWith(mockActions.flushCloudTimerList(mockTimerList));
96
+ expect(mockActions.flushRtcTimerList).not.toHaveBeenCalled();
97
+ });
98
+ it('should return correct ready status', () => {
99
+ useSupportLocalTimer.mockReturnValue({
100
+ isSupport: true,
101
+ isReady: false
102
+ });
103
+ const {
104
+ result
105
+ } = renderHook(() => useTimerListFlush());
106
+ expect(result.current.isReady).toBe(false);
107
+ });
108
+ });
109
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,79 @@
1
+ import { renderHook, act } from '@testing-library/react-hooks';
2
+ import { useTimerDp } from '../useTimerDp';
3
+ import { useBaseLightDp } from '../useBaseLightDp';
4
+ import { scheduleDpCodes } from '../../config/dpCodes';
5
+ import { rtcTimerParser } from '../../dpParser/rtcTimer';
6
+ // Mock dependencies
7
+ jest.mock('../useBaseLightDp');
8
+ jest.mock('../../dpParser/rtcTimer');
9
+ describe('useTimerDp', () => {
10
+ const mockTimerData = {
11
+ timerId: '1',
12
+ status: true,
13
+ loops: '0000000',
14
+ time: '08:00',
15
+ deviceAction: 1,
16
+ dps: {
17
+ switch_led: true,
18
+ colour_data: {
19
+ hue: 0,
20
+ saturation: 100,
21
+ value: 100
22
+ },
23
+ bright_value: 100,
24
+ temp_value: 5000
25
+ }
26
+ };
27
+ beforeEach(() => {
28
+ jest.clearAllMocks();
29
+ useBaseLightDp.mockReturnValue({
30
+ dpValue: mockTimerData,
31
+ updateDp: jest.fn()
32
+ });
33
+ rtcTimerParser.formatter.mockImplementation(data => data);
34
+ rtcTimerParser.parser.mockImplementation(data => data);
35
+ });
36
+ it('should return correct initial values', () => {
37
+ const {
38
+ result
39
+ } = renderHook(() => useTimerDp());
40
+ expect(result.current.dpValue).toEqual(mockTimerData);
41
+ expect(typeof result.current.updateDp).toBe('function');
42
+ });
43
+ it('should call updateDp with formatted data', () => {
44
+ const mockUpdateDp = jest.fn();
45
+ useBaseLightDp.mockReturnValue({
46
+ dpValue: mockTimerData,
47
+ updateDp: mockUpdateDp
48
+ });
49
+ const {
50
+ result
51
+ } = renderHook(() => useTimerDp());
52
+ act(() => {
53
+ result.current.updateDp(mockTimerData);
54
+ });
55
+ expect(rtcTimerParser.formatter).toHaveBeenCalledWith(mockTimerData);
56
+ expect(mockUpdateDp).toHaveBeenCalledWith(mockTimerData);
57
+ });
58
+ it('should parse string dpValue correctly', () => {
59
+ const stringDpValue = JSON.stringify(mockTimerData);
60
+ useBaseLightDp.mockReturnValue({
61
+ dpValue: stringDpValue,
62
+ updateDp: jest.fn()
63
+ });
64
+ const {
65
+ result
66
+ } = renderHook(() => useTimerDp());
67
+ expect(rtcTimerParser.parser).toHaveBeenCalledWith(stringDpValue);
68
+ expect(result.current.dpValue).toEqual(JSON.stringify(mockTimerData));
69
+ });
70
+ it('should use correct dpCode', () => {
71
+ renderHook(() => useTimerDp());
72
+ expect(useBaseLightDp).toHaveBeenCalledWith(scheduleDpCodes.RTC_TIMER);
73
+ });
74
+ it('should handle custom dpCode', () => {
75
+ const customDpCode = scheduleDpCodes.RTC_TIMER;
76
+ renderHook(() => useTimerDp(customDpCode));
77
+ expect(useBaseLightDp).toHaveBeenCalledWith(customDpCode);
78
+ });
79
+ });
@@ -0,0 +1 @@
1
+ export {};