@griddo/ax 12.17.1 → 12.18.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 (30) hide show
  1. package/package.json +4 -4
  2. package/src/__tests__/components/ConfigPanel/Form/ConnectedField/PageConnectedField/TemplateManager/TemplateManagerWhiteList.test.tsx +89 -0
  3. package/src/__tests__/components/Login/LoginCollapsible.test.tsx +5 -5
  4. package/src/__tests__/components/Login/LoginDropdownCard.test.tsx +1 -1
  5. package/src/__tests__/components/Login/LoginGriddoId.test.tsx +13 -13
  6. package/src/__tests__/components/Login/LoginPending.test.tsx +273 -0
  7. package/src/__tests__/components/SideModal/SideModal.test.tsx +84 -1
  8. package/src/__tests__/containers/App/loginSSO.test.ts +57 -0
  9. package/src/__tests__/containers/PageEditor/pasteModule.test.ts +116 -0
  10. package/src/__tests__/hooks/pendingNavigation.test.tsx +214 -0
  11. package/src/__tests__/locales/loginLocale.test.ts +13 -2
  12. package/src/__tests__/modules/Login/Login.test.tsx +4 -4
  13. package/src/__tests__/modules/Login/signInOut.test.tsx +19 -1
  14. package/src/components/Button/index.tsx +8 -0
  15. package/src/components/ConfigPanel/Form/ConnectedField/PageConnectedField/TemplateManager/index.tsx +2 -1
  16. package/src/components/Login/LoginGriddoId/index.tsx +14 -27
  17. package/src/components/Login/LoginGriddoId/style.tsx +7 -2
  18. package/src/components/Login/LoginSSO/index.tsx +33 -10
  19. package/src/components/Login/LoginSSO/style.tsx +18 -0
  20. package/src/components/Login/index.tsx +1 -1
  21. package/src/components/SideModal/index.tsx +3 -1
  22. package/src/containers/App/actions.tsx +11 -3
  23. package/src/containers/PageEditor/actions.tsx +12 -7
  24. package/src/hooks/index.tsx +2 -0
  25. package/src/hooks/pendingNavigation.ts +63 -0
  26. package/src/locales/en-US.ts +2 -1
  27. package/src/locales/es-ES.ts +2 -1
  28. package/src/modules/Login/index.tsx +6 -4
  29. package/src/schemas/pages/GlobalPage.ts +3 -5
  30. package/src/schemas/pages/Page.ts +3 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/ax",
3
3
  "description": "Griddo Author Experience",
4
- "version": "12.17.1",
4
+ "version": "12.18.1",
5
5
  "homepage": "https://griddo.io",
6
6
  "repository": {
7
7
  "type": "git",
@@ -128,7 +128,7 @@
128
128
  },
129
129
  "devDependencies": {
130
130
  "@biomejs/biome": "2.5.15",
131
- "@griddo/core": "12.17.1",
131
+ "@griddo/core": "12.18.1",
132
132
  "@stryker-mutator/core": "^10.0.0",
133
133
  "@stryker-mutator/vitest-runner": "^10.0.0",
134
134
  "@types/redux-mock-store": "1.5.0",
@@ -141,7 +141,7 @@
141
141
  "vitest-styled-components": "1.0.0"
142
142
  },
143
143
  "peerDependencies": {
144
- "@griddo/core": "12.17.1"
144
+ "@griddo/core": "12.18.1"
145
145
  },
146
146
  "babel": {
147
147
  "presets": [
@@ -174,5 +174,5 @@
174
174
  "publishConfig": {
175
175
  "access": "public"
176
176
  },
177
- "gitHead": "bf8ecb55af04ebcd8d14168b2bc41613dba88dda"
177
+ "gitHead": "2df0d76a0be014606a131b64f1e7ec4c9ccf5e2c"
178
178
  }
@@ -0,0 +1,89 @@
1
+ import { TemplateManager } from "@ax/components/ConfigPanel/Form/ConnectedField/PageConnectedField/TemplateManager";
2
+
3
+ import { render } from "@testing-library/react";
4
+
5
+ // sc-125145: captures the whiteList each zone passes down to Field (the module selector).
6
+ const fieldWhiteLists: Record<string, string[]> = {};
7
+
8
+ vi.mock("@ax/components/ConfigPanel/Form/ConnectedField/PageConnectedField/Field", () => ({
9
+ default: (props: { field: { key: string }; whiteList: string[] }) => {
10
+ fieldWhiteLists[props.field.key] = props.whiteList;
11
+ return null;
12
+ },
13
+ }));
14
+
15
+ const ZONE = "mainSection";
16
+
17
+ const packInjecting = (...moduleIds: string[]) => ({
18
+ id: "PACK",
19
+ modules: moduleIds.map((id) => ({ id, sectionList: { BasicTemplate: [ZONE] } })),
20
+ });
21
+
22
+ const renderZone = (whiteList: string[] | null | undefined, activatedPacks: any[]) => {
23
+ const zone: Record<string, unknown> = { title: "Main Section", type: "ComponentArray", key: ZONE };
24
+ if (whiteList !== undefined) zone.whiteList = whiteList;
25
+
26
+ const props: any = {
27
+ template: { component: "BasicTemplate", content: [zone] },
28
+ selectedTab: "content",
29
+ selectedContent: { template: { editorID: 1, [ZONE]: { modules: [] } } },
30
+ objKey: "template",
31
+ goTo: vi.fn(),
32
+ updateValue: vi.fn(),
33
+ pages: [],
34
+ actions: {},
35
+ activatedPacks,
36
+ activatedModules: [],
37
+ isTemplateActivated: true,
38
+ deleteError: vi.fn(),
39
+ errors: [],
40
+ theme: "griddo-alt-theme",
41
+ moduleCopy: null,
42
+ availableDataPacks: [],
43
+ lang: 4,
44
+ themeElements: null,
45
+ scrollEditorID: null,
46
+ isForm: false,
47
+ languages: [],
48
+ };
49
+
50
+ render(<TemplateManager {...props} />);
51
+ return fieldWhiteLists[ZONE];
52
+ };
53
+
54
+ describe("TemplateManager zone whiteList (sc-125145)", () => {
55
+ beforeEach(() => {
56
+ for (const key of Object.keys(fieldWhiteLists)) delete fieldWhiteLists[key];
57
+ });
58
+
59
+ it("offers a module once when it is both in the whitelist and injected by a data pack", () => {
60
+ expect(renderZone(["BasicContent", "CardCollection"], [packInjecting("BasicContent")])).toEqual([
61
+ "BasicContent",
62
+ "CardCollection",
63
+ ]);
64
+ });
65
+
66
+ it("offers exactly one module when the only whitelisted module is also injected by a data pack", () => {
67
+ expect(renderZone(["BasicContent"], [packInjecting("BasicContent")])).toHaveLength(1);
68
+ });
69
+
70
+ it("adds data pack modules that are not in the whitelist", () => {
71
+ expect(renderZone(["CardCollection"], [packInjecting("AModule")])).toEqual(["AModule", "CardCollection"]);
72
+ });
73
+
74
+ it.each([
75
+ ["undefined", undefined],
76
+ ["null", null],
77
+ ["[]", []],
78
+ ])("offers only the injected modules when the whitelist is %s", (_label, whiteList) => {
79
+ expect(renderZone(whiteList, [packInjecting("BasicContent")])).toEqual(["BasicContent"]);
80
+ });
81
+
82
+ it("sorts the deduplicated union", () => {
83
+ expect(renderZone(["Zeta", "Alfa"], [packInjecting("Medio", "Alfa")])).toEqual(["Alfa", "Medio", "Zeta"]);
84
+ });
85
+
86
+ it("collapses repeated modules inside the whitelist itself", () => {
87
+ expect(renderZone(["CardCollection", "CardCollection"], [])).toEqual(["CardCollection"]);
88
+ });
89
+ });
@@ -74,7 +74,7 @@ describe("[UC-AX-sign-in-out] formulario plegable con Griddo ID", () => {
74
74
  it("AC7 · plegado por defecto: SSO y desplegable visibles; email, contraseña y «Remember me» ocultos", () => {
75
75
  renderLogin();
76
76
 
77
- expect(screen.getByRole("button", { name: "Sign in with Griddo" })).toBeVisible();
77
+ expect(screen.getByRole("button", { name: "Sign in with Griddo ID" })).toBeVisible();
78
78
  expect(toggle()).toBeVisible();
79
79
  expect(toggle()).toHaveAttribute("aria-expanded", "false");
80
80
  expect(email()).not.toBeVisible();
@@ -176,10 +176,10 @@ describe("[UC-AX-sign-in-out] formulario plegable con Griddo ID", () => {
176
176
  expect(handleSubmit).toHaveBeenCalledTimes(1);
177
177
  });
178
178
 
179
- it("AC8 · «Sign in with Griddo» funciona con el formulario plegado", async () => {
179
+ it("AC8 · «Sign in with Griddo ID» funciona con el formulario plegado", async () => {
180
180
  const { handleGriddoId } = renderLogin();
181
181
 
182
- await userEvent.click(screen.getByRole("button", { name: "Sign in with Griddo" }));
182
+ await userEvent.click(screen.getByRole("button", { name: "Sign in with Griddo ID" }));
183
183
 
184
184
  expect(handleGriddoId).toHaveBeenCalledTimes(1);
185
185
  });
@@ -219,7 +219,7 @@ describe("[UC-AX-sign-in-out] formulario plegable con Griddo ID", () => {
219
219
 
220
220
  it("AC12 · al volver con Atrás (página restaurada de la caché) el botón vuelve a navegar", () => {
221
221
  const { handleGriddoId } = renderLogin({ GriddoIdEnabled: true });
222
- const button = screen.getByRole("button", { name: "Sign in with Griddo" });
222
+ const button = screen.getByRole("button", { name: "Sign in with Griddo ID" });
223
223
 
224
224
  fireEvent.click(button);
225
225
  fireEvent.click(button);
@@ -238,7 +238,7 @@ describe("[UC-AX-sign-in-out] formulario plegable con Griddo ID", () => {
238
238
 
239
239
  it("AC12 · un pageshow de una carga normal no reabre el botón", () => {
240
240
  const { handleGriddoId } = renderLogin({ GriddoIdEnabled: true });
241
- const button = screen.getByRole("button", { name: "Sign in with Griddo" });
241
+ const button = screen.getByRole("button", { name: "Sign in with Griddo ID" });
242
242
 
243
243
  fireEvent.click(button);
244
244
  act(() => {
@@ -53,7 +53,7 @@ const TOGGLE = "Login with email and password";
53
53
  const toggle = () => screen.getByRole("button", { name: TOGGLE });
54
54
  const card = () => screen.getByTestId("login-dropdown");
55
55
  const email = () => screen.getByPlaceholderText("Type your email");
56
- const sso = () => screen.getByRole("button", { name: "Sign in with Griddo" });
56
+ const sso = () => screen.getByRole("button", { name: "Sign in with Griddo ID" });
57
57
 
58
58
  describe("[UC-AX-sign-in-out] dropdown de email como botón (AC7/AC8/AC14)", () => {
59
59
  beforeEach(() => vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US"));
@@ -65,12 +65,12 @@ const setLanguage = (language: string) => vi.spyOn(window.navigator, "language",
65
65
  describe("Login con auth.griddo.io", () => {
66
66
  beforeEach(() => setLanguage("en-US"));
67
67
 
68
- it("con el flag activo «Sign in with Griddo» va sobre el desplegable del formulario de usuario y contraseña", () => {
68
+ it("con el flag activo «Sign in with Griddo ID» va sobre el desplegable del formulario de usuario y contraseña", () => {
69
69
  renderLogin({ GriddoIdEnabled: true });
70
70
 
71
71
  const email = screen.getByPlaceholderText("Type your email");
72
72
  const toggle = screen.getByRole("button", { name: "Login with email and password" });
73
- const griddo = screen.getByRole("button", { name: "Sign in with Griddo" });
73
+ const griddo = screen.getByRole("button", { name: "Sign in with Griddo ID" });
74
74
 
75
75
  expect(screen.getByText("Lost your password?")).toBeInTheDocument();
76
76
  expect(griddo.compareDocumentPosition(toggle) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
@@ -86,7 +86,7 @@ describe("Login con auth.griddo.io", () => {
86
86
  expect(screen.queryByText(/introduce your email and password/)).toBeNull();
87
87
  expect(
88
88
  screen
89
- .getByRole("button", { name: "Sign in with Griddo" })
89
+ .getByRole("button", { name: "Sign in with Griddo ID" })
90
90
  .querySelector('img[src="/img/logos/logoGriddoG.svg"]'),
91
91
  ).not.toBeNull();
92
92
  });
@@ -99,7 +99,7 @@ describe("Login con auth.griddo.io", () => {
99
99
 
100
100
  expect(screen.queryByRole("separator")).toBeNull();
101
101
  expect(
102
- screen.getByRole("button", { name: "Sign in with Griddo" }).compareDocumentPosition(toggle) &
102
+ screen.getByRole("button", { name: "Sign in with Griddo ID" }).compareDocumentPosition(toggle) &
103
103
  Node.DOCUMENT_POSITION_FOLLOWING,
104
104
  ).toBeTruthy();
105
105
  expect(
@@ -126,7 +126,7 @@ describe("Login con auth.griddo.io", () => {
126
126
  it("con el flag apagado el login es el de siempre y no hay botón nuevo ni separador", () => {
127
127
  renderLogin({ GriddoIdEnabled: false });
128
128
 
129
- expect(screen.queryByText("Sign in with Griddo")).toBeNull();
129
+ expect(screen.queryByText("Sign in with Griddo ID")).toBeNull();
130
130
  expect(screen.queryByText("o")).toBeNull();
131
131
  expect(screen.getByPlaceholderText("Type your email")).toBeInTheDocument();
132
132
  expect(screen.getByText("Login")).toBeInTheDocument();
@@ -136,8 +136,8 @@ describe("Login con auth.griddo.io", () => {
136
136
  const { handleGriddoId } = renderLogin({ GriddoIdEnabled: true, SSOActivated: true });
137
137
 
138
138
  expect(screen.getByRole("button", { name: /Microsoft ID/ })).toBeInTheDocument();
139
- expect(screen.queryByRole("button", { name: "Sign in with Griddo" })).toBeNull();
140
- expect(screen.queryByText("Sign in with Griddo")).toBeNull();
139
+ expect(screen.queryByRole("button", { name: "Sign in with Griddo ID" })).toBeNull();
140
+ expect(screen.queryByText("Sign in with Griddo ID")).toBeNull();
141
141
  expect(screen.queryByText("o")).toBeNull();
142
142
  expect(screen.queryByPlaceholderText("Type your email")).toBeNull();
143
143
  expect(screen.queryByText("Login")).toBeNull();
@@ -156,14 +156,14 @@ describe("Login con auth.griddo.io", () => {
156
156
  renderLogin({ SSOActivated: true });
157
157
 
158
158
  expect(screen.getByRole("button", { name: /Microsoft ID/ })).toBeInTheDocument();
159
- expect(screen.queryByText("Sign in with Griddo")).toBeNull();
159
+ expect(screen.queryByText("Sign in with Griddo ID")).toBeNull();
160
160
  expect(screen.queryByText("o")).toBeNull();
161
161
  expect(screen.queryByPlaceholderText("Type your email")).toBeNull();
162
162
  });
163
163
 
164
164
  it("el botón navega una sola vez aunque se pulse dos veces seguidas", () => {
165
165
  const { handleGriddoId } = renderLogin({ GriddoIdEnabled: true });
166
- const button = screen.getByRole("button", { name: "Sign in with Griddo" });
166
+ const button = screen.getByRole("button", { name: "Sign in with Griddo ID" });
167
167
 
168
168
  fireEvent.click(button);
169
169
  fireEvent.click(button);
@@ -193,16 +193,16 @@ describe("Login con auth.griddo.io", () => {
193
193
 
194
194
  expect(screen.queryByPlaceholderText("Type your email")).toBeNull();
195
195
  expect(screen.queryByText("Login")).toBeNull();
196
- expect(screen.queryByRole("button", { name: "Sign in with Griddo" })).toBeNull();
196
+ expect(screen.queryByRole("button", { name: "Sign in with Griddo ID" })).toBeNull();
197
197
  expect(screen.queryByText("o")).toBeNull();
198
198
  expect(screen.getByText(/Welcome/)).toBeInTheDocument();
199
199
  expect(screen.getAllByRole("button")).toHaveLength(1);
200
200
  });
201
201
 
202
202
  it.each([
203
- ["en-US", "Sign in with Griddo", "Login with email and password"],
204
- ["es-ES", "Sign in with Griddo", "Login with email and password"],
205
- ["fr-FR", "Sign in with Griddo", "Login with email and password"],
203
+ ["en-US", "Sign in with Griddo ID", "Login with email and password"],
204
+ ["es-ES", "Sign in with Griddo ID", "Login with email and password"],
205
+ ["fr-FR", "Sign in with Griddo ID", "Login with email and password"],
206
206
  ])("idioma %s", (language, button, toggle) => {
207
207
  setLanguage(language);
208
208
  renderLogin({ GriddoIdEnabled: true });
@@ -0,0 +1,273 @@
1
+ import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
2
+ import { ThemeProvider } from "styled-components";
3
+ import "@testing-library/jest-dom";
4
+
5
+ import Login, { type ILoginProps } from "@ax/components/Login";
6
+ import { parseTheme } from "@ax/helpers";
7
+ import globalTheme from "@ax/themes/theme.json";
8
+
9
+ afterEach(cleanup);
10
+
11
+ const settings = {
12
+ SSOActivated: false,
13
+ GriddoIdEnabled: false,
14
+ SSOWelcomeText: "",
15
+ } as ILoginProps["settings"];
16
+
17
+ const renderLogin = (flags: Partial<ILoginProps["settings"]>, props: Partial<ILoginProps> = {}) =>
18
+ render(
19
+ <ThemeProvider theme={parseTheme(globalTheme)}>
20
+ <Login
21
+ handleSubmit={vi.fn()}
22
+ email=""
23
+ handleEmail={vi.fn()}
24
+ password=""
25
+ handlePassword={vi.fn()}
26
+ isLoggingIn={false}
27
+ rememberMe={false}
28
+ handleRememberMe={vi.fn()}
29
+ isLoginSuccess={false}
30
+ handleLoginSuccess={vi.fn()}
31
+ handleSSO={vi.fn()}
32
+ handleGriddoId={vi.fn()}
33
+ errorSSO={null}
34
+ {...props}
35
+ settings={{ ...settings, ...flags }}
36
+ />
37
+ </ThemeProvider>,
38
+ );
39
+
40
+ const firePageShow = (persisted: boolean) => {
41
+ const event = new Event("pageshow") as PageTransitionEvent;
42
+ Object.defineProperty(event, "persisted", { value: persisted });
43
+ act(() => {
44
+ window.dispatchEvent(event);
45
+ });
46
+ };
47
+
48
+ const deferred = <T,>() => {
49
+ let resolve!: (v: T) => void;
50
+ const promise = new Promise<T>((r) => {
51
+ resolve = r;
52
+ });
53
+ return { promise, resolve };
54
+ };
55
+
56
+ const ssoButton = () => screen.getByRole("button", { name: /Microsoft ID|Connecting…/ });
57
+
58
+ describe("SSO · estado conectando", () => {
59
+ it("AC6 · el clic deshabilita el botón con loader y «Connecting…», y sustituye al icono de Microsoft", async () => {
60
+ const d = deferred<string | null>();
61
+ const { container } = renderLogin({ SSOActivated: true }, { handleSSO: () => d.promise });
62
+
63
+ expect(container.querySelector("svg")).not.toBeNull();
64
+ fireEvent.click(ssoButton());
65
+
66
+ const button = screen.getByRole("button", { name: /Connecting…/ });
67
+ expect(button).toBeDisabled();
68
+ expect(button).toHaveAttribute("aria-busy", "true");
69
+ expect(screen.queryByText("Microsoft ID")).toBeNull();
70
+ expect(button.querySelector("svg")).not.toBeNull();
71
+ expect(container.querySelector('[name="microsoft"], use[href*="microsoft"]')).toBeNull();
72
+ await act(async () => d.resolve("url"));
73
+ });
74
+
75
+ it("AC6 · sin conexión en curso el botón no está ocupado", () => {
76
+ renderLogin({ SSOActivated: true });
77
+
78
+ expect(ssoButton()).not.toHaveAttribute("aria-busy", "true");
79
+ expect(ssoButton()).toBeEnabled();
80
+ });
81
+
82
+ it("AC6 · clics repetidos lanzan un único flujo", async () => {
83
+ const d = deferred<string | null>();
84
+ const handleSSO = vi.fn(() => d.promise);
85
+ renderLogin({ SSOActivated: true }, { handleSSO });
86
+
87
+ fireEvent.click(ssoButton());
88
+ fireEvent.click(screen.getByRole("button", { name: /Connecting…/ }));
89
+
90
+ expect(handleSSO).toHaveBeenCalledTimes(1);
91
+ await act(async () => d.resolve("url"));
92
+ });
93
+
94
+ it("AC6 · dos clics en el mismo instante lanzan un único flujo", async () => {
95
+ const handleSSO = vi.fn(async () => "url");
96
+ renderLogin({ SSOActivated: true }, { handleSSO });
97
+ const button = ssoButton();
98
+
99
+ await act(async () => {
100
+ fireEvent.click(button);
101
+ fireEvent.click(button);
102
+ });
103
+
104
+ expect(handleSSO).toHaveBeenCalledTimes(1);
105
+ });
106
+
107
+ it.each([
108
+ ["null", null],
109
+ ["cadena vacía", ""],
110
+ ])("AC6 · un retorno %s libera el botón y se puede reintentar", async (_n, value) => {
111
+ const handleSSO = vi.fn(async () => value);
112
+ renderLogin({ SSOActivated: true }, { handleSSO });
113
+
114
+ await act(async () => {
115
+ fireEvent.click(ssoButton());
116
+ });
117
+
118
+ expect(ssoButton()).toBeEnabled();
119
+ expect(screen.getByText("Microsoft ID")).toBeInTheDocument();
120
+
121
+ await act(async () => {
122
+ fireEvent.click(ssoButton());
123
+ });
124
+ expect(handleSSO).toHaveBeenCalledTimes(2);
125
+ });
126
+
127
+ it("AC6 · con URL el botón permanece deshabilitado", async () => {
128
+ renderLogin({ SSOActivated: true }, { handleSSO: async () => "https://sso" });
129
+
130
+ await act(async () => {
131
+ fireEvent.click(ssoButton());
132
+ });
133
+
134
+ expect(screen.getByRole("button", { name: /Connecting…/ })).toBeDisabled();
135
+ });
136
+
137
+ it("AC6 · «Try again» muestra y respeta el estado conectando", async () => {
138
+ const handleSSO = vi.fn(async () => "url");
139
+ renderLogin({ SSOActivated: true }, { handleSSO, errorSSO: "Algo falló" });
140
+
141
+ await act(async () => {
142
+ fireEvent.click(screen.getByRole("button", { name: "Try again" }));
143
+ });
144
+
145
+ const button = screen.getByRole("button", { name: /Connecting…/ });
146
+ expect(button).toBeDisabled();
147
+ expect(button).toHaveAttribute("aria-busy", "true");
148
+ fireEvent.click(button);
149
+ expect(handleSSO).toHaveBeenCalledTimes(1);
150
+ });
151
+
152
+ it("AC6 · el estado conectando persiste al cambiar errorSSO o settings", async () => {
153
+ const handleSSO = vi.fn(async () => "url");
154
+ const props = (errorSSO: string | null, welcome: string) => (
155
+ <ThemeProvider theme={parseTheme(globalTheme)}>
156
+ <Login
157
+ handleSubmit={vi.fn()}
158
+ email=""
159
+ handleEmail={vi.fn()}
160
+ password=""
161
+ handlePassword={vi.fn()}
162
+ isLoggingIn={false}
163
+ rememberMe={false}
164
+ handleRememberMe={vi.fn()}
165
+ isLoginSuccess={false}
166
+ handleLoginSuccess={vi.fn()}
167
+ handleSSO={handleSSO}
168
+ errorSSO={errorSSO}
169
+ settings={{ ...settings, SSOActivated: true, SSOWelcomeText: welcome }}
170
+ />
171
+ </ThemeProvider>
172
+ );
173
+ const { rerender } = render(props(null, "a"));
174
+
175
+ await act(async () => {
176
+ fireEvent.click(ssoButton());
177
+ });
178
+ rerender(props("error", "b"));
179
+
180
+ expect(screen.getByRole("button", { name: /Connecting…/ })).toBeDisabled();
181
+ });
182
+
183
+ it("AC12 · pageshow persisted reactiva el botón SSO", async () => {
184
+ renderLogin({ SSOActivated: true }, { handleSSO: async () => "url" });
185
+
186
+ await act(async () => {
187
+ fireEvent.click(ssoButton());
188
+ });
189
+ firePageShow(true);
190
+
191
+ expect(ssoButton()).toBeEnabled();
192
+ expect(screen.getByText("Microsoft ID")).toBeInTheDocument();
193
+ });
194
+
195
+ it("AC6 · pageshow no persistido no reactiva el botón", async () => {
196
+ renderLogin({ SSOActivated: true }, { handleSSO: async () => "url" });
197
+
198
+ await act(async () => {
199
+ fireEvent.click(ssoButton());
200
+ });
201
+ firePageShow(false);
202
+
203
+ expect(screen.getByRole("button", { name: /Connecting…/ })).toBeDisabled();
204
+ });
205
+
206
+ it("AC6 · desmontar durante la conexión no deja efectos", async () => {
207
+ const d = deferred<string | null>();
208
+ const errors = vi.spyOn(console, "error").mockImplementation(() => undefined);
209
+ const remove = vi.spyOn(window, "removeEventListener");
210
+ const { unmount } = renderLogin({ SSOActivated: true }, { handleSSO: () => d.promise });
211
+
212
+ fireEvent.click(ssoButton());
213
+ unmount();
214
+ await act(async () => d.resolve(null));
215
+
216
+ expect(remove).toHaveBeenCalledWith("pageshow", expect.any(Function));
217
+ expect(errors).not.toHaveBeenCalled();
218
+ });
219
+
220
+ it("AC6 · aria-busy y Enter/Espacio no relanzan el flujo (botón deshabilitado)", async () => {
221
+ const handleSSO = vi.fn(async () => "url");
222
+ renderLogin({ SSOActivated: true }, { handleSSO });
223
+
224
+ await act(async () => {
225
+ fireEvent.click(ssoButton());
226
+ });
227
+ const button = screen.getByRole("button", { name: /Connecting…/ });
228
+ fireEvent.keyDown(button, { key: "Enter" });
229
+ fireEvent.keyDown(button, { key: " " });
230
+
231
+ expect(button).toBeDisabled();
232
+ expect(button).toHaveAttribute("aria-busy", "true");
233
+ expect(handleSSO).toHaveBeenCalledTimes(1);
234
+ });
235
+ });
236
+
237
+ describe("Sign in with Griddo · estado conectando", () => {
238
+ const griddoButton = () => screen.getByRole("button", { name: /Sign in with Griddo|Connecting…/ });
239
+
240
+ it("AC12 · el clic deshabilita el botón con loader y navega una sola vez", async () => {
241
+ const handleGriddoId = vi.fn();
242
+ renderLogin({ GriddoIdEnabled: true }, { handleGriddoId });
243
+
244
+ await act(async () => {
245
+ fireEvent.click(griddoButton());
246
+ });
247
+ const button = screen.getByRole("button", { name: /Connecting…/ });
248
+ fireEvent.click(button);
249
+
250
+ expect(button).toBeDisabled();
251
+ expect(button).toHaveAttribute("aria-busy", "true");
252
+ expect(button.querySelector("svg")).not.toBeNull();
253
+ expect(button.querySelector('img[src="/img/logos/logoGriddoG.svg"]')).toBeNull();
254
+ expect(handleGriddoId).toHaveBeenCalledTimes(1);
255
+ });
256
+
257
+ it("AC12 · tras restaurar desde la caché el botón vuelve a funcionar y navega otra vez", async () => {
258
+ const handleGriddoId = vi.fn();
259
+ renderLogin({ GriddoIdEnabled: true }, { handleGriddoId });
260
+
261
+ await act(async () => {
262
+ fireEvent.click(griddoButton());
263
+ });
264
+ firePageShow(true);
265
+
266
+ expect(griddoButton()).toBeEnabled();
267
+ expect(screen.getByText("Sign in with Griddo ID")).toBeInTheDocument();
268
+ await act(async () => {
269
+ fireEvent.click(griddoButton());
270
+ });
271
+ expect(handleGriddoId).toHaveBeenCalledTimes(2);
272
+ });
273
+ });
@@ -3,8 +3,8 @@ import { parseTheme } from "@ax/helpers";
3
3
  import globalTheme from "@ax/themes/theme.json";
4
4
 
5
5
  import { cleanup, fireEvent, render, screen } from "@testing-library/react";
6
- import { type CalledWithMock, mock } from "vitest-mock-extended";
7
6
  import { ThemeProvider } from "styled-components";
7
+ import { type CalledWithMock, mock } from "vitest-mock-extended";
8
8
 
9
9
  // Stub the page schemas so the component tree does not pull the real catalogue.
10
10
  // These are the module's only exports; under ESM the mock has to declare them
@@ -403,3 +403,86 @@ describe("SideModal component events", () => {
403
403
  expect(toggleModal).not.toHaveBeenCalled();
404
404
  });
405
405
  });
406
+
407
+ // sc-125145: repeated options must get distinct React keys, or searching leaves ghost copies.
408
+ describe("SideModal with repeated options", () => {
409
+ const duplicateKeyWarnings = (spy: { mock: { calls: unknown[][] } }) =>
410
+ spy.mock.calls.filter((call) => call.some((arg) => typeof arg === "string" && arg.includes("same key")));
411
+
412
+ const renderModal = (overrides: Partial<ISideModalProps>) =>
413
+ render(
414
+ <ThemeProvider theme={parseTheme(globalTheme)}>
415
+ <SideModal {...makeProps(overrides)} />
416
+ </ThemeProvider>,
417
+ );
418
+
419
+ const repeated = ["BasicContent", "BasicContent", "CardCollection"];
420
+ const categories = [
421
+ { featured: true, label: "All", value: "all" },
422
+ { label: "Content", value: "content" },
423
+ { label: "Collections", value: "collections" },
424
+ ];
425
+
426
+ it("shows the same options after searching and clearing the search", () => {
427
+ const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
428
+ renderModal({ whiteList: repeated, showSearch: true });
429
+
430
+ const input = screen.getByTestId("search-input");
431
+ fireEvent.change(input, { target: { value: "card" } });
432
+ fireEvent.change(input, { target: { value: "" } });
433
+
434
+ expect(screen.getAllByTestId("side-modal-option")).toHaveLength(3);
435
+ expect(duplicateKeyWarnings(errorSpy)).toHaveLength(0);
436
+ });
437
+
438
+ it("filters repeated options by search without leaving copies", () => {
439
+ renderModal({ whiteList: repeated, showSearch: true });
440
+
441
+ fireEvent.change(screen.getByTestId("search-input"), { target: { value: "basic" } });
442
+
443
+ const options = screen.getAllByTestId("side-modal-option");
444
+ expect(options).toHaveLength(2);
445
+ expect(options.map((o) => o.textContent)).toEqual(["Basic Content", "Basic Content"]);
446
+ });
447
+
448
+ it("shows the right options per category when switching categories", () => {
449
+ const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
450
+ renderModal({ whiteList: repeated, categories });
451
+
452
+ const filters = screen.getAllByTestId("side-modal-nav-link");
453
+ fireEvent.click(filters[1]);
454
+ expect(screen.getAllByTestId("side-modal-option")).toHaveLength(2);
455
+ fireEvent.click(filters[0]);
456
+ expect(screen.getAllByTestId("side-modal-option")).toHaveLength(3);
457
+ expect(duplicateKeyWarnings(errorSpy)).toHaveLength(0);
458
+ });
459
+
460
+ it("adds the module and closes when choosing the second copy", () => {
461
+ const onClick = vi.fn();
462
+ const toggleModal = vi.fn();
463
+ renderModal({ whiteList: repeated, onClick, toggleModal });
464
+
465
+ fireEvent.click(screen.getAllByTestId("side-modal-option")[1]);
466
+
467
+ expect(onClick).toHaveBeenCalledWith("BasicContent");
468
+ expect(toggleModal).toHaveBeenCalled();
469
+ });
470
+
471
+ it("renders repeated object options without id or editorID", () => {
472
+ const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
473
+ renderModal({
474
+ componentOptions: { a: { component: "BasicContent" }, b: { component: "BasicContent" } } as any,
475
+ whiteList: ["BasicContent"],
476
+ optionsType: "components",
477
+ });
478
+
479
+ expect(screen.getAllByTestId("side-modal-option")).toHaveLength(2);
480
+ expect(duplicateKeyWarnings(errorSpy)).toHaveLength(0);
481
+ });
482
+
483
+ it("keeps showing non-repeated options unchanged", () => {
484
+ renderModal({ whiteList: ["BasicContent", "CardCollection"] });
485
+
486
+ expect(screen.getAllByTestId("side-modal-option")).toHaveLength(2);
487
+ });
488
+ });