@applicaster/zapp-react-native-utils 12.0.0-alpha.7528906949 → 12.0.0-alpha.7531504237

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.
@@ -4,38 +4,77 @@ import {
4
4
  timers,
5
5
  } from "@applicaster/zapp-react-native-utils/reactHooks/debugging";
6
6
 
7
- jest.useFakeTimers();
8
-
9
7
  describe("Debug utils", () => {
8
+ let performanceNowMock;
9
+
10
+ beforeEach(() => {
11
+ jest.useFakeTimers();
12
+ // Clear the timers object
13
+ Object.keys(timers).forEach((key) => delete timers[key]);
14
+
15
+ // Mock performance.now()
16
+ // eslint-disable-next-line no-undef
17
+ performanceNowMock = jest.spyOn(performance, "now");
18
+ performanceNowMock.mockReturnValue(0); // Initial value
19
+ });
20
+
21
+ afterEach(() => {
22
+ jest.useRealTimers();
23
+ jest.restoreAllMocks();
24
+ performanceNowMock.mockRestore();
25
+ });
26
+
10
27
  describe("Unit Test: time", () => {
11
28
  it("should create new timer if timer with a label does not exist", () => {
29
+ performanceNowMock.mockReturnValue(1000);
12
30
  time("timer1");
13
31
  expect(timers["timer1"]).toBeDefined();
32
+ expect(timers["timer1"].startTime).toBe(1000);
14
33
  });
15
34
 
16
35
  it("should update start time of timer if timer with a label exists", () => {
36
+ // First call to time()
37
+ performanceNowMock.mockReturnValue(1000);
38
+ time("timer1");
17
39
  const previousStartTime = timers["timer1"].startTime;
18
- jest.advanceTimersByTime(1000);
40
+
41
+ // Second call to time()
42
+ performanceNowMock.mockReturnValue(2000);
19
43
  time("timer1");
20
44
  const currentStartTime = timers["timer1"].startTime;
21
- expect(previousStartTime).not.toEqual(currentStartTime);
45
+
46
+ expect(previousStartTime).toBe(1000);
47
+ expect(currentStartTime).toBe(2000);
22
48
  });
23
49
  });
24
50
 
25
51
  describe("Unit Test: timeEnd", () => {
26
- beforeEach(() => jest.resetAllMocks());
52
+ beforeEach(() => {
53
+ jest.spyOn(console, "log").mockImplementation(() => {});
54
+ });
27
55
 
28
56
  it("should log elapsed time", () => {
29
57
  const logSpy = jest.spyOn(console, "log");
30
58
 
59
+ performanceNowMock.mockReturnValue(1000);
60
+ time("timer1");
61
+
62
+ performanceNowMock.mockReturnValue(2000);
31
63
  timeEnd("timer1");
32
64
 
33
- expect(logSpy).toHaveBeenCalled();
65
+ expect(logSpy).toHaveBeenCalledWith(
66
+ "timer1: 1000.000ms 2",
67
+ expect.any(Object)
68
+ );
34
69
  });
35
70
 
36
71
  it("should not log elapsed time if accumulative: true in settings", () => {
37
72
  const logSpy = jest.spyOn(console, "log");
38
73
 
74
+ performanceNowMock.mockReturnValue(1000);
75
+ time("timer1");
76
+
77
+ performanceNowMock.mockReturnValue(2000);
39
78
  timeEnd("timer1", { accumulative: true });
40
79
 
41
80
  expect(logSpy).not.toHaveBeenCalled();
@@ -43,21 +82,52 @@ describe("Debug utils", () => {
43
82
  });
44
83
 
45
84
  describe("Integration Test: time and timeEnd", () => {
46
- beforeEach(() => jest.resetAllMocks());
85
+ beforeEach(() => {
86
+ jest.spyOn(console, "log").mockImplementation(() => {});
87
+ });
47
88
 
48
89
  it("should log elapsed time on timeEnd call", () => {
49
90
  const logSpy = jest.spyOn(console, "log");
91
+
92
+ performanceNowMock.mockReturnValue(1000);
50
93
  time("timer1");
94
+
95
+ performanceNowMock.mockReturnValue(2000);
51
96
  timeEnd("timer1");
52
- expect(logSpy).toHaveBeenCalled();
97
+
98
+ expect(logSpy).toHaveBeenCalledWith(
99
+ "timer1: 1000.000ms 2",
100
+ expect.objectContaining({
101
+ label: "timer1",
102
+ settings: undefined,
103
+ })
104
+ );
53
105
  });
54
106
 
55
- it("should log total and average time on timeEnd call without accumulative option", () => {
107
+ it("should log total and average time when accumulative timing is complete", () => {
56
108
  const logSpy = jest.spyOn(console, "log");
109
+
110
+ // First timing
111
+ performanceNowMock.mockReturnValue(1000);
57
112
  time("timer2");
113
+
114
+ performanceNowMock.mockReturnValue(2000);
58
115
  timeEnd("timer2", { accumulative: true });
59
- timeEnd("timer2");
60
- expect(logSpy).toHaveBeenCalled();
116
+
117
+ // Second timing
118
+ performanceNowMock.mockReturnValue(3000);
119
+ time("timer2");
120
+
121
+ performanceNowMock.mockReturnValue(5000);
122
+ timeEnd("timer2"); // This will log because timer is accumulative (callCount > 1)
123
+
124
+ expect(logSpy).toHaveBeenCalledWith(
125
+ "timer2: 2000.000ms 2",
126
+ expect.objectContaining({
127
+ label: "timer2",
128
+ settings: undefined,
129
+ })
130
+ );
61
131
  });
62
132
  });
63
133
  });
@@ -95,6 +95,8 @@ export const useDimensions: UseDimensions = (
95
95
 
96
96
  const activeSubscription = Dimensions.addEventListener("change", handler);
97
97
 
98
+ handler({ [context]: Dimensions.get(context) });
99
+
98
100
  return () => {
99
101
  activeSubscription.remove();
100
102
  };
@@ -78,6 +78,10 @@ export function isNavBarVisible(
78
78
  return false;
79
79
  }
80
80
 
81
+ if (screenData?.plugin_type === "login" && isTV()) {
82
+ return false;
83
+ }
84
+
81
85
  /* Match if screen is Hook */
82
86
  if (route.startsWith("/hooks/")) {
83
87
  const module = screenData?.module;
@@ -48,7 +48,11 @@ export function useCellResolver({
48
48
  ...cellResolverOptions
49
49
  }: Props) {
50
50
  let _component = Object.assign({}, component);
51
- const { width, height } = useDimensions("screen");
51
+
52
+ const { width, height } = useDimensions("screen", {
53
+ updateForInactiveScreens: false,
54
+ });
55
+
52
56
  const { plugins, cellStyles } = usePickFromState(["plugins", "cellStyles"]);
53
57
  const isRTL = useIsRTL();
54
58
 
@@ -112,6 +112,9 @@ export const isAndroidTVPlatform = () => getPlatform() === "android_tv";
112
112
  declare global {
113
113
  interface Window {
114
114
  VIZIO?: {
115
+ Chromevox: {
116
+ play: (text: string) => void;
117
+ };
115
118
  exitApplication: () => void;
116
119
  setClosedCaptionHandler: (
117
120
  callback: (isCCEnabled: boolean) => void
@@ -149,8 +152,7 @@ export const hasTizen = typeof window?.tizen !== "undefined";
149
152
  */
150
153
  export const hasWebOS = typeof window?.webOS !== "undefined";
151
154
 
152
- export const getUserAgent = () =>
153
- window?.navigator?.userAgent || global?.navigator?.userAgent;
155
+ export const getUserAgent = () => window?.navigator?.userAgent;
154
156
 
155
157
  export const isLgPlatform = () => {
156
158
  const userAgent = getUserAgent();