@box/box-ai-agent-selector 0.40.1 → 0.40.2
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.
@@ -4629,7 +4629,7 @@ function zc({
|
|
4629
4629
|
formatMessage: f
|
4630
4630
|
} = bi(), [c, l] = X(!1), p = o === fn.ERROR, [b, v] = X(p), [x, w] = Ei(Si), P = wi(), g = o === fn.SUCCESS, m = o === fn.IN_PROGRESS, y = f(Qe.selectAgent), C = f(Qe.defaultAgent);
|
4631
4631
|
let O = "";
|
4632
|
-
g ? O = (u == null ? void 0 : u.name)
|
4632
|
+
g ? O = (u == null ? void 0 : u.name) ?? y : p && (O = C);
|
4633
4633
|
const A = Y(null), {
|
4634
4634
|
Wrapper: S,
|
4635
4635
|
wrapperProps: T
|
@@ -1,24 +1,37 @@
|
|
1
|
-
import { renderHook as
|
2
|
-
import
|
1
|
+
import { renderHook as l, act as d } from "@testing-library/react";
|
2
|
+
import c from "../useLocalStorageAIAgents.js";
|
3
3
|
describe("useLocalStorageAIAgents", () => {
|
4
|
-
const
|
5
|
-
let
|
6
|
-
|
7
|
-
|
4
|
+
const o = "testAgentKey", r = "agent-456";
|
5
|
+
let a = {};
|
6
|
+
const g = jest.fn((e) => a[e]);
|
7
|
+
let u = jest.fn((e, t) => {
|
8
|
+
a[e] = t;
|
9
|
+
});
|
10
|
+
const i = jest.fn((e) => {
|
11
|
+
delete a[e];
|
12
|
+
});
|
13
|
+
Object.defineProperty(window, "localStorage", {
|
14
|
+
value: {
|
15
|
+
getItem: (e) => g(e),
|
16
|
+
setItem: (e, t) => u(e, t),
|
17
|
+
removeItem: (e) => i(e)
|
18
|
+
}
|
19
|
+
}), beforeEach(() => {
|
20
|
+
a = {};
|
8
21
|
}), afterEach(() => {
|
9
22
|
jest.clearAllMocks();
|
10
23
|
}), test("should initialize with null when localStorage is empty", () => {
|
11
24
|
const {
|
12
25
|
result: e
|
13
|
-
} =
|
14
|
-
expect(
|
26
|
+
} = l(() => c(o)), [t] = e.current;
|
27
|
+
expect(t).toBeNull(), expect(g(o)).toBeUndefined();
|
15
28
|
}), test("should initialize with value from localStorage if it exists and is valid", () => {
|
16
29
|
const e = "agent-123";
|
17
|
-
|
30
|
+
a[o] = e;
|
18
31
|
const {
|
19
|
-
result:
|
20
|
-
} =
|
21
|
-
expect(
|
32
|
+
result: t
|
33
|
+
} = l(() => c(o)), [n] = t.current;
|
34
|
+
expect(n).toBe(e), expect(g).toHaveBeenCalledWith(o);
|
22
35
|
}), test("should return null if localStorage value contains invalid characters", () => {
|
23
36
|
[
|
24
37
|
`><script>alert('XSS Attack!');<\/script><div class="`,
|
@@ -27,48 +40,60 @@ describe("useLocalStorageAIAgents", () => {
|
|
27
40
|
"${process.env.SECRET_KEY}",
|
28
41
|
"../../../etc/passwd",
|
29
42
|
"agent@123!"
|
30
|
-
].forEach((
|
31
|
-
|
43
|
+
].forEach((t) => {
|
44
|
+
a[o] = t;
|
32
45
|
const {
|
33
|
-
result:
|
34
|
-
} =
|
35
|
-
expect(s).toBeNull(), expect(
|
46
|
+
result: n
|
47
|
+
} = l(() => c(o)), [s] = n.current;
|
48
|
+
expect(s).toBeNull(), expect(i).toHaveBeenCalledWith(o);
|
36
49
|
});
|
37
50
|
}), test("should update localStorage when state changes", () => {
|
38
51
|
const {
|
39
52
|
result: e,
|
40
|
-
rerender:
|
41
|
-
} =
|
42
|
-
let [
|
43
|
-
expect(
|
44
|
-
s(
|
45
|
-
}),
|
53
|
+
rerender: t
|
54
|
+
} = l(() => c(o));
|
55
|
+
let [n, s] = e.current;
|
56
|
+
expect(n).not.toBe(r), d(() => {
|
57
|
+
s(r);
|
58
|
+
}), t(), [n] = e.current, expect(n).toBe(r), expect(u).toHaveBeenCalledWith(o, r);
|
46
59
|
}), test("should remove localStorage item when setting to null", () => {
|
47
60
|
const {
|
48
61
|
result: e,
|
49
|
-
rerender:
|
50
|
-
} =
|
51
|
-
let [
|
52
|
-
expect(
|
53
|
-
s(
|
54
|
-
}),
|
62
|
+
rerender: t
|
63
|
+
} = l(() => c(o));
|
64
|
+
let [n, s] = e.current;
|
65
|
+
expect(n).toBeNull(), d(() => {
|
66
|
+
s(r);
|
67
|
+
}), t(), [n] = e.current, expect(n).toBe(r), d(() => {
|
55
68
|
s(null);
|
56
|
-
}),
|
69
|
+
}), t(), [n] = e.current, expect(n).toBeNull(), expect(i).toHaveBeenCalledWith(o);
|
57
70
|
}), test("should handle valid alphanumeric characters with underscores and hyphens", () => {
|
58
71
|
const e = "valid-agent_123", {
|
59
|
-
result:
|
60
|
-
rerender:
|
61
|
-
} =
|
62
|
-
|
72
|
+
result: t,
|
73
|
+
rerender: n
|
74
|
+
} = l(() => c(o)), [, s] = t.current;
|
75
|
+
d(() => {
|
63
76
|
s(e);
|
64
|
-
}),
|
65
|
-
const [
|
66
|
-
expect(
|
77
|
+
}), n();
|
78
|
+
const [h] = t.current;
|
79
|
+
expect(h).toBe(e), expect(u).toHaveBeenCalledWith(o, e);
|
67
80
|
}), test("should return null for whitespace-only values in localStorage", () => {
|
68
|
-
|
81
|
+
a[o] = " ";
|
69
82
|
const {
|
70
83
|
result: e
|
71
|
-
} =
|
72
|
-
expect(
|
84
|
+
} = l(() => c(o)), [t] = e.current;
|
85
|
+
expect(t).toBeNull();
|
86
|
+
}), test("should keep agent selection when localStorage full", () => {
|
87
|
+
u = jest.fn((h, p) => {
|
88
|
+
throw new Error("Quota exceeded");
|
89
|
+
});
|
90
|
+
const {
|
91
|
+
result: e,
|
92
|
+
rerender: t
|
93
|
+
} = l(() => c(o));
|
94
|
+
let [n, s] = e.current;
|
95
|
+
expect(n).not.toBe(r), d(() => {
|
96
|
+
s(r);
|
97
|
+
}), t(), [n] = e.current, expect(n).toBe(r), expect(u).toHaveBeenCalledWith(o, r), expect(i).toHaveBeenCalledWith(o);
|
73
98
|
});
|
74
99
|
});
|
@@ -1,21 +1,28 @@
|
|
1
|
-
import { useState as l, useEffect as
|
2
|
-
const
|
3
|
-
const [
|
1
|
+
import { useState as l, useEffect as n } from "react";
|
2
|
+
const s = (t, o = !0) => {
|
3
|
+
const [e, a] = l(() => {
|
4
4
|
try {
|
5
|
-
const r = localStorage.getItem(
|
5
|
+
const r = localStorage.getItem(t);
|
6
6
|
if (!r)
|
7
7
|
return null;
|
8
8
|
if (o && !/^[a-zA-Z0-9_-]+$/.test(r))
|
9
9
|
throw new Error("Invalid characters in stored value");
|
10
10
|
return r;
|
11
11
|
} catch {
|
12
|
-
return localStorage.removeItem(
|
12
|
+
return localStorage.removeItem(t), null;
|
13
13
|
}
|
14
14
|
});
|
15
|
-
return
|
16
|
-
|
17
|
-
|
15
|
+
return n(() => {
|
16
|
+
try {
|
17
|
+
if (e) {
|
18
|
+
localStorage.setItem(t, e);
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
} catch {
|
22
|
+
}
|
23
|
+
localStorage.removeItem(t);
|
24
|
+
}, [e, t]), [e, a];
|
18
25
|
};
|
19
26
|
export {
|
20
|
-
|
27
|
+
s as default
|
21
28
|
};
|