@griddo/ax 12.15.0-beta.1 → 12.15.0

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 (75) hide show
  1. package/README.md +0 -1
  2. package/package.json +4 -7
  3. package/src/GlobalStore.tsx +25 -32
  4. package/src/__tests__/components/Fields/FileField/FileField.test.tsx +6 -33
  5. package/src/__tests__/components/FieldsBehavior/FieldsBehavior.test.tsx +3 -5
  6. package/src/__tests__/modules/GlobalSettings/Llms/Llms.uc.test.tsx +2861 -0
  7. package/src/__tests__/modules/Redirects/Redirects/Redirects.create.test.tsx +0 -19
  8. package/src/__tests__/modules/Redirects/Redirects/Redirects.edit.test.tsx +0 -19
  9. package/src/__tests__/modules/Redirects/Redirects/Redirects.filter.test.tsx +0 -19
  10. package/src/api/domains.tsx +98 -2
  11. package/src/api/global.tsx +1 -24
  12. package/src/api/utils.tsx +12 -22
  13. package/src/components/FieldsBehavior/index.tsx +1 -3
  14. package/src/components/Login/LoginForm/index.tsx +2 -7
  15. package/src/components/Login/index.tsx +1 -13
  16. package/src/components/index.tsx +7 -11
  17. package/src/containers/App/actions.tsx +5 -110
  18. package/src/containers/App/interfaces.tsx +2 -2
  19. package/src/containers/App/reducer.tsx +0 -9
  20. package/src/containers/Users/actions.tsx +24 -28
  21. package/src/{components/CategoryCell/buildCategoryColumns.tsx → helpers/categoryColumns.tsx} +2 -3
  22. package/src/{components/FieldsBehavior/getFieldByPath.tsx → helpers/fields.tsx} +1 -1
  23. package/src/helpers/index.tsx +5 -4
  24. package/src/locales/en-US.ts +0 -7
  25. package/src/locales/es-ES.ts +0 -7
  26. package/src/locales/index.ts +0 -10
  27. package/src/modules/App/Routing/NavMenu/index.tsx +4 -4
  28. package/src/modules/Content/PageItem/index.tsx +8 -6
  29. package/src/modules/GlobalSettings/Llms/AutomaticSelection/index.tsx +317 -0
  30. package/src/modules/GlobalSettings/Llms/DomainList/index.tsx +65 -0
  31. package/src/modules/GlobalSettings/Llms/IndexModelEditor/index.tsx +325 -0
  32. package/src/modules/GlobalSettings/Llms/MirrorExample/index.tsx +61 -0
  33. package/src/modules/GlobalSettings/Llms/MirrorOptions/index.tsx +82 -0
  34. package/src/modules/GlobalSettings/Llms/Outline/index.tsx +183 -0
  35. package/src/modules/GlobalSettings/Llms/PagePicker/index.tsx +105 -0
  36. package/src/modules/GlobalSettings/Llms/Preview/index.tsx +65 -0
  37. package/src/modules/GlobalSettings/Llms/ResolvedPages/index.tsx +191 -0
  38. package/src/modules/GlobalSettings/Llms/SectionEditor/index.tsx +262 -0
  39. package/src/modules/GlobalSettings/Llms/atoms.tsx +37 -0
  40. package/src/modules/GlobalSettings/Llms/index.tsx +383 -0
  41. package/src/modules/GlobalSettings/Llms/style.tsx +541 -0
  42. package/src/modules/GlobalSettings/Llms/utils.tsx +307 -0
  43. package/src/modules/GlobalSettings/index.tsx +7 -0
  44. package/src/modules/Login/index.tsx +2 -12
  45. package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/index.tsx +8 -6
  46. package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/index.tsx +11 -9
  47. package/src/routes/multisite.tsx +8 -1
  48. package/src/routes/publicRoutes.tsx +0 -3
  49. package/src/schemas/pages/GlobalPage.ts +2 -2
  50. package/src/schemas/pages/Page.ts +2 -2
  51. package/src/types/index.tsx +80 -12
  52. package/src/types/llms.tsx +315 -0
  53. package/src/__tests__/GlobalStore.session.test.tsx +0 -98
  54. package/src/__tests__/api/global.test.ts +0 -64
  55. package/src/__tests__/api/session.test.ts +0 -311
  56. package/src/__tests__/api/sessionRenewal.test.ts +0 -705
  57. package/src/__tests__/api/utils.test.ts +0 -373
  58. package/src/__tests__/components/Login/LoginGriddoId.test.tsx +0 -195
  59. package/src/__tests__/components/SsoDenied/SsoDenied.test.tsx +0 -86
  60. package/src/__tests__/containers/App/reducer.griddoId.test.ts +0 -18
  61. package/src/__tests__/containers/App/session.test.ts +0 -397
  62. package/src/__tests__/helpers/griddoId.test.ts +0 -56
  63. package/src/__tests__/locales/loginLocale.test.ts +0 -52
  64. package/src/__tests__/modules/App/Routing/NavMenu.test.tsx +0 -54
  65. package/src/__tests__/modules/Login/Login.test.tsx +0 -151
  66. package/src/__tests__/modules/SsoDenied/SsoDenied.test.tsx +0 -30
  67. package/src/__tests__/routes/publicRoutes.test.ts +0 -36
  68. package/src/api/session.tsx +0 -197
  69. package/src/api/sessionRenewal.tsx +0 -114
  70. package/src/components/Login/LoginGriddoId/index.tsx +0 -46
  71. package/src/components/Login/LoginGriddoId/style.tsx +0 -35
  72. package/src/components/SsoDenied/index.tsx +0 -46
  73. package/src/components/SsoDenied/style.tsx +0 -37
  74. package/src/helpers/griddoId.ts +0 -28
  75. package/src/modules/SsoDenied/index.tsx +0 -9
@@ -1,397 +0,0 @@
1
- import { global, languages, users } from "@ax/api";
2
- import { appActions } from "@ax/containers/App";
3
- import { LOGOUT, SET_TOKEN } from "@ax/containers/App/constants";
4
- import { appReducer } from "@ax/containers/App/reducer";
5
- import { usersActions } from "@ax/containers/Users";
6
-
7
- import type { Mock } from "vitest";
8
-
9
- import { getSession, registerSessionBridge, resetSessionState, setSession } from "../../../api/session";
10
- import history from "../../../routes/history";
11
-
12
- const persisted = (token: string, refreshToken: string, sessionUpdatedAt: number) =>
13
- JSON.stringify({
14
- token: JSON.stringify(token),
15
- refreshToken: JSON.stringify(refreshToken),
16
- sessionUpdatedAt: JSON.stringify(sessionUpdatedAt),
17
- _persist: JSON.stringify({ version: -1, rehydrated: true }),
18
- });
19
-
20
- let onExpired: Mock<() => void>;
21
-
22
- beforeEach(() => {
23
- localStorage.clear();
24
- resetSessionState();
25
- onExpired = vi.fn();
26
- registerSessionBridge({ onExpired });
27
- });
28
-
29
- describe("login guarda el par de sesión", () => {
30
- const runLogin = async (data: Record<string, unknown>) => {
31
- const dispatch = vi.fn();
32
- vi.spyOn(global, "login").mockResolvedValue({ status: 200, data } as any);
33
- vi.spyOn(languages, "getLanguages").mockResolvedValue({ status: 200, data: { items: [] } } as any);
34
- vi.spyOn(usersActions, "getUser").mockReturnValue((async () => undefined) as any);
35
- const result = await appActions.login({ email: "a@b.c", password: "x" })(dispatch, vi.fn() as any);
36
- return { dispatch, result };
37
- };
38
-
39
- it("login con refresh: acción SET_TOKEN con acceso, refresh y versión; sesión en memoria", async () => {
40
- const { dispatch, result } = await runLogin({ id: 7, token: "jwt", refreshToken: "r1" });
41
-
42
- expect(result).toBe(true);
43
- const setToken = dispatch.mock.calls.map(([a]) => a).find((a) => a.type === SET_TOKEN);
44
- expect(setToken.payload).toEqual({ token: "jwt", refreshToken: "r1", sessionUpdatedAt: expect.any(Number) });
45
- expect(setToken.payload.sessionUpdatedAt).toBeGreaterThan(0);
46
- expect(getSession()).toMatchObject({ token: "jwt", refreshToken: "r1" });
47
- });
48
-
49
- it("login con API antigua (sin refresh): refresh vacío y sesión sin refresh", async () => {
50
- const { dispatch } = await runLogin({ id: 7, token: "jwt" });
51
-
52
- const setToken = dispatch.mock.calls.map(([a]) => a).find((a) => a.type === SET_TOKEN);
53
- expect(setToken.payload.refreshToken).toBe("");
54
- expect(getSession()).toMatchObject({ token: "jwt", refreshToken: null });
55
- });
56
-
57
- it("el login SSO (petitionId) usa el mismo camino y guarda el refresh", async () => {
58
- const dispatch = vi.fn();
59
- const login = vi.spyOn(global, "login").mockResolvedValue({
60
- status: 200,
61
- data: { id: 1, token: "sso-jwt", refreshToken: "sso-r" },
62
- } as any);
63
- vi.spyOn(languages, "getLanguages").mockResolvedValue({ status: 200, data: { items: [] } } as any);
64
- vi.spyOn(usersActions, "getUser").mockReturnValue((async () => undefined) as any);
65
-
66
- await appActions.login({ petitionId: "abc" })(dispatch, vi.fn() as any);
67
-
68
- expect(login).toHaveBeenCalledWith({ username: undefined, password: undefined, petitionId: "abc" });
69
- expect(getSession()).toMatchObject({ token: "sso-jwt", refreshToken: "sso-r" });
70
- });
71
- });
72
-
73
- describe("createPassword y cambio de contraseña guardan la sesión nueva", () => {
74
- it("createPassword guarda acceso y refresh", async () => {
75
- const dispatch = vi.fn();
76
- vi.spyOn(global, "createPassword").mockResolvedValue({
77
- status: 200,
78
- data: { token: "t", refreshToken: "r" },
79
- } as any);
80
- vi.spyOn(usersActions, "getRoles").mockReturnValue((async () => undefined) as any);
81
- vi.spyOn(usersActions, "getUser").mockReturnValue((async () => undefined) as any);
82
-
83
- await usersActions.createPassword(5, { password: "p" } as any)(dispatch, vi.fn() as any);
84
-
85
- const setToken = dispatch.mock.calls.map(([a]) => a).find((a) => a?.type === SET_TOKEN);
86
- expect(setToken.payload).toMatchObject({ token: "t", refreshToken: "r" });
87
- expect(getSession()).toMatchObject({ token: "t", refreshToken: "r" });
88
- });
89
-
90
- it("cambiar la contraseña devuelve par nuevo y AX sustituye la sesión", async () => {
91
- setSession("old", "r-old");
92
- const dispatch = vi.fn();
93
- vi.spyOn(users, "updatePassword").mockResolvedValue({
94
- status: 200,
95
- data: { token: "new", refreshToken: "r-new" },
96
- } as any);
97
-
98
- const ok = await usersActions.updatePassword(5, { password: "x" })(dispatch);
99
-
100
- expect(ok).toBe(true);
101
- expect(getSession()).toMatchObject({ token: "new", refreshToken: "r-new" });
102
- expect(dispatch.mock.calls.map(([a]) => a).some((a) => a?.type === SET_TOKEN && a.payload.token === "new")).toBe(
103
- true,
104
- );
105
- });
106
-
107
- it("cambiar la contraseña de otra persona (sin par en la respuesta) no toca la sesión", async () => {
108
- setSession("mine", "r-mine");
109
- const dispatch = vi.fn();
110
- vi.spyOn(users, "updatePassword").mockResolvedValue({ status: 200, data: {} } as any);
111
-
112
- await usersActions.updatePassword(9, { password: "x" })(dispatch);
113
-
114
- expect(getSession()).toMatchObject({ token: "mine", refreshToken: "r-mine" });
115
- expect(dispatch.mock.calls.some(([a]) => a?.type === SET_TOKEN)).toBe(false);
116
- });
117
-
118
- it("un cambio de contraseña fallido no toca la sesión", async () => {
119
- setSession("mine", "r-mine");
120
- vi.spyOn(users, "updatePassword").mockResolvedValue({ status: 400, data: { code: 400, message: "x" } } as any);
121
-
122
- await usersActions.updatePassword(5, { password: "x" })(vi.fn());
123
-
124
- expect(getSession()).toMatchObject({ token: "mine" });
125
- });
126
- });
127
-
128
- describe("logout", () => {
129
- it("avisa a la API con el acceso (aunque esté caducado) y el refresh, y limpia el estado local", () => {
130
- localStorage.setItem("persist:app", persisted("expired-jwt", "r1", 5));
131
- localStorage.setItem("sitesConfig", "keep");
132
- localStorage.setItem("other", "drop");
133
- const logoutApi = vi.spyOn(global, "logout").mockResolvedValue({ status: 204 } as any);
134
-
135
- const action = appActions.logout();
136
-
137
- expect(logoutApi).toHaveBeenCalledWith({ token: "expired-jwt", refreshToken: "r1" });
138
- expect(action).toEqual({ type: LOGOUT, payload: { token: "", refreshToken: "", sessionUpdatedAt: 0 } });
139
- expect(localStorage.getItem("other")).toBeNull();
140
- expect(localStorage.getItem("sitesConfig")).toBe("keep");
141
- expect(getSession()).toBeNull();
142
- });
143
-
144
- it("sin sesión no llama a la API", () => {
145
- const logoutApi = vi.spyOn(global, "logout").mockResolvedValue({ status: 204 } as any);
146
-
147
- appActions.logout();
148
-
149
- expect(logoutApi).not.toHaveBeenCalled();
150
- });
151
-
152
- it("si la API de logout falla o rechaza, el cierre local no se rompe", async () => {
153
- setSession("jwt", "r");
154
- vi.spyOn(global, "logout").mockRejectedValue(new Error("boom"));
155
-
156
- expect(() => appActions.logout()).not.toThrow();
157
- await Promise.resolve();
158
- expect(getSession()).toBeNull();
159
- });
160
-
161
- it("un 401 del logout no vuelve a despachar el cierre de sesión", async () => {
162
- setSession("jwt", "r");
163
- vi.spyOn(global, "logout").mockResolvedValue({ status: 401 } as any);
164
-
165
- appActions.logout();
166
- await Promise.resolve();
167
-
168
- expect(onExpired).not.toHaveBeenCalled();
169
- });
170
-
171
- it("el reducer vacía acceso, refresh y versión", () => {
172
- const state = appReducer(
173
- { ...appReducer(undefined, { type: "x" }), token: "t", refreshToken: "r", sessionUpdatedAt: 9 } as Parameters<
174
- typeof appReducer
175
- >[0],
176
- appActions.logout(),
177
- );
178
- expect(state).toMatchObject({ token: "", refreshToken: "", sessionUpdatedAt: 0 });
179
- });
180
- });
181
-
182
- describe("logoutAndNavigate", () => {
183
- it("navega a /logout y marca la sesión como cerrada (un cierre remoto no lanza otro)", async () => {
184
- const push = vi.spyOn(history, "push").mockImplementation(() => undefined);
185
-
186
- await appActions.logoutAndNavigate()(vi.fn());
187
-
188
- expect(push).toHaveBeenCalledWith("/logout", undefined);
189
- // después de un cierre manual/remoto, un 401 en vuelo no vuelve a despachar
190
- const { endSession } = await import("../../../api/session");
191
- endSession();
192
- expect(onExpired).not.toHaveBeenCalled();
193
- });
194
- });
195
-
196
- describe("logoutAndEndCentralSession (botón «Logout» del menú)", () => {
197
- const URL_OK = "https://api.uni.es/sso/logout";
198
- let assign: Mock<(url: string) => void>;
199
- let push: ReturnType<typeof vi.spyOn>;
200
-
201
- const state = (GriddoIdEnabled: boolean) => () => ({ app: { globalSettings: { GriddoIdEnabled } } }) as never;
202
- const run = (dispatch = vi.fn(), enabled = true) => appActions.logoutAndEndCentralSession()(dispatch, state(enabled));
203
-
204
- beforeEach(() => {
205
- assign = vi.fn();
206
- vi.stubGlobal("location", { ...window.location, assign });
207
- push = vi.spyOn(history, "push").mockImplementation(() => undefined);
208
- setSession("jwt", "r1");
209
- });
210
-
211
- afterEach(() => {
212
- vi.useRealTimers();
213
- vi.unstubAllGlobals();
214
- });
215
-
216
- it("sesión de Griddo ID: limpia lo local, navega a la URL de cierre central y no pasa por /logout", async () => {
217
- localStorage.setItem("sitesConfig", "keep");
218
- localStorage.setItem("other", "drop");
219
- const logoutApi = vi
220
- .spyOn(global, "logout")
221
- .mockResolvedValue({ status: 200, data: { endSessionUrl: URL_OK } } as any);
222
- const dispatch = vi.fn();
223
-
224
- await run(dispatch);
225
-
226
- expect(logoutApi).toHaveBeenCalledTimes(1);
227
- expect(logoutApi).toHaveBeenCalledWith({ token: "jwt", refreshToken: "r1" });
228
- expect(assign).toHaveBeenCalledExactlyOnceWith(URL_OK);
229
- expect(push).not.toHaveBeenCalled();
230
- expect(getSession()).toBeNull();
231
- expect(localStorage.getItem("other")).toBeNull();
232
- expect(localStorage.getItem("sitesConfig")).toBe("keep");
233
- expect(dispatch).toHaveBeenCalledWith({
234
- type: LOGOUT,
235
- payload: { token: "", refreshToken: "", sessionUpdatedAt: 0 },
236
- });
237
- });
238
-
239
- it("marca la sesión como cerrada: un 401 en vuelo no lanza otro cierre", async () => {
240
- vi.spyOn(global, "logout").mockResolvedValue({ status: 200, data: { endSessionUrl: URL_OK } } as any);
241
-
242
- await run();
243
- const { endSession } = await import("../../../api/session");
244
-
245
- endSession();
246
-
247
- expect(onExpired).not.toHaveBeenCalled();
248
- });
249
-
250
- it.each([
251
- ["204", { status: 204 }],
252
- ["401", { status: 401 }],
253
- ["200 sin endSessionUrl", { status: 200, data: {} }],
254
- ["200 con endSessionUrl vacío", { status: 200, data: { endSessionUrl: "" } }],
255
- ["endSessionUrl que no es una URL", { status: 200, data: { endSessionUrl: "no-es-una-url" } }],
256
- ["endSessionUrl javascript:", { status: 200, data: { endSessionUrl: "javascript:alert(1)" } }],
257
- ["endSessionUrl data:", { status: 200, data: { endSessionUrl: "data:text/html,x" } }],
258
- ["204 con endSessionUrl en el cuerpo", { status: 204, data: { endSessionUrl: URL_OK } }],
259
- ])("%s: limpia lo local y navega a /logout como hoy", async (_name, response) => {
260
- vi.spyOn(global, "logout").mockResolvedValue(response as any);
261
-
262
- await run();
263
-
264
- expect(assign).not.toHaveBeenCalled();
265
- expect(push).toHaveBeenCalledWith("/logout", undefined);
266
- expect(getSession()).toBeNull();
267
- });
268
-
269
- it("si la API rechaza, el cierre local sigue y navega a /logout", async () => {
270
- vi.spyOn(global, "logout").mockRejectedValue(new Error("Network Error"));
271
-
272
- await run();
273
-
274
- expect(assign).not.toHaveBeenCalled();
275
- expect(push).toHaveBeenCalledWith("/logout", undefined);
276
- expect(getSession()).toBeNull();
277
- });
278
-
279
- it("si la API no responde en 5 s, no se queda esperando: cierra lo local y navega a /logout", async () => {
280
- vi.useFakeTimers();
281
- vi.spyOn(global, "logout").mockReturnValue(new Promise(() => undefined) as any);
282
-
283
- const pending = run();
284
-
285
- await vi.advanceTimersByTimeAsync(4999);
286
- expect(push).not.toHaveBeenCalled();
287
-
288
- await vi.advanceTimersByTimeAsync(1);
289
- await pending;
290
-
291
- expect(assign).not.toHaveBeenCalled();
292
- expect(push).toHaveBeenCalledWith("/logout", undefined);
293
- expect(getSession()).toBeNull();
294
- });
295
-
296
- it("sin sesión no llama a la API y navega a /logout", async () => {
297
- resetSessionState();
298
- const logoutApi = vi.spyOn(global, "logout").mockResolvedValue({ status: 204 } as any);
299
-
300
- await run();
301
-
302
- expect(logoutApi).not.toHaveBeenCalled();
303
- expect(assign).not.toHaveBeenCalled();
304
- expect(push).toHaveBeenCalledWith("/logout", undefined);
305
- });
306
-
307
- it("una URL http también se acepta (entornos locales)", async () => {
308
- vi.spyOn(global, "logout").mockResolvedValue({
309
- status: 200,
310
- data: { endSessionUrl: "http://localhost:3001/sso/logout" },
311
- } as any);
312
-
313
- await run();
314
-
315
- expect(assign).toHaveBeenCalledExactlyOnceWith("http://localhost:3001/sso/logout");
316
- });
317
- });
318
-
319
- describe("logoutAndEndCentralSession sin Griddo ID (Comillas o contraseña): como en producción", () => {
320
- let assign: Mock<(url: string) => void>;
321
- let push: ReturnType<typeof vi.spyOn>;
322
-
323
- const run = () =>
324
- appActions.logoutAndEndCentralSession()(vi.fn(), (() => ({
325
- app: { globalSettings: { GriddoIdEnabled: false } },
326
- })) as never);
327
-
328
- beforeEach(() => {
329
- assign = vi.fn();
330
- vi.stubGlobal("location", { ...window.location, assign });
331
- push = vi.spyOn(history, "push").mockImplementation(() => undefined);
332
- setSession("jwt", "r1");
333
- });
334
-
335
- afterEach(() => vi.unstubAllGlobals());
336
-
337
- it("navega a /logout sin esperar a la API (aunque no responda) y no llama a la API desde la acción", async () => {
338
- const logoutApi = vi.spyOn(global, "logout").mockReturnValue(new Promise(() => undefined) as any);
339
-
340
- await run();
341
-
342
- expect(push).toHaveBeenCalledWith("/logout", undefined);
343
- expect(logoutApi).not.toHaveBeenCalled();
344
- expect(assign).not.toHaveBeenCalled();
345
- });
346
-
347
- it("no usa endSessionUrl aunque la API lo devolviera", async () => {
348
- vi.spyOn(global, "logout").mockResolvedValue({
349
- status: 200,
350
- data: { endSessionUrl: "https://api.uni.es/sso/logout" },
351
- } as any);
352
-
353
- await run();
354
-
355
- expect(assign).not.toHaveBeenCalled();
356
- expect(push).toHaveBeenCalledWith("/logout", undefined);
357
- });
358
-
359
- it("marca la sesión como cerrada (un 401 en vuelo no lanza otro cierre)", async () => {
360
- await run();
361
- const { endSession } = await import("../../../api/session");
362
-
363
- endSession();
364
-
365
- expect(onExpired).not.toHaveBeenCalled();
366
- });
367
- });
368
-
369
- describe("estado de sesión en el reducer", () => {
370
- it("SET_TOKEN con par y versión se funde en el estado", () => {
371
- const state = appReducer(undefined, {
372
- type: SET_TOKEN,
373
- payload: { token: "t", refreshToken: "r", sessionUpdatedAt: 4 },
374
- });
375
- expect(state).toMatchObject({ token: "t", refreshToken: "r", sessionUpdatedAt: 4 });
376
- });
377
-
378
- it("el estado inicial no tiene refresh ni versión", () => {
379
- expect(appReducer(undefined, { type: "x" })).toMatchObject({ token: "", refreshToken: "", sessionUpdatedAt: 0 });
380
- });
381
-
382
- it("applySession guarda el par y lo despacha con su versión", () => {
383
- const dispatch = vi.fn();
384
- appActions.applySession("a", "b")(dispatch);
385
- expect(dispatch).toHaveBeenCalledWith({
386
- type: SET_TOKEN,
387
- payload: { token: "a", refreshToken: "b", sessionUpdatedAt: getSession()?.updatedAt },
388
- });
389
- });
390
-
391
- it("applySession sin refresh despacha cadena vacía", () => {
392
- const dispatch = vi.fn();
393
- appActions.applySession("a")(dispatch);
394
- expect(dispatch.mock.calls[0][0].payload.refreshToken).toBe("");
395
- expect(getSession()?.refreshToken).toBeNull();
396
- });
397
- });
@@ -1,56 +0,0 @@
1
- import { buildGriddoIdStartUrl, MAX_LOGIN_HINT_LENGTH } from "@ax/helpers";
2
-
3
- const API = "https://api.uni.es";
4
- const START = `${API}/sso/start`;
5
-
6
- const emailOfLength = (length: number) => `${"a".repeat(length - "@uni.es".length)}@uni.es`;
7
-
8
- describe("buildGriddoIdStartUrl", () => {
9
- it.each([
10
- ["ana@uni.es", `${START}?login_hint=ana%40uni.es`],
11
- [" ana@uni.es ", `${START}?login_hint=ana%40uni.es`],
12
- ["\t\nana@uni.es\r\n", `${START}?login_hint=ana%40uni.es`],
13
- ["Ana@UNI.es", `${START}?login_hint=Ana%40UNI.es`],
14
- ["ana @uni.es", `${START}?login_hint=ana%20%40uni.es`],
15
- ["ana+x@uni.es", `${START}?login_hint=ana%2Bx%40uni.es`],
16
- ["a&b=c@uni.es", `${START}?login_hint=a%26b%3Dc%40uni.es`],
17
- ["ñandú@uni.es", `${START}?login_hint=%C3%B1and%C3%BA%40uni.es`],
18
- ])("con %j navega con el hint codificado", (typed, expected) => {
19
- expect(buildGriddoIdStartUrl(API, typed)).toBe(expected);
20
- });
21
-
22
- it("el tope es 254 caracteres", () => {
23
- expect(MAX_LOGIN_HINT_LENGTH).toBe(254);
24
- });
25
-
26
- it("254 caracteres con @ llevan el hint", () => {
27
- const email = emailOfLength(254);
28
-
29
- expect(buildGriddoIdStartUrl(API, email)).toBe(`${START}?login_hint=${encodeURIComponent(email)}`);
30
- });
31
-
32
- it("254 caracteres con espacios en los extremos llevan el hint recortado", () => {
33
- const email = emailOfLength(254);
34
-
35
- expect(buildGriddoIdStartUrl(API, ` ${email} `)).toBe(`${START}?login_hint=${encodeURIComponent(email)}`);
36
- });
37
-
38
- it.each([
39
- ["vacío", ""],
40
- ["solo espacios", " "],
41
- ["sin arroba", "ana"],
42
- ["255 caracteres con @", emailOfLength(255)],
43
- ["un texto de 20 KB con @", `${"a".repeat(20 * 1024)}@uni.es`],
44
- ["un sustituto suelto", "\uD800@uni.es"],
45
- ])("con %s navega a /sso/start sin query", (_case, typed) => {
46
- expect(buildGriddoIdStartUrl(API, typed)).toBe(START);
47
- });
48
-
49
- it("no cambia mayúsculas ni espacios interiores (la normalización es de la app de login)", () => {
50
- expect(buildGriddoIdStartUrl(API, "A B@UNI.es")).toBe(`${START}?login_hint=A%20%20B%40UNI.es`);
51
- });
52
-
53
- it("con una URL de API sin definir no inventa un host", () => {
54
- expect(buildGriddoIdStartUrl("", "ana@uni.es")).toBe("/sso/start?login_hint=ana%40uni.es");
55
- });
56
- });
@@ -1,52 +0,0 @@
1
- import { getLoginLocale } from "@ax/locales";
2
-
3
- describe("getLoginLocale", () => {
4
- it.each([
5
- ["es-ES", "Entrar con Griddo"],
6
- ["es", "Entrar con Griddo"],
7
- ["es-MX", "Entrar con Griddo"],
8
- ["en-US", "Sign in with Griddo"],
9
- ["en", "Sign in with Griddo"],
10
- ["en-GB", "Sign in with Griddo"],
11
- ["EN-us", "Sign in with Griddo"],
12
- ])("idioma %s", (language, button) => {
13
- expect(getLoginLocale(language).griddoIdButton).toBe(button);
14
- });
15
-
16
- it.each(["fr-FR", "de", "", "xx-YY"])("idioma no soportado %j: español", (language) => {
17
- expect(getLoginLocale(language).griddoIdButton).toBe("Entrar con Griddo");
18
- });
19
-
20
- it("sin argumento usa el idioma del navegador", () => {
21
- vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US");
22
-
23
- expect(getLoginLocale().griddoIdButton).toBe("Sign in with Griddo");
24
- });
25
-
26
- it("sin argumento y sin idioma del navegador: español", () => {
27
- vi.spyOn(window.navigator, "language", "get").mockReturnValue(undefined as unknown as string);
28
-
29
- expect(getLoginLocale().griddoIdButton).toBe("Entrar con Griddo");
30
- });
31
-
32
- it("textos fijos de S6 en español e inglés", () => {
33
- expect(getLoginLocale("es").deniedTitle).toBe("No tienes acceso a esta instancia");
34
- expect(getLoginLocale("es").switchAccount).toBe("Entrar con otra cuenta");
35
- expect(getLoginLocale("en").deniedTitle).toBe("You don't have access to this instance");
36
- expect(getLoginLocale("en").switchAccount).toBe("Sign in with another account");
37
- });
38
-
39
- it("separador entre el formulario y el SSO de Griddo en español e inglés", () => {
40
- expect(getLoginLocale("es").or).toBe("o");
41
- expect(getLoginLocale("en").or).toBe("or");
42
- });
43
-
44
- it("ya no hay texto de «Acceso de administración»", () => {
45
- expect(getLoginLocale("es")).not.toHaveProperty("adminAccess");
46
- expect(getLoginLocale("en")).not.toHaveProperty("adminAccess");
47
- });
48
-
49
- it("ambos idiomas tienen las mismas claves de login", () => {
50
- expect(Object.keys(getLoginLocale("en")).sort()).toEqual(Object.keys(getLoginLocale("es")).sort());
51
- });
52
- });
@@ -1,54 +0,0 @@
1
- import { Provider } from "react-redux";
2
- import { Router } from "react-router-dom";
3
-
4
- import { cleanup, fireEvent, render, screen } from "@testing-library/react";
5
- import configureStore from "redux-mock-store";
6
- import { ThemeProvider } from "styled-components";
7
- import "@testing-library/jest-dom";
8
-
9
- import { appInitialState } from "@ax/containers/App/reducer";
10
- import { parseTheme } from "@ax/helpers";
11
- import NavMenu from "@ax/modules/App/Routing/NavMenu";
12
- import history from "@ax/routes/history";
13
- import globalTheme from "@ax/themes/theme.json";
14
-
15
- vi.mock("@ax/containers/App", async (importOriginal) => {
16
- const original = await importOriginal<typeof import("@ax/containers/App")>();
17
-
18
- return {
19
- ...original,
20
- appActions: {
21
- ...original.appActions,
22
- logoutAndEndCentralSession: () => ({ type: "test/logoutAndEndCentralSession" }),
23
- logoutAndNavigate: () => ({ type: "test/logoutAndNavigate" }),
24
- setHistoryPush: () => ({ type: "test/setHistoryPush" }),
25
- },
26
- };
27
- });
28
-
29
- afterEach(cleanup);
30
-
31
- describe("NavMenu: botón «Logout»", () => {
32
- it("usa el cierre completo (con la sesión central de auth.griddo.io), no el solo local", () => {
33
- const store = configureStore([])({
34
- app: { ...appInitialState, lang: { locale: "es-ES", id: 1 }, globalSettings: appInitialState.globalSettings },
35
- structuredData: { categories: { global: [], site: [] }, structuredData: { global: [], site: [] } },
36
- sites: { currentSiteInfo: null, currentSiteLanguages: [] },
37
- users: { currentUser: null },
38
- });
39
-
40
- render(
41
- <Provider store={store}>
42
- <Router history={history}>
43
- <ThemeProvider theme={parseTheme(globalTheme)}>
44
- <NavMenu />
45
- </ThemeProvider>
46
- </Router>
47
- </Provider>,
48
- );
49
-
50
- fireEvent.click(screen.getAllByText("Logout")[0]);
51
-
52
- expect(store.getActions()).toEqual([{ type: "test/logoutAndEndCentralSession" }]);
53
- });
54
- });