@griddo/ax 12.15.1-astro-rc.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/__tests__/getCSSModuleLocalIdent.test.js +30 -0
- package/config/griddo-config/index.js +3 -2
- package/config/webpack/getCSSModuleLocalIdent.js +10 -0
- package/config/webpack.config.js +1 -1
- package/package.json +8 -6
- 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/Fields/TranslateButton/TranslateButton.test.tsx +121 -4
- 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/components/Fields/TranslateButton/index.tsx +4 -9
- 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,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
|
+
});
|
|
@@ -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
|
+
});
|