@griddo/ax 12.16.0 → 12.17.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.
- package/README.md +1 -0
- package/config/griddo-config/index.js +3 -2
- package/package.json +7 -4
- package/public/img/logos/logoGriddoDxp.svg +22 -0
- package/public/img/logos/logoGriddoG.svg +10 -0
- package/src/GlobalStore.tsx +32 -25
- package/src/__tests__/GlobalStore.session.test.tsx +98 -0
- package/src/__tests__/api/global.test.ts +64 -0
- package/src/__tests__/api/session.test.ts +311 -0
- package/src/__tests__/api/sessionRenewal.test.ts +705 -0
- package/src/__tests__/api/utils.test.ts +373 -0
- package/src/__tests__/components/Fields/FileField/FileField.test.tsx +33 -6
- package/src/__tests__/components/FieldsBehavior/FieldsBehavior.test.tsx +5 -3
- package/src/__tests__/components/Login/BrandPalette.test.tsx +145 -0
- package/src/__tests__/components/Login/Login.test.tsx +2 -33
- package/src/__tests__/components/Login/LoginCollapsible.test.tsx +271 -0
- package/src/__tests__/components/Login/LoginDropdownCard.test.tsx +311 -0
- package/src/__tests__/components/Login/LoginFooter.test.tsx +128 -0
- package/src/__tests__/components/Login/LoginGriddoId.test.tsx +213 -0
- package/src/__tests__/components/Login/LoginInlineError.test.tsx +116 -0
- package/src/__tests__/components/Login/RecoveryModal/RecoveryModal.test.tsx +3 -4
- package/src/__tests__/components/SsoDenied/SsoDenied.test.tsx +86 -0
- package/src/__tests__/config/webpackAliases.test.ts +18 -0
- package/src/__tests__/containers/App/reducer.griddoId.test.ts +18 -0
- package/src/__tests__/containers/App/session.test.ts +397 -0
- package/src/__tests__/containers/App/signInOut.test.ts +159 -0
- package/src/__tests__/helpers/griddoId.test.ts +56 -0
- package/src/__tests__/hooks/useShouldBeSaved.test.tsx +78 -0
- package/src/__tests__/locales/loginLocale.test.ts +37 -0
- package/src/__tests__/modules/App/Routing/NavMenu.test.tsx +54 -0
- package/src/__tests__/modules/App/Routing/PrivateRoute.test.tsx +64 -0
- package/src/__tests__/modules/App/Routing/Routing.startup.test.tsx +79 -0
- package/src/__tests__/modules/Login/Login.test.tsx +169 -0
- package/src/__tests__/modules/Login/loginError.uc.test.tsx +294 -0
- package/src/__tests__/modules/Login/signInOut.test.tsx +125 -0
- package/src/__tests__/modules/Redirects/RedirectPanel/RedirectPanel.test.tsx +9 -0
- package/src/__tests__/modules/Redirects/Redirects/Redirects.create.test.tsx +19 -0
- package/src/__tests__/modules/Redirects/Redirects/Redirects.edit.test.tsx +19 -0
- package/src/__tests__/modules/Redirects/Redirects/Redirects.filter.test.tsx +19 -0
- package/src/__tests__/modules/SsoDenied/SsoDenied.test.tsx +30 -0
- package/src/__tests__/routes/publicRoutes.test.ts +36 -0
- package/src/api/global.tsx +24 -1
- package/src/api/session.tsx +197 -0
- package/src/api/sessionRenewal.tsx +114 -0
- package/src/api/utils.tsx +22 -12
- package/src/{helpers/categoryColumns.tsx → components/CategoryCell/buildCategoryColumns.tsx} +3 -2
- package/src/components/Circle/index.tsx +1 -1
- package/src/components/Circle/style.tsx +4 -2
- package/src/components/ErrorPage/index.tsx +1 -1
- package/src/components/ErrorPage/style.tsx +11 -9
- package/src/components/ErrorToast/index.tsx +2 -0
- package/src/{helpers/fields.tsx → components/FieldsBehavior/getFieldByPath.tsx} +1 -1
- package/src/components/FieldsBehavior/index.tsx +3 -1
- package/src/components/Login/LoginFooter/index.tsx +16 -0
- package/src/components/Login/LoginFooter/style.tsx +17 -0
- package/src/components/Login/LoginForm/index.tsx +147 -79
- package/src/components/Login/LoginForm/style.tsx +147 -24
- package/src/components/Login/LoginGriddoId/index.tsx +56 -0
- package/src/components/Login/LoginGriddoId/style.tsx +35 -0
- package/src/components/Login/LoginSSO/index.tsx +4 -7
- package/src/components/Login/LoginSSO/style.tsx +10 -26
- package/src/components/Login/LoginSlider/style.tsx +5 -5
- package/src/components/Login/index.tsx +35 -6
- package/src/components/Login/style.tsx +40 -24
- package/src/components/Notification/index.tsx +3 -1
- package/src/components/SsoDenied/index.tsx +46 -0
- package/src/components/SsoDenied/style.tsx +37 -0
- package/src/components/index.tsx +11 -7
- package/src/containers/App/actions.tsx +114 -6
- package/src/containers/App/interfaces.tsx +2 -2
- package/src/containers/App/reducer.tsx +9 -0
- package/src/containers/Users/actions.tsx +28 -24
- package/src/helpers/griddoId.ts +28 -0
- package/src/helpers/index.tsx +4 -5
- package/src/hooks/forms.tsx +8 -5
- package/src/locales/en-US.ts +13 -0
- package/src/locales/es-ES.ts +13 -0
- package/src/locales/index.ts +9 -1
- package/src/modules/App/Routing/NavMenu/index.tsx +4 -4
- package/src/modules/Content/PageItem/index.tsx +6 -8
- package/src/modules/Login/index.tsx +33 -14
- package/src/modules/SsoDenied/index.tsx +9 -0
- package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/index.tsx +6 -8
- package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/index.tsx +9 -11
- package/src/modules/Users/UserEdit/index.tsx +9 -2
- package/src/routes/publicRoutes.tsx +3 -0
- package/src/themes/brandPalette.ts +16 -0
- package/public/img/logos/logoSQY.svg +0 -3
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { act, cleanup, fireEvent, 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 globalTheme from "@ax/themes/theme.json";
|
|
9
|
+
|
|
10
|
+
afterEach(cleanup);
|
|
11
|
+
|
|
12
|
+
const baseSettings = {
|
|
13
|
+
cloudinaryName: "cloudinary",
|
|
14
|
+
globalLogoBig: "",
|
|
15
|
+
globalLogoMini: "",
|
|
16
|
+
siteLogoBig: "",
|
|
17
|
+
siteLogoMini: "",
|
|
18
|
+
welcomeText1: "Welcome back to",
|
|
19
|
+
welcomeText2: "Griddo",
|
|
20
|
+
autoSummary: false,
|
|
21
|
+
autoTranslation: false,
|
|
22
|
+
SSOActivated: false,
|
|
23
|
+
GriddoIdEnabled: true,
|
|
24
|
+
SSOWelcomeText: "",
|
|
25
|
+
useForms: false,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const element = (
|
|
29
|
+
settings: Partial<typeof baseSettings>,
|
|
30
|
+
props: Partial<ILoginProps>,
|
|
31
|
+
handlers: Pick<ILoginProps, "handleSubmit" | "handleSSO" | "handleGriddoId">,
|
|
32
|
+
) => (
|
|
33
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
34
|
+
<Login
|
|
35
|
+
email=""
|
|
36
|
+
handleEmail={vi.fn()}
|
|
37
|
+
password=""
|
|
38
|
+
handlePassword={vi.fn()}
|
|
39
|
+
isLoggingIn={false}
|
|
40
|
+
rememberMe={false}
|
|
41
|
+
handleRememberMe={vi.fn()}
|
|
42
|
+
isLoginSuccess={false}
|
|
43
|
+
handleLoginSuccess={vi.fn()}
|
|
44
|
+
errorSSO={null}
|
|
45
|
+
{...handlers}
|
|
46
|
+
{...props}
|
|
47
|
+
settings={{ ...baseSettings, ...settings } as ILoginProps["settings"]}
|
|
48
|
+
/>
|
|
49
|
+
</ThemeProvider>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const renderLogin = (settings: Partial<typeof baseSettings> = {}, props: Partial<ILoginProps> = {}) => {
|
|
53
|
+
const handlers = {
|
|
54
|
+
handleSubmit: vi.fn((e: React.FormEvent) => e.preventDefault()),
|
|
55
|
+
handleSSO: vi.fn(),
|
|
56
|
+
handleGriddoId: vi.fn(),
|
|
57
|
+
};
|
|
58
|
+
const view = render(element(settings, props, handlers));
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
...handlers,
|
|
62
|
+
...view,
|
|
63
|
+
rerenderWith: (next: Partial<typeof baseSettings>) => view.rerender(element(next, props, handlers)),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const TOGGLE = "Login with email and password";
|
|
68
|
+
const toggle = () => screen.getByRole("button", { name: TOGGLE });
|
|
69
|
+
const email = () => screen.getByPlaceholderText("Type your email");
|
|
70
|
+
|
|
71
|
+
describe("[UC-AX-sign-in-out] formulario plegable con Griddo ID", () => {
|
|
72
|
+
beforeEach(() => vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US"));
|
|
73
|
+
|
|
74
|
+
it("AC7 · plegado por defecto: SSO y desplegable visibles; email, contraseña y «Remember me» ocultos", () => {
|
|
75
|
+
renderLogin();
|
|
76
|
+
|
|
77
|
+
expect(screen.getByRole("button", { name: "Sign in with Griddo" })).toBeVisible();
|
|
78
|
+
expect(toggle()).toBeVisible();
|
|
79
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "false");
|
|
80
|
+
expect(email()).not.toBeVisible();
|
|
81
|
+
expect(document.querySelector('input[name="password"]')).not.toBeVisible();
|
|
82
|
+
expect(screen.getByText("Remember me")).not.toBeVisible();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("AC7 · al montar el foco no está en el email", () => {
|
|
86
|
+
renderLogin();
|
|
87
|
+
|
|
88
|
+
expect(email()).not.toHaveFocus();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("AC7 · relación ARIA: aria-controls apunta al contenedor y el desplegable no es un separator", () => {
|
|
92
|
+
renderLogin();
|
|
93
|
+
const id = toggle().getAttribute("aria-controls") as string;
|
|
94
|
+
|
|
95
|
+
expect(id).toBeTruthy();
|
|
96
|
+
expect(document.getElementById(id)).toContainElement(email());
|
|
97
|
+
expect(toggle()).not.toHaveAttribute("role", "separator");
|
|
98
|
+
expect(screen.queryByRole("separator")).toBeNull();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("AC7 · settings que llegan tarde: queda plegado y sin foco en el email", () => {
|
|
102
|
+
const { rerenderWith } = renderLogin({ GriddoIdEnabled: false });
|
|
103
|
+
|
|
104
|
+
rerenderWith({ GriddoIdEnabled: true });
|
|
105
|
+
|
|
106
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "false");
|
|
107
|
+
expect(email()).not.toBeVisible();
|
|
108
|
+
expect(email()).not.toHaveFocus();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("AC8 · desplegar muestra el formulario, aria-expanded=true y enfoca el email", async () => {
|
|
112
|
+
renderLogin();
|
|
113
|
+
|
|
114
|
+
await userEvent.click(toggle());
|
|
115
|
+
|
|
116
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "true");
|
|
117
|
+
expect(email()).toBeVisible();
|
|
118
|
+
expect(email()).toHaveFocus();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("AC8 · plegar de nuevo oculta el formulario, conserva lo escrito y deja el foco en el botón", async () => {
|
|
122
|
+
renderLogin({}, { email: "ana@uni.es", password: "s3cr3t" });
|
|
123
|
+
|
|
124
|
+
await userEvent.click(toggle());
|
|
125
|
+
await userEvent.click(toggle());
|
|
126
|
+
|
|
127
|
+
expect(email()).not.toBeVisible();
|
|
128
|
+
expect(toggle()).toHaveFocus();
|
|
129
|
+
|
|
130
|
+
await userEvent.click(toggle());
|
|
131
|
+
|
|
132
|
+
expect(email()).toHaveValue("ana@uni.es");
|
|
133
|
+
expect(document.querySelector('input[name="password"]')).toHaveValue("s3cr3t");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("AC8 · re-desplegar vuelve a enfocar el email", async () => {
|
|
137
|
+
renderLogin();
|
|
138
|
+
|
|
139
|
+
await userEvent.click(toggle());
|
|
140
|
+
await userEvent.click(toggle());
|
|
141
|
+
expect(email()).not.toHaveFocus();
|
|
142
|
+
await userEvent.click(toggle());
|
|
143
|
+
|
|
144
|
+
expect(email()).toHaveFocus();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("AC8 · dos pulsaciones seguidas dejan el formulario plegado y sin foco en el email", () => {
|
|
148
|
+
renderLogin();
|
|
149
|
+
|
|
150
|
+
fireEvent.click(toggle());
|
|
151
|
+
fireEvent.click(toggle());
|
|
152
|
+
|
|
153
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "false");
|
|
154
|
+
expect(email()).not.toBeVisible();
|
|
155
|
+
expect(email()).not.toHaveFocus();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it.each([
|
|
159
|
+
["Enter", "{Enter}"],
|
|
160
|
+
["Espacio", " "],
|
|
161
|
+
])("AC8 · con teclado (%s) alterna exactamente una vez", async (_name, key) => {
|
|
162
|
+
renderLogin();
|
|
163
|
+
toggle().focus();
|
|
164
|
+
|
|
165
|
+
await userEvent.keyboard(key);
|
|
166
|
+
|
|
167
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "true");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("AC8 · desde el formulario desplegado se puede iniciar sesión", async () => {
|
|
171
|
+
const { handleSubmit } = renderLogin();
|
|
172
|
+
|
|
173
|
+
await userEvent.click(toggle());
|
|
174
|
+
await userEvent.click(screen.getByText("Login"));
|
|
175
|
+
|
|
176
|
+
expect(handleSubmit).toHaveBeenCalledTimes(1);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("AC8 · «Sign in with Griddo» funciona con el formulario plegado", async () => {
|
|
180
|
+
const { handleGriddoId } = renderLogin();
|
|
181
|
+
|
|
182
|
+
await userEvent.click(screen.getByRole("button", { name: "Sign in with Griddo" }));
|
|
183
|
+
|
|
184
|
+
expect(handleGriddoId).toHaveBeenCalledTimes(1);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("AC9 · con el formulario plegado «Lost your password?» del toast abre el modal de recuperación", () => {
|
|
188
|
+
renderLogin();
|
|
189
|
+
|
|
190
|
+
expect(screen.queryByTestId("recovery-modal-content")).toBeNull();
|
|
191
|
+
|
|
192
|
+
act(() => window.handleErrorClick?.());
|
|
193
|
+
|
|
194
|
+
expect(screen.getByTestId("recovery-modal-content")).toBeInTheDocument();
|
|
195
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "false");
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("AC9 · con el formulario plegado el ErrorToast y el errorSSO siguen visibles", () => {
|
|
199
|
+
renderLogin({}, { errorSSO: "Error de SSO" });
|
|
200
|
+
|
|
201
|
+
expect(screen.getByTestId("error-wrapper")).toBeVisible();
|
|
202
|
+
expect(screen.getByText("Error de SSO")).toBeVisible();
|
|
203
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "false");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("AC10 · sin GriddoIdEnabled: formulario visible y sin desplegable", () => {
|
|
207
|
+
renderLogin({ GriddoIdEnabled: false });
|
|
208
|
+
|
|
209
|
+
expect(email()).toBeVisible();
|
|
210
|
+
expect(screen.queryByRole("button", { name: TOGGLE })).toBeNull();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("AC10 · con SSOActivated (Comillas) la pantalla no lleva desplegable ni formulario", () => {
|
|
214
|
+
renderLogin({ SSOActivated: true });
|
|
215
|
+
|
|
216
|
+
expect(screen.queryByRole("button", { name: TOGGLE })).toBeNull();
|
|
217
|
+
expect(screen.queryByPlaceholderText("Type your email")).toBeNull();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("AC12 · al volver con Atrás (página restaurada de la caché) el botón vuelve a navegar", () => {
|
|
221
|
+
const { handleGriddoId } = renderLogin({ GriddoIdEnabled: true });
|
|
222
|
+
const button = screen.getByRole("button", { name: "Sign in with Griddo" });
|
|
223
|
+
|
|
224
|
+
fireEvent.click(button);
|
|
225
|
+
fireEvent.click(button);
|
|
226
|
+
expect(handleGriddoId).toHaveBeenCalledTimes(1);
|
|
227
|
+
|
|
228
|
+
const restored = new Event("pageshow");
|
|
229
|
+
|
|
230
|
+
Object.defineProperty(restored, "persisted", { value: true });
|
|
231
|
+
act(() => {
|
|
232
|
+
window.dispatchEvent(restored);
|
|
233
|
+
});
|
|
234
|
+
fireEvent.click(button);
|
|
235
|
+
|
|
236
|
+
expect(handleGriddoId).toHaveBeenCalledTimes(2);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("AC12 · un pageshow de una carga normal no reabre el botón", () => {
|
|
240
|
+
const { handleGriddoId } = renderLogin({ GriddoIdEnabled: true });
|
|
241
|
+
const button = screen.getByRole("button", { name: "Sign in with Griddo" });
|
|
242
|
+
|
|
243
|
+
fireEvent.click(button);
|
|
244
|
+
act(() => {
|
|
245
|
+
window.dispatchEvent(new Event("pageshow"));
|
|
246
|
+
});
|
|
247
|
+
fireEvent.click(button);
|
|
248
|
+
|
|
249
|
+
expect(handleGriddoId).toHaveBeenCalledTimes(1);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it.each([
|
|
253
|
+
["en-US", "Login"],
|
|
254
|
+
["es-ES", "Login"],
|
|
255
|
+
])("AC11 · idioma %s: texto del botón de envío", (language, submit) => {
|
|
256
|
+
vi.spyOn(window.navigator, "language", "get").mockReturnValue(language);
|
|
257
|
+
renderLogin({ GriddoIdEnabled: false });
|
|
258
|
+
|
|
259
|
+
expect(screen.getByRole("button", { name: submit })).toBeInTheDocument();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it.each([
|
|
263
|
+
["en-US", TOGGLE],
|
|
264
|
+
["es-ES", "Login with email and password"],
|
|
265
|
+
])("AC11 · idioma %s: texto del desplegable", (language, toggleText) => {
|
|
266
|
+
vi.spyOn(window.navigator, "language", "get").mockReturnValue(language);
|
|
267
|
+
renderLogin();
|
|
268
|
+
|
|
269
|
+
expect(screen.getByRole("button", { name: toggleText })).toBeInTheDocument();
|
|
270
|
+
});
|
|
271
|
+
});
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { cleanup, fireEvent, 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> = {}, props: Partial<ILoginProps> = {}) =>
|
|
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
|
+
{...props}
|
|
47
|
+
settings={{ ...baseSettings, ...settings } as ILoginProps["settings"]}
|
|
48
|
+
/>
|
|
49
|
+
</ThemeProvider>,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const TOGGLE = "Login with email and password";
|
|
53
|
+
const toggle = () => screen.getByRole("button", { name: TOGGLE });
|
|
54
|
+
const card = () => screen.getByTestId("login-dropdown");
|
|
55
|
+
const email = () => screen.getByPlaceholderText("Type your email");
|
|
56
|
+
const sso = () => screen.getByRole("button", { name: "Sign in with Griddo" });
|
|
57
|
+
|
|
58
|
+
describe("[UC-AX-sign-in-out] dropdown de email como botón (AC7/AC8/AC14)", () => {
|
|
59
|
+
beforeEach(() => vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US"));
|
|
60
|
+
|
|
61
|
+
it("AC7 · plegado: botón 48px con el estilo del Figma (navyControl, borde, radio 8, 15/19)", () => {
|
|
62
|
+
renderLogin();
|
|
63
|
+
|
|
64
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "false");
|
|
65
|
+
// Desde -03 la caja plegada la lleva el botón (el contenedor es transparente para alojar el #error encima).
|
|
66
|
+
expect(toggle()).toHaveStyle({
|
|
67
|
+
backgroundColor: BRAND_PALETTE.navyControl,
|
|
68
|
+
border: "1px solid rgba(219,221,233,.3)",
|
|
69
|
+
borderRadius: "8px",
|
|
70
|
+
});
|
|
71
|
+
expect(card()).toHaveStyle({ padding: "0px" });
|
|
72
|
+
expect(toggle()).toHaveStyle({ height: "48px", width: "100%", fontSize: "15px", lineHeight: "19px" });
|
|
73
|
+
expect(email()).not.toBeVisible();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("AC7 · el chevron es de 24px y apunta hacia abajo plegado", () => {
|
|
77
|
+
renderLogin();
|
|
78
|
+
|
|
79
|
+
const svg = toggle().querySelector("svg");
|
|
80
|
+
|
|
81
|
+
expect(svg).toHaveAttribute("width", "24");
|
|
82
|
+
expect(svg).toHaveAttribute("height", "24");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("AC7 · va debajo del SSO con 32px de hueco (Figma) y ya no hay línea separadora", () => {
|
|
86
|
+
renderLogin();
|
|
87
|
+
|
|
88
|
+
expect(sso().compareDocumentPosition(card()) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
89
|
+
expect(card()).toHaveStyle({ marginTop: "32px" });
|
|
90
|
+
expect(screen.queryByTestId("login-divider")).toBeNull();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("AC8 · abrir: la misma caja pasa a tarjeta (radio 12, padding 11/25/28/23) con cabecera + formulario y foco en el email", async () => {
|
|
94
|
+
renderLogin();
|
|
95
|
+
|
|
96
|
+
await userEvent.click(toggle());
|
|
97
|
+
|
|
98
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "true");
|
|
99
|
+
expect(card()).toHaveStyle({
|
|
100
|
+
backgroundColor: BRAND_PALETTE.navyControl,
|
|
101
|
+
border: "1px solid rgba(219,221,233,.3)",
|
|
102
|
+
borderRadius: "12px",
|
|
103
|
+
padding: "11px 25px 28px 23px",
|
|
104
|
+
});
|
|
105
|
+
expect(card()).toContainElement(toggle());
|
|
106
|
+
expect(card()).toContainElement(email());
|
|
107
|
+
expect(email()).toBeVisible();
|
|
108
|
+
expect(email()).toHaveFocus();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("AC8 · plegar conserva lo escrito y devuelve el foco al botón", async () => {
|
|
112
|
+
renderLogin({}, { email: "ana@uni.es", password: "s3cr3t" });
|
|
113
|
+
|
|
114
|
+
await userEvent.click(toggle());
|
|
115
|
+
await userEvent.click(toggle());
|
|
116
|
+
|
|
117
|
+
expect(toggle()).toHaveFocus();
|
|
118
|
+
expect(card()).toHaveStyle({ borderRadius: "8px", padding: "0px" });
|
|
119
|
+
|
|
120
|
+
await userEvent.click(toggle());
|
|
121
|
+
|
|
122
|
+
expect(email()).toHaveValue("ana@uni.es");
|
|
123
|
+
expect(document.querySelector('input[name="password"]')).toHaveValue("s3cr3t");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("AC14 · el botón SSO no se mueve: va antes de la tarjeta y no depende de su estado", async () => {
|
|
127
|
+
renderLogin();
|
|
128
|
+
const before = sso().parentElement?.parentElement?.outerHTML;
|
|
129
|
+
|
|
130
|
+
await userEvent.click(toggle());
|
|
131
|
+
expect(card().contains(sso())).toBe(false);
|
|
132
|
+
expect(sso().compareDocumentPosition(card()) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
133
|
+
|
|
134
|
+
await userEvent.click(toggle());
|
|
135
|
+
expect(sso().parentElement?.parentElement?.outerHTML).toBe(before);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("AC14 · el panel plegado no reserva alto: se oculta sin quedarse en el flujo", () => {
|
|
139
|
+
renderLogin();
|
|
140
|
+
const panel = document.getElementById(toggle().getAttribute("aria-controls") as string) as HTMLElement;
|
|
141
|
+
|
|
142
|
+
expect(panel).toHaveStyle({ visibility: "hidden", gridTemplateRows: "0fr" });
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("AC14 · abierto el panel ocupa su alto y es visible", async () => {
|
|
146
|
+
renderLogin();
|
|
147
|
+
await userEvent.click(toggle());
|
|
148
|
+
const panel = document.getElementById(toggle().getAttribute("aria-controls") as string) as HTMLElement;
|
|
149
|
+
|
|
150
|
+
expect(panel).toHaveStyle({ visibility: "visible", gridTemplateRows: "1fr" });
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("AC7 · plegado, Tab pasa del botón a lo siguiente sin entrar en email, contraseña ni «Lost your password?»", async () => {
|
|
154
|
+
renderLogin();
|
|
155
|
+
sso().focus();
|
|
156
|
+
|
|
157
|
+
await userEvent.tab();
|
|
158
|
+
expect(toggle()).toHaveFocus();
|
|
159
|
+
|
|
160
|
+
await userEvent.tab();
|
|
161
|
+
expect(email()).not.toHaveFocus();
|
|
162
|
+
expect(screen.getByTestId("forgot-button")).not.toHaveFocus();
|
|
163
|
+
expect(document.querySelector('input[name="password"]')).not.toHaveFocus();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("AC8 · doble pulsación rápida: aria-expanded refleja el último estado", () => {
|
|
167
|
+
renderLogin();
|
|
168
|
+
|
|
169
|
+
fireEvent.click(toggle());
|
|
170
|
+
fireEvent.click(toggle());
|
|
171
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "false");
|
|
172
|
+
|
|
173
|
+
fireEvent.click(toggle());
|
|
174
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "true");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("AC8 · con prefers-reduced-motion no hay transición", () => {
|
|
178
|
+
renderLogin();
|
|
179
|
+
const panel = document.getElementById(toggle().getAttribute("aria-controls") as string) as HTMLElement;
|
|
180
|
+
const css = Array.from(document.querySelectorAll("style"))
|
|
181
|
+
.map((s) => s.textContent)
|
|
182
|
+
.join("");
|
|
183
|
+
|
|
184
|
+
expect(panel).toBeInTheDocument();
|
|
185
|
+
expect(css).toMatch(/@media \(prefers-reduced-motion:\s*reduce\)\{[^}]*(\{[^}]*\}[^}]*)*transition:\s*none/);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("AC8 · isLoggingIn con la tarjeta abierta: botón deshabilitado y la tarjeta no se pliega", async () => {
|
|
189
|
+
const view = renderLogin();
|
|
190
|
+
|
|
191
|
+
await userEvent.click(toggle());
|
|
192
|
+
view.rerender(
|
|
193
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
194
|
+
<Login
|
|
195
|
+
handleSubmit={vi.fn()}
|
|
196
|
+
email=""
|
|
197
|
+
handleEmail={vi.fn()}
|
|
198
|
+
password=""
|
|
199
|
+
handlePassword={vi.fn()}
|
|
200
|
+
isLoggingIn
|
|
201
|
+
rememberMe={false}
|
|
202
|
+
handleRememberMe={vi.fn()}
|
|
203
|
+
isLoginSuccess={false}
|
|
204
|
+
handleLoginSuccess={vi.fn()}
|
|
205
|
+
handleSSO={vi.fn()}
|
|
206
|
+
handleGriddoId={vi.fn()}
|
|
207
|
+
errorSSO={null}
|
|
208
|
+
settings={baseSettings as ILoginProps["settings"]}
|
|
209
|
+
/>
|
|
210
|
+
</ThemeProvider>,
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
expect(screen.getByRole("button", { name: "Sending" })).toBeDisabled();
|
|
214
|
+
expect(toggle()).toHaveAttribute("aria-expanded", "true");
|
|
215
|
+
expect(card()).toHaveStyle({ borderRadius: "12px", padding: "11px 25px 28px 23px" });
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("AC14 · RecoveryModal queda fuera de la zona plegable", () => {
|
|
219
|
+
renderLogin();
|
|
220
|
+
const panel = document.getElementById(toggle().getAttribute("aria-controls") as string) as HTMLElement;
|
|
221
|
+
|
|
222
|
+
expect(panel.querySelector('[data-testid="recovery-modal-content"]')).toBeNull();
|
|
223
|
+
expect(card().querySelector('[data-testid="recovery-modal-content"]')).toBeNull();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe("[UC-AX-sign-in-out] bloque anclado arriba solo con Griddo ID (AC14)", () => {
|
|
228
|
+
beforeEach(() => vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US"));
|
|
229
|
+
|
|
230
|
+
it("el logo Brand entra en el flujo del bloque, antes de «Welcome» y sin posición absoluta", () => {
|
|
231
|
+
renderLogin();
|
|
232
|
+
const logo = screen.getByAltText("Griddo DXP");
|
|
233
|
+
const block = screen.getByTestId("login-block");
|
|
234
|
+
|
|
235
|
+
expect(block).toContainElement(logo);
|
|
236
|
+
expect(
|
|
237
|
+
logo.compareDocumentPosition(screen.getByRole("heading", { name: "Welcome" })) & Node.DOCUMENT_POSITION_FOLLOWING,
|
|
238
|
+
).toBeTruthy();
|
|
239
|
+
expect(screen.getByTestId("login-brand")).not.toHaveStyle({ position: "absolute" });
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("el bloque arranca arriba (64px, align flex-start) y hace scroll interno si no cabe", () => {
|
|
243
|
+
renderLogin();
|
|
244
|
+
|
|
245
|
+
expect(screen.getByTestId("login-block")).toHaveStyle({
|
|
246
|
+
alignItems: "flex-start",
|
|
247
|
+
paddingTop: "64px",
|
|
248
|
+
overflowY: "auto",
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("login normal: sigue centrado y sin dropdown", () => {
|
|
253
|
+
renderLogin({ GriddoIdEnabled: false });
|
|
254
|
+
|
|
255
|
+
expect(screen.getByTestId("login-block")).toHaveStyle({ alignItems: "center", paddingTop: "0px" });
|
|
256
|
+
expect(screen.queryByTestId("login-dropdown")).toBeNull();
|
|
257
|
+
expect(screen.queryByAltText("Griddo DXP")).toBeNull();
|
|
258
|
+
expect(email()).toBeVisible();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("Comillas (con y sin GriddoIdEnabled): sin anclar y sin logo Brand", () => {
|
|
262
|
+
for (const GriddoIdEnabled of [false, true]) {
|
|
263
|
+
renderLogin({ SSOActivated: true, GriddoIdEnabled });
|
|
264
|
+
|
|
265
|
+
expect(screen.queryByAltText("Griddo DXP")).toBeNull();
|
|
266
|
+
expect(screen.queryByTestId("login-dropdown")).toBeNull();
|
|
267
|
+
cleanup();
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe("[UC-AX-sign-in-out] despliegue suave del dropdown (AC8)", () => {
|
|
273
|
+
beforeEach(() => vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US"));
|
|
274
|
+
|
|
275
|
+
// Plegado y abierto cambian caja (padding, borde, fondo, radio) y alto del botón: si solo se anima el panel, la
|
|
276
|
+
// tarjeta salta de golpe y el texto del botón pasa de 16px a 24px de padding sin transición.
|
|
277
|
+
const transitionOf = (el: HTMLElement) => getComputedStyle(el).transition;
|
|
278
|
+
|
|
279
|
+
it.each([
|
|
280
|
+
["contenedor", () => card(), ["padding", "background-color", "border-color", "border-radius"]],
|
|
281
|
+
["botón", () => toggle(), ["padding", "height", "background-color", "border-color", "border-radius"]],
|
|
282
|
+
] as const)("AC8 · el %s anima sus propiedades de caja con la misma duración que el panel", (_n, get, props) => {
|
|
283
|
+
renderLogin();
|
|
284
|
+
|
|
285
|
+
for (const prop of props) {
|
|
286
|
+
expect(transitionOf(get())).toMatch(new RegExp(`${prop} 0\\.3s ease`));
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe("[UC-AX-sign-in-out] sin saltos de los campos al desplegar (AC8)", () => {
|
|
292
|
+
beforeEach(() => vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US"));
|
|
293
|
+
|
|
294
|
+
it("AC8 · el foco del email no hace scroll del panel (si no, los campos saltan hacia arriba al abrir)", async () => {
|
|
295
|
+
const focus = vi.spyOn(HTMLElement.prototype, "focus");
|
|
296
|
+
renderLogin();
|
|
297
|
+
|
|
298
|
+
await userEvent.click(toggle());
|
|
299
|
+
|
|
300
|
+
const emailCall = focus.mock.instances.findIndex((el) => (el as HTMLInputElement).name === "email");
|
|
301
|
+
expect(emailCall).toBeGreaterThanOrEqual(0);
|
|
302
|
+
expect(focus.mock.calls[emailCall][0]).toEqual({ preventScroll: true });
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("AC8 · el formulario conserva el ancho de la tarjeta abierta desde el primer frame (sin reflow de los inputs)", () => {
|
|
306
|
+
renderLogin();
|
|
307
|
+
|
|
308
|
+
// 368 (bloque) − 2×1px de borde − 2×24px de padding de la tarjeta abierta.
|
|
309
|
+
expect(email().closest("form")).toHaveStyle({ width: "318px" });
|
|
310
|
+
});
|
|
311
|
+
});
|