@griddo/ax 12.16.0 → 12.17.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 (88) hide show
  1. package/README.md +1 -0
  2. package/config/griddo-config/index.js +3 -2
  3. package/package.json +7 -4
  4. package/public/img/logos/logoGriddoDxp.svg +22 -0
  5. package/public/img/logos/logoGriddoG.svg +10 -0
  6. package/src/GlobalStore.tsx +32 -25
  7. package/src/__tests__/GlobalStore.session.test.tsx +98 -0
  8. package/src/__tests__/api/global.test.ts +64 -0
  9. package/src/__tests__/api/session.test.ts +311 -0
  10. package/src/__tests__/api/sessionRenewal.test.ts +705 -0
  11. package/src/__tests__/api/utils.test.ts +373 -0
  12. package/src/__tests__/components/Fields/FileField/FileField.test.tsx +33 -6
  13. package/src/__tests__/components/FieldsBehavior/FieldsBehavior.test.tsx +5 -3
  14. package/src/__tests__/components/Login/BrandPalette.test.tsx +145 -0
  15. package/src/__tests__/components/Login/Login.test.tsx +2 -33
  16. package/src/__tests__/components/Login/LoginCollapsible.test.tsx +271 -0
  17. package/src/__tests__/components/Login/LoginDropdownCard.test.tsx +311 -0
  18. package/src/__tests__/components/Login/LoginFooter.test.tsx +128 -0
  19. package/src/__tests__/components/Login/LoginGriddoId.test.tsx +213 -0
  20. package/src/__tests__/components/Login/LoginInlineError.test.tsx +116 -0
  21. package/src/__tests__/components/Login/RecoveryModal/RecoveryModal.test.tsx +3 -4
  22. package/src/__tests__/components/SsoDenied/SsoDenied.test.tsx +86 -0
  23. package/src/__tests__/config/webpackAliases.test.ts +18 -0
  24. package/src/__tests__/containers/App/reducer.griddoId.test.ts +18 -0
  25. package/src/__tests__/containers/App/session.test.ts +397 -0
  26. package/src/__tests__/containers/App/signInOut.test.ts +159 -0
  27. package/src/__tests__/helpers/griddoId.test.ts +56 -0
  28. package/src/__tests__/hooks/useShouldBeSaved.test.tsx +78 -0
  29. package/src/__tests__/locales/loginLocale.test.ts +37 -0
  30. package/src/__tests__/modules/App/Routing/NavMenu.test.tsx +54 -0
  31. package/src/__tests__/modules/App/Routing/PrivateRoute.test.tsx +64 -0
  32. package/src/__tests__/modules/App/Routing/Routing.startup.test.tsx +79 -0
  33. package/src/__tests__/modules/Login/Login.test.tsx +169 -0
  34. package/src/__tests__/modules/Login/loginError.uc.test.tsx +294 -0
  35. package/src/__tests__/modules/Login/signInOut.test.tsx +125 -0
  36. package/src/__tests__/modules/Redirects/RedirectPanel/RedirectPanel.test.tsx +9 -0
  37. package/src/__tests__/modules/Redirects/Redirects/Redirects.create.test.tsx +19 -0
  38. package/src/__tests__/modules/Redirects/Redirects/Redirects.edit.test.tsx +19 -0
  39. package/src/__tests__/modules/Redirects/Redirects/Redirects.filter.test.tsx +19 -0
  40. package/src/__tests__/modules/SsoDenied/SsoDenied.test.tsx +30 -0
  41. package/src/__tests__/routes/publicRoutes.test.ts +36 -0
  42. package/src/api/global.tsx +24 -1
  43. package/src/api/session.tsx +197 -0
  44. package/src/api/sessionRenewal.tsx +114 -0
  45. package/src/api/utils.tsx +22 -12
  46. package/src/{helpers/categoryColumns.tsx → components/CategoryCell/buildCategoryColumns.tsx} +3 -2
  47. package/src/components/Circle/index.tsx +1 -1
  48. package/src/components/Circle/style.tsx +4 -2
  49. package/src/components/ErrorPage/index.tsx +1 -1
  50. package/src/components/ErrorPage/style.tsx +11 -9
  51. package/src/components/ErrorToast/index.tsx +2 -0
  52. package/src/{helpers/fields.tsx → components/FieldsBehavior/getFieldByPath.tsx} +1 -1
  53. package/src/components/FieldsBehavior/index.tsx +3 -1
  54. package/src/components/Login/LoginFooter/index.tsx +16 -0
  55. package/src/components/Login/LoginFooter/style.tsx +17 -0
  56. package/src/components/Login/LoginForm/index.tsx +147 -79
  57. package/src/components/Login/LoginForm/style.tsx +147 -24
  58. package/src/components/Login/LoginGriddoId/index.tsx +56 -0
  59. package/src/components/Login/LoginGriddoId/style.tsx +35 -0
  60. package/src/components/Login/LoginSSO/index.tsx +4 -7
  61. package/src/components/Login/LoginSSO/style.tsx +10 -26
  62. package/src/components/Login/LoginSlider/style.tsx +5 -5
  63. package/src/components/Login/index.tsx +35 -6
  64. package/src/components/Login/style.tsx +40 -24
  65. package/src/components/Notification/index.tsx +3 -1
  66. package/src/components/SsoDenied/index.tsx +46 -0
  67. package/src/components/SsoDenied/style.tsx +37 -0
  68. package/src/components/index.tsx +11 -7
  69. package/src/containers/App/actions.tsx +114 -6
  70. package/src/containers/App/interfaces.tsx +2 -2
  71. package/src/containers/App/reducer.tsx +9 -0
  72. package/src/containers/Users/actions.tsx +28 -24
  73. package/src/helpers/griddoId.ts +28 -0
  74. package/src/helpers/index.tsx +4 -5
  75. package/src/hooks/forms.tsx +8 -5
  76. package/src/locales/en-US.ts +13 -0
  77. package/src/locales/es-ES.ts +13 -0
  78. package/src/locales/index.ts +9 -1
  79. package/src/modules/App/Routing/NavMenu/index.tsx +4 -4
  80. package/src/modules/Content/PageItem/index.tsx +6 -8
  81. package/src/modules/Login/index.tsx +33 -14
  82. package/src/modules/SsoDenied/index.tsx +9 -0
  83. package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/index.tsx +6 -8
  84. package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/index.tsx +9 -11
  85. package/src/modules/Users/UserEdit/index.tsx +9 -2
  86. package/src/routes/publicRoutes.tsx +3 -0
  87. package/src/themes/brandPalette.ts +16 -0
  88. package/public/img/logos/logoSQY.svg +0 -3
@@ -0,0 +1,128 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { ThemeProvider } from "styled-components";
3
+
4
+ import { readdirSync, readFileSync, statSync } from "node:fs";
5
+ import { join, resolve } from "node:path";
6
+ import "@testing-library/jest-dom";
7
+
8
+ import Login, { type ILoginProps } from "@ax/components/Login";
9
+ import { parseTheme } from "@ax/helpers";
10
+ import globalTheme from "@ax/themes/theme.json";
11
+
12
+ afterEach(cleanup);
13
+
14
+ const SLOGAN = "Edit. See. Publish";
15
+
16
+ const settings = {
17
+ cloudinaryName: "cloudinary",
18
+ globalLogoBig: "",
19
+ globalLogoMini: "",
20
+ siteLogoBig: "",
21
+ siteLogoMini: "",
22
+ welcomeText1: "Welcome back to",
23
+ welcomeText2: "Griddo",
24
+ autoSummary: false,
25
+ autoTranslation: false,
26
+ SSOActivated: false,
27
+ GriddoIdEnabled: false,
28
+ SSOWelcomeText: "",
29
+ useForms: false,
30
+ };
31
+
32
+ const renderLogin = (overrides: Partial<ILoginProps["settings"]> = {}, isLoginSuccess = false) =>
33
+ render(
34
+ <ThemeProvider theme={parseTheme(globalTheme)}>
35
+ <Login
36
+ handleSubmit={vi.fn()}
37
+ email=""
38
+ handleEmail={vi.fn()}
39
+ password=""
40
+ handlePassword={vi.fn()}
41
+ isLoggingIn={false}
42
+ settings={{ ...settings, ...overrides }}
43
+ rememberMe={false}
44
+ handleRememberMe={vi.fn()}
45
+ handleGriddoId={vi.fn()}
46
+ isLoginSuccess={isLoginSuccess}
47
+ handleLoginSuccess={vi.fn()}
48
+ handleSSO={vi.fn()}
49
+ errorSSO=""
50
+ />
51
+ </ThemeProvider>,
52
+ );
53
+
54
+ const setLanguage = (language: string) => vi.spyOn(window.navigator, "language", "get").mockReturnValue(language);
55
+
56
+ const VARIANTS = [
57
+ ["Griddo ID", { GriddoIdEnabled: true }],
58
+ ["normal", {}],
59
+ ["SSO Comillas", { SSOActivated: true }],
60
+ ] as const;
61
+
62
+ describe("[UC-AX-sign-in-out] LoginFooter: eslogan de plataforma", () => {
63
+ beforeEach(() => setLanguage("en-US"));
64
+
65
+ it.each(VARIANTS)("AC17 · variante %s: eslogan y sin rastro de Secuoyas", (_n, overrides) => {
66
+ const { container } = renderLogin(overrides);
67
+ expect(screen.getByTestId("login-footer")).toHaveTextContent(SLOGAN);
68
+ expect(container).not.toHaveTextContent(/made with care/i);
69
+ expect(screen.queryByAltText(/secuoyas/i)).toBeNull();
70
+ expect(container.querySelector('img[src*="logoSQY"]')).toBeNull();
71
+ });
72
+
73
+ it.each(VARIANTS)("AC17 · variante %s: un único pie", (_n, overrides) => {
74
+ renderLogin(overrides);
75
+ expect(screen.getAllByTestId("login-footer")).toHaveLength(1);
76
+ });
77
+
78
+ it("AC17 · es-ES: el pie sale con el texto del locale", () => {
79
+ setLanguage("es-ES");
80
+ renderLogin();
81
+ expect(screen.getByTestId("login-footer")).toHaveTextContent(SLOGAN);
82
+ });
83
+
84
+ it("AC17 · idioma sin locale: cae al texto por defecto sin lanzar", () => {
85
+ setLanguage("fr-FR");
86
+ expect(() => renderLogin()).not.toThrow();
87
+ expect(screen.getByTestId("login-footer")).toHaveTextContent(SLOGAN);
88
+ });
89
+
90
+ it.each(VARIANTS)("AC17 · variante %s: el pie se desvanece con el formulario en el éxito", (_n, overrides) => {
91
+ renderLogin(overrides, true);
92
+ const fading = document.querySelector(".animate:not([data-testid=login-left])");
93
+ expect(fading).toContainElement(screen.getByTestId("login-footer"));
94
+ });
95
+
96
+ it("AC17 · el pie no es interactivo", () => {
97
+ renderLogin();
98
+ const footer = screen.getByTestId("login-footer");
99
+ expect(footer.closest("a, button")).toBeNull();
100
+ expect(footer.querySelector("a, button, img")).toBeNull();
101
+ });
102
+ });
103
+
104
+ const listSources = (dir: string): string[] =>
105
+ readdirSync(dir).flatMap((name) => {
106
+ const path = join(dir, name);
107
+ return statSync(path).isDirectory() ? listSources(path) : [path];
108
+ });
109
+
110
+ describe("[UC-AX-sign-in-out] LoginFooter: sin copias de Secuoyas", () => {
111
+ const loginDir = resolve(__dirname, "../../../components/Login");
112
+ const files = listSources(loginDir).filter((f) => /\.(tsx?|svg)$/.test(f));
113
+
114
+ it("AC17 · solo LoginFooter define el pie: ningún otro fichero del login menciona Secuoyas/logoSQY", () => {
115
+ const offenders = files.filter(
116
+ (f) => !f.includes("LoginFooter") && /Secuoyas|logoSQY|Made with care/.test(readFileSync(f, "utf8")),
117
+ );
118
+ expect(offenders).toEqual([]);
119
+ });
120
+
121
+ it("AC17 · ningún componente ni test referencia logoSQY.svg", () => {
122
+ const srcDir = resolve(__dirname, "../../..");
123
+ const refs = listSources(srcDir).filter(
124
+ (f) => !f.endsWith("LoginFooter.test.tsx") && /logoSQY\.svg|Secuoyas logo/.test(readFileSync(f, "utf8")),
125
+ );
126
+ expect(refs).toEqual([]);
127
+ });
128
+ });
@@ -0,0 +1,213 @@
1
+ import { 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 baseSettings = {
12
+ cloudinaryName: "cloudinary",
13
+ globalLogoBig: "",
14
+ globalLogoMini: "",
15
+ siteLogoBig: "",
16
+ siteLogoMini: "",
17
+ welcomeText1: "Welcome back to",
18
+ welcomeText2: "Griddo",
19
+ autoSummary: false,
20
+ autoTranslation: false,
21
+ SSOActivated: false,
22
+ GriddoIdEnabled: false,
23
+ SSOWelcomeText: "",
24
+ useForms: false,
25
+ };
26
+
27
+ const renderLoginContainer = (settings: Partial<typeof baseSettings>, props: Partial<ILoginProps> = {}) => {
28
+ const handlers = {
29
+ handleSubmit: vi.fn((e: React.FormEvent) => e.preventDefault()),
30
+ handleSSO: vi.fn(),
31
+ handleGriddoId: vi.fn(),
32
+ };
33
+
34
+ const { container } = render(
35
+ <ThemeProvider theme={parseTheme(globalTheme)}>
36
+ <Login
37
+ email=""
38
+ handleEmail={vi.fn()}
39
+ password=""
40
+ handlePassword={vi.fn()}
41
+ isLoggingIn={false}
42
+ rememberMe={false}
43
+ handleRememberMe={vi.fn()}
44
+ isLoginSuccess={false}
45
+ handleLoginSuccess={vi.fn()}
46
+ errorSSO={null}
47
+ {...handlers}
48
+ {...props}
49
+ settings={{ ...baseSettings, ...settings } as ILoginProps["settings"]}
50
+ />
51
+ </ThemeProvider>,
52
+ );
53
+
54
+ return { container, ...handlers };
55
+ };
56
+
57
+ const renderLogin = (settings: Partial<typeof baseSettings>, props: Partial<ILoginProps> = {}) => {
58
+ const { container: _container, ...handlers } = renderLoginContainer(settings, props);
59
+
60
+ return handlers;
61
+ };
62
+
63
+ const setLanguage = (language: string) => vi.spyOn(window.navigator, "language", "get").mockReturnValue(language);
64
+
65
+ describe("Login con auth.griddo.io", () => {
66
+ beforeEach(() => setLanguage("en-US"));
67
+
68
+ it("con el flag activo «Sign in with Griddo» va sobre el desplegable del formulario de usuario y contraseña", () => {
69
+ renderLogin({ GriddoIdEnabled: true });
70
+
71
+ const email = screen.getByPlaceholderText("Type your email");
72
+ const toggle = screen.getByRole("button", { name: "Login with email and password" });
73
+ const griddo = screen.getByRole("button", { name: "Sign in with Griddo" });
74
+
75
+ expect(screen.getByText("Lost your password?")).toBeInTheDocument();
76
+ expect(griddo.compareDocumentPosition(toggle) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
77
+ expect(toggle.compareDocumentPosition(email) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
78
+ expect(screen.queryByText("Microsoft ID")).toBeNull();
79
+ });
80
+
81
+ it("la cabecera es «Welcome / Login to start publishing» y el botón lleva el logo de Griddo", () => {
82
+ renderLogin({ GriddoIdEnabled: true });
83
+
84
+ expect(screen.getByRole("heading", { name: "Welcome" })).toBeInTheDocument();
85
+ expect(screen.getByText("Login to start publishing")).toBeInTheDocument();
86
+ expect(screen.queryByText(/introduce your email and password/)).toBeNull();
87
+ expect(
88
+ screen
89
+ .getByRole("button", { name: "Sign in with Griddo" })
90
+ .querySelector('img[src="/img/logos/logoGriddoG.svg"]'),
91
+ ).not.toBeNull();
92
+ });
93
+
94
+ it("entre el botón y el formulario hay un desplegable, no un separador", () => {
95
+ setLanguage("en-US");
96
+ renderLogin({ GriddoIdEnabled: true });
97
+
98
+ const toggle = screen.getByRole("button", { name: "Login with email and password" });
99
+
100
+ expect(screen.queryByRole("separator")).toBeNull();
101
+ expect(
102
+ screen.getByRole("button", { name: "Sign in with Griddo" }).compareDocumentPosition(toggle) &
103
+ Node.DOCUMENT_POSITION_FOLLOWING,
104
+ ).toBeTruthy();
105
+ expect(
106
+ toggle.compareDocumentPosition(screen.getByPlaceholderText("Type your email")) & Node.DOCUMENT_POSITION_FOLLOWING,
107
+ ).toBeTruthy();
108
+ });
109
+
110
+ it("con el flag activo se puede iniciar sesión con usuario y contraseña", () => {
111
+ const { handleSubmit } = renderLogin({ GriddoIdEnabled: true });
112
+
113
+ fireEvent.click(screen.getByRole("button", { name: "Login with email and password" }));
114
+ fireEvent.click(screen.getByText("Login"));
115
+
116
+ expect(handleSubmit).toHaveBeenCalledTimes(1);
117
+ });
118
+
119
+ it("ya no existe el enlace «Acceso de administración»", () => {
120
+ renderLogin({ GriddoIdEnabled: true, SSOActivated: true });
121
+
122
+ expect(screen.queryByText("Acceso de administración")).toBeNull();
123
+ expect(screen.queryByText("Administrator access")).toBeNull();
124
+ });
125
+
126
+ it("con el flag apagado el login es el de siempre y no hay botón nuevo ni separador", () => {
127
+ renderLogin({ GriddoIdEnabled: false });
128
+
129
+ expect(screen.queryByText("Sign in with Griddo")).toBeNull();
130
+ expect(screen.queryByText("o")).toBeNull();
131
+ expect(screen.getByPlaceholderText("Type your email")).toBeInTheDocument();
132
+ expect(screen.getByText("Login")).toBeInTheDocument();
133
+ });
134
+
135
+ it("con Comillas y Griddo ID la pantalla es la de Comillas: sin formulario, sin «Entrar con Griddo» y sin separador", () => {
136
+ const { handleGriddoId } = renderLogin({ GriddoIdEnabled: true, SSOActivated: true });
137
+
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();
141
+ expect(screen.queryByText("o")).toBeNull();
142
+ expect(screen.queryByPlaceholderText("Type your email")).toBeNull();
143
+ expect(screen.queryByText("Login")).toBeNull();
144
+ expect(screen.getAllByRole("button")).toHaveLength(1);
145
+ expect(handleGriddoId).not.toHaveBeenCalled();
146
+ });
147
+
148
+ it("la pantalla de Comillas es idéntica con y sin GriddoIdEnabled", () => {
149
+ const { container: withFlag } = renderLoginContainer({ SSOActivated: true, GriddoIdEnabled: true });
150
+ const { container: withoutFlag } = renderLoginContainer({ SSOActivated: true, GriddoIdEnabled: false });
151
+
152
+ expect(withFlag.innerHTML).toBe(withoutFlag.innerHTML);
153
+ });
154
+
155
+ it("con solo SSOActivated (Comillas) la pantalla es la de hoy: sin formulario, sin botón de Griddo ni separador", () => {
156
+ renderLogin({ SSOActivated: true });
157
+
158
+ expect(screen.getByRole("button", { name: /Microsoft ID/ })).toBeInTheDocument();
159
+ expect(screen.queryByText("Sign in with Griddo")).toBeNull();
160
+ expect(screen.queryByText("o")).toBeNull();
161
+ expect(screen.queryByPlaceholderText("Type your email")).toBeNull();
162
+ });
163
+
164
+ it("el botón navega una sola vez aunque se pulse dos veces seguidas", () => {
165
+ const { handleGriddoId } = renderLogin({ GriddoIdEnabled: true });
166
+ const button = screen.getByRole("button", { name: "Sign in with Griddo" });
167
+
168
+ fireEvent.click(button);
169
+ fireEvent.click(button);
170
+
171
+ expect(handleGriddoId).toHaveBeenCalledTimes(1);
172
+ });
173
+
174
+ it("el botón de Microsoft sigue llamando a handleSSO", () => {
175
+ const { handleSSO } = renderLogin({ SSOActivated: true });
176
+
177
+ fireEvent.click(screen.getByRole("button", { name: /Microsoft ID/ }));
178
+
179
+ expect(handleSSO).toHaveBeenCalledTimes(1);
180
+ });
181
+
182
+ it.each([
183
+ ["solo Comillas", { SSOActivated: true }],
184
+ ["Comillas y Griddo ID", { SSOActivated: true, GriddoIdEnabled: true }],
185
+ ])("%s: muestra el error del SSO de Comillas una sola vez", (_name, flags) => {
186
+ renderLogin(flags, { errorSSO: "Error de Comillas" });
187
+
188
+ expect(screen.getAllByText("Error de Comillas")).toHaveLength(1);
189
+ });
190
+
191
+ it("con Comillas la pantalla es la de siempre aunque se pase handleGriddoId: sin formulario, sin botón ni separador", () => {
192
+ renderLogin({ SSOActivated: true, GriddoIdEnabled: false });
193
+
194
+ expect(screen.queryByPlaceholderText("Type your email")).toBeNull();
195
+ expect(screen.queryByText("Login")).toBeNull();
196
+ expect(screen.queryByRole("button", { name: "Sign in with Griddo" })).toBeNull();
197
+ expect(screen.queryByText("o")).toBeNull();
198
+ expect(screen.getByText(/Welcome/)).toBeInTheDocument();
199
+ expect(screen.getAllByRole("button")).toHaveLength(1);
200
+ });
201
+
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"],
206
+ ])("idioma %s", (language, button, toggle) => {
207
+ setLanguage(language);
208
+ renderLogin({ GriddoIdEnabled: true });
209
+
210
+ expect(screen.getByRole("button", { name: button })).toBeInTheDocument();
211
+ expect(screen.getByRole("button", { name: toggle })).toBeInTheDocument();
212
+ });
213
+ });
@@ -0,0 +1,116 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import userEvent from "@testing-library/user-event";
3
+ import { ThemeProvider } from "styled-components";
4
+ import "@testing-library/jest-dom";
5
+
6
+ import Login, { type ILoginProps } from "@ax/components/Login";
7
+ import { parseTheme } from "@ax/helpers";
8
+ import { BRAND_PALETTE } from "@ax/themes/brandPalette";
9
+ import globalTheme from "@ax/themes/theme.json";
10
+
11
+ afterEach(cleanup);
12
+
13
+ const baseSettings = {
14
+ cloudinaryName: "cloudinary",
15
+ globalLogoBig: "",
16
+ globalLogoMini: "",
17
+ siteLogoBig: "",
18
+ siteLogoMini: "",
19
+ welcomeText1: "Welcome back to",
20
+ welcomeText2: "Griddo",
21
+ autoSummary: false,
22
+ autoTranslation: false,
23
+ SSOActivated: false,
24
+ GriddoIdEnabled: true,
25
+ SSOWelcomeText: "",
26
+ useForms: false,
27
+ };
28
+
29
+ const renderLogin = (settings: Partial<typeof baseSettings> = {}) =>
30
+ render(
31
+ <ThemeProvider theme={parseTheme(globalTheme)}>
32
+ <Login
33
+ handleSubmit={vi.fn((e: React.FormEvent) => e.preventDefault())}
34
+ email=""
35
+ handleEmail={vi.fn()}
36
+ password=""
37
+ handlePassword={vi.fn()}
38
+ isLoggingIn={false}
39
+ rememberMe={false}
40
+ handleRememberMe={vi.fn()}
41
+ isLoginSuccess={false}
42
+ handleLoginSuccess={vi.fn()}
43
+ handleSSO={vi.fn()}
44
+ handleGriddoId={vi.fn()}
45
+ errorSSO={null}
46
+ settings={{ ...baseSettings, ...settings } as ILoginProps["settings"]}
47
+ />
48
+ </ThemeProvider>,
49
+ );
50
+
51
+ const toggle = () => screen.getByRole("button", { name: "Login with email and password" });
52
+ const card = () => screen.getByTestId("login-dropdown");
53
+ const slot = () => document.querySelector("#error") as HTMLElement;
54
+
55
+ describe("[UC-AX-sign-in-out] #error único dentro de la tarjeta (AC15)", () => {
56
+ beforeEach(() => vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US"));
57
+
58
+ it("AC15 · el #error vive dentro de la tarjeta, entre la cabecera y el formulario, y es único", () => {
59
+ renderLogin();
60
+
61
+ expect(document.querySelectorAll("#error")).toHaveLength(1);
62
+ expect(card()).toContainElement(slot());
63
+ expect(toggle().compareDocumentPosition(slot()) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
64
+ expect(
65
+ slot().compareDocumentPosition(screen.getByPlaceholderText("Type your email")) & Node.DOCUMENT_POSITION_FOLLOWING,
66
+ ).toBeTruthy();
67
+ });
68
+
69
+ it("AC15 · plegado el #error se pinta encima del botón (hueco fijo) y abierto va tras la cabecera", async () => {
70
+ renderLogin();
71
+
72
+ expect(slot()).toHaveStyle({ order: "-1" });
73
+
74
+ await userEvent.click(toggle());
75
+
76
+ expect(slot()).toHaveStyle({ order: "0" });
77
+ expect(document.querySelectorAll("#error")).toHaveLength(1);
78
+ });
79
+
80
+ it("AC15 · la caja del botón (fondo, borde, radio 8) vive en el botón plegado y la tarjeta abierta la toma el contenedor", async () => {
81
+ renderLogin();
82
+
83
+ expect(toggle()).toHaveStyle({
84
+ backgroundColor: BRAND_PALETTE.navyControl,
85
+ border: "1px solid rgba(219,221,233,.3)",
86
+ borderRadius: "8px",
87
+ });
88
+ expect(card()).toHaveStyle({ padding: "0px" });
89
+
90
+ await userEvent.click(toggle());
91
+
92
+ expect(card()).toHaveStyle({
93
+ backgroundColor: BRAND_PALETTE.navyControl,
94
+ borderRadius: "12px",
95
+ padding: "11px 25px 28px 23px",
96
+ });
97
+ });
98
+
99
+ it("AC15 · el #error es una región role=alert (se anuncia) también con el panel plegado", () => {
100
+ renderLogin();
101
+
102
+ expect(slot()).toHaveAttribute("role", "alert");
103
+ });
104
+
105
+ it("AC15 · login normal sin Griddo ID: sigue habiendo un único #error", () => {
106
+ renderLogin({ GriddoIdEnabled: false });
107
+
108
+ expect(document.querySelectorAll("#error")).toHaveLength(1);
109
+ });
110
+
111
+ it("AC15 · SSO de Comillas: sigue habiendo un único #error", () => {
112
+ renderLogin({ SSOActivated: true });
113
+
114
+ expect(document.querySelectorAll("#error")).toHaveLength(1);
115
+ });
116
+ });
@@ -1,12 +1,11 @@
1
- import type { MockedFunction } from "vitest";
2
- import * as React from "react";
1
+ import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
3
2
  import Axios from "axios";
4
3
  import { ThemeProvider } from "styled-components";
5
- import { render, cleanup, screen, fireEvent, waitFor, act } from "@testing-library/react";
4
+ import type { MockedFunction } from "vitest";
6
5
  import "@testing-library/jest-dom";
7
6
 
8
- import { parseTheme } from "@ax/helpers";
9
7
  import RecoveryModal, { type IRecoveryProps } from "@ax/components/Login/LoginForm/RecoveryModal";
8
+ import { parseTheme } from "@ax/helpers";
10
9
  import globalTheme from "@ax/themes/theme.json";
11
10
 
12
11
  afterEach(cleanup);
@@ -0,0 +1,86 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { ThemeProvider } from "styled-components";
3
+ import "@testing-library/jest-dom";
4
+
5
+ import SsoDenied from "@ax/components/SsoDenied";
6
+ import { parseTheme } from "@ax/helpers";
7
+ import globalTheme from "@ax/themes/theme.json";
8
+
9
+ afterEach(() => {
10
+ cleanup();
11
+ window.history.pushState({}, "", "/");
12
+ });
13
+
14
+ const SWITCH_URL = "https://api.uni.es/sso/switch-account";
15
+
16
+ const renderS6 = () =>
17
+ render(
18
+ <ThemeProvider theme={parseTheme(globalTheme)}>
19
+ <SsoDenied switchAccountUrl={SWITCH_URL} />
20
+ </ThemeProvider>,
21
+ );
22
+
23
+ const setLanguage = (language: string) => vi.spyOn(window.navigator, "language", "get").mockReturnValue(language);
24
+
25
+ describe("S6 — acceso denegado", () => {
26
+ beforeEach(() => setLanguage("es-ES"));
27
+
28
+ it("dice «You don't have access to this instance» y no menciona motivo ni email", () => {
29
+ const { container } = renderS6();
30
+
31
+ expect(screen.getByRole("heading", { name: "You don't have access to this instance" })).toBeInTheDocument();
32
+ expect(container.textContent).not.toMatch(/motivo|reason|@/i);
33
+ });
34
+
35
+ it("«Sign in with another account» es un enlace al cambio de cuenta de la API", () => {
36
+ renderS6();
37
+
38
+ expect(screen.getByRole("link", { name: "Sign in with another account" })).toHaveAttribute("href", SWITCH_URL);
39
+ });
40
+
41
+ it("el enlace está subrayado", () => {
42
+ renderS6();
43
+
44
+ expect(
45
+ getComputedStyle(screen.getByRole("link", { name: "Sign in with another account" })).textDecoration,
46
+ ).toContain("underline");
47
+ });
48
+
49
+ it("el foco va al título al abrirla", () => {
50
+ renderS6();
51
+
52
+ expect(screen.getByRole("heading")).toHaveFocus();
53
+ });
54
+
55
+ it("no refleja parámetros de la URL: texto fijo con ?reason=<script> y ?email=x", () => {
56
+ window.history.pushState({}, "", "/sso-denied?reason=%3Cscript%3Ealert(1)%3C/script%3E&email=x@y.z");
57
+
58
+ const { container } = renderS6();
59
+
60
+ expect(container.textContent).not.toContain("<script>");
61
+ expect(container.textContent).not.toContain("x@y.z");
62
+ expect(container.querySelector("script")).toBeNull();
63
+ expect(screen.getByRole("heading", { name: "You don't have access to this instance" })).toBeInTheDocument();
64
+ });
65
+
66
+ it("abierta por URL directa muestra la misma pantalla", () => {
67
+ window.history.pushState({}, "", "/sso-denied");
68
+
69
+ renderS6();
70
+
71
+ expect(screen.getByRole("heading", { name: "You don't have access to this instance" })).toBeInTheDocument();
72
+ expect(screen.getByRole("link", { name: "Sign in with another account" })).toBeInTheDocument();
73
+ });
74
+
75
+ it.each([
76
+ ["en-US", "You don't have access to this instance", "Sign in with another account"],
77
+ ["es-ES", "You don't have access to this instance", "Sign in with another account"],
78
+ ["fr-FR", "You don't have access to this instance", "Sign in with another account"],
79
+ ])("idioma %s", (language, title, link) => {
80
+ setLanguage(language);
81
+ renderS6();
82
+
83
+ expect(screen.getByRole("heading", { name: title })).toBeInTheDocument();
84
+ expect(screen.getByRole("link", { name: link })).toBeInTheDocument();
85
+ });
86
+ });
@@ -0,0 +1,18 @@
1
+ import { createRequire } from "node:module";
2
+ import { resolve } from "node:path";
3
+ import paths from "../../../tsconfig.paths.json";
4
+
5
+ const require = createRequire(import.meta.url);
6
+ const { projectAliases } = require(resolve(__dirname, "../../../config/griddo-config")) as {
7
+ projectAliases: Record<string, string>;
8
+ };
9
+
10
+ // Vitest y `tsc` leen `tsconfig.paths.json`; webpack, no: sus alias salen de `config/griddo-config`. Un alias que
11
+ // solo exista en el primero pasa los tests y rompe `pnpm start` (p. ej. `@ax/themes/brandPalette`).
12
+ describe("alias de webpack = alias de tsconfig", () => {
13
+ const roots = [...new Set(Object.keys(paths.compilerOptions.paths).map((alias) => alias.replace(/\/\*$/, "")))];
14
+
15
+ it.each(roots)("%s está declarado en los alias de webpack", (root) => {
16
+ expect(projectAliases).toHaveProperty([root]);
17
+ });
18
+ });
@@ -0,0 +1,18 @@
1
+ import { SET_GLOBAL_SETTINGS } from "@ax/containers/App/constants";
2
+ import { appInitialState, appReducer } from "@ax/containers/App/reducer";
3
+
4
+ describe("GriddoIdEnabled en los settings de AX", () => {
5
+ it("está apagado por defecto: si GET /settings falla se ve el login de siempre", () => {
6
+ expect(appInitialState.globalSettings.GriddoIdEnabled).toBe(false);
7
+ expect(appInitialState.globalSettings.SSOActivated).toBe(false);
8
+ });
9
+
10
+ it("el valor de la API llega al estado", () => {
11
+ const state = appReducer(appInitialState, {
12
+ type: SET_GLOBAL_SETTINGS,
13
+ payload: { globalSettings: { ...appInitialState.globalSettings, GriddoIdEnabled: true } },
14
+ });
15
+
16
+ expect(state.globalSettings.GriddoIdEnabled).toBe(true);
17
+ });
18
+ });