@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,294 @@
|
|
|
1
|
+
import { Provider } from "react-redux";
|
|
2
|
+
import { MemoryRouter, Route } from "react-router-dom";
|
|
3
|
+
|
|
4
|
+
import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
|
5
|
+
import userEvent from "@testing-library/user-event";
|
|
6
|
+
import { applyMiddleware, combineReducers, createStore } from "redux";
|
|
7
|
+
import thunk from "redux-thunk";
|
|
8
|
+
import { ThemeProvider } from "styled-components";
|
|
9
|
+
import "@testing-library/jest-dom";
|
|
10
|
+
|
|
11
|
+
import { global, languages, users } from "@ax/api";
|
|
12
|
+
import { appActions } from "@ax/containers/App";
|
|
13
|
+
import { appInitialState, appReducer, type IAppState } from "@ax/containers/App/reducer";
|
|
14
|
+
import { sitesReducer } from "@ax/containers/Sites/reducer";
|
|
15
|
+
import { usersReducer } from "@ax/containers/Users/reducer";
|
|
16
|
+
import { ErrorGuard } from "@ax/guards";
|
|
17
|
+
import { parseTheme } from "@ax/helpers";
|
|
18
|
+
import LoginModule from "@ax/modules/Login";
|
|
19
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
20
|
+
|
|
21
|
+
// UC-AX-sign-in-out · AC15/AC16: el error de login dentro de la tarjeta. Store REAL (reducer `app` + thunks) con la
|
|
22
|
+
// API (`global`) simulada, y el `ErrorGuard` montado como en `Routing`: lo que se asierta es lo que la persona ve.
|
|
23
|
+
|
|
24
|
+
const TOGGLE = "Login with email and password";
|
|
25
|
+
const toggle = () => screen.findByRole("button", { name: TOGGLE });
|
|
26
|
+
const card = () => screen.getByTestId("login-dropdown");
|
|
27
|
+
const emailInput = () => screen.getByPlaceholderText("Type your email");
|
|
28
|
+
const passwordInput = () => document.querySelector('input[name="password"]') as HTMLInputElement;
|
|
29
|
+
// El aviso pintado en el #error (el de errorSSO es otro `Notification`, con el mismo testid, fuera de él).
|
|
30
|
+
const banner = () => document.querySelector<HTMLElement>("#error [data-testid=notification-wrapper]");
|
|
31
|
+
|
|
32
|
+
const FORBIDDEN = { status: 403, data: { code: 403, message: "Unknown email or password" } };
|
|
33
|
+
|
|
34
|
+
let loginResponse: unknown = FORBIDDEN;
|
|
35
|
+
|
|
36
|
+
const renderLogin = async (path = "/login") => {
|
|
37
|
+
vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US");
|
|
38
|
+
vi.spyOn(global, "getSettings").mockResolvedValue({
|
|
39
|
+
status: 200,
|
|
40
|
+
data: { ...appInitialState.globalSettings, GriddoIdEnabled: true },
|
|
41
|
+
} as never);
|
|
42
|
+
vi.spyOn(global, "login").mockImplementation((async () => loginResponse) as never);
|
|
43
|
+
|
|
44
|
+
const store = createStore(
|
|
45
|
+
combineReducers({ app: appReducer, users: usersReducer, sites: sitesReducer }),
|
|
46
|
+
applyMiddleware(thunk),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
render(
|
|
50
|
+
<Provider store={store}>
|
|
51
|
+
<MemoryRouter initialEntries={[path]}>
|
|
52
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
53
|
+
<ErrorGuard />
|
|
54
|
+
<Route path={["/login/:petitionId", "/login"]}>
|
|
55
|
+
<LoginModule />
|
|
56
|
+
</Route>
|
|
57
|
+
</ThemeProvider>
|
|
58
|
+
</MemoryRouter>
|
|
59
|
+
</Provider>,
|
|
60
|
+
);
|
|
61
|
+
await toggle();
|
|
62
|
+
|
|
63
|
+
return store;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const openPanel = async () => userEvent.click(await toggle());
|
|
67
|
+
|
|
68
|
+
const failLogin = async () => {
|
|
69
|
+
await userEvent.type(emailInput(), "ana@uni.es");
|
|
70
|
+
await userEvent.type(passwordInput(), "mala");
|
|
71
|
+
await userEvent.click(screen.getByRole("button", { name: "Login" }));
|
|
72
|
+
await waitFor(() => expect(banner()).not.toBeNull());
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
loginResponse = FORBIDDEN;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
afterEach(() => {
|
|
80
|
+
cleanup();
|
|
81
|
+
vi.restoreAllMocks();
|
|
82
|
+
delete (window as { handleErrorClick?: () => void }).handleErrorClick;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("[UC-AX-sign-in-out] error de login en la tarjeta (AC15)", () => {
|
|
86
|
+
it("AC15 · 403 con el panel abierto: el banner sale dentro de la tarjeta, encima de Email", async () => {
|
|
87
|
+
await renderLogin();
|
|
88
|
+
await openPanel();
|
|
89
|
+
|
|
90
|
+
await failLogin();
|
|
91
|
+
|
|
92
|
+
expect(banner()).toHaveTextContent("Unknown email or password");
|
|
93
|
+
expect(card()).toContainElement(banner());
|
|
94
|
+
expect(
|
|
95
|
+
(banner() as HTMLElement).compareDocumentPosition(emailInput()) & Node.DOCUMENT_POSITION_FOLLOWING,
|
|
96
|
+
).toBeTruthy();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("AC15 · plegar y volver a abrir no pierde el error y solo hay un #error en el DOM", async () => {
|
|
100
|
+
await renderLogin();
|
|
101
|
+
await openPanel();
|
|
102
|
+
await failLogin();
|
|
103
|
+
|
|
104
|
+
await userEvent.click(await toggle());
|
|
105
|
+
expect(banner()).not.toBeNull();
|
|
106
|
+
expect(document.querySelectorAll("#error")).toHaveLength(1);
|
|
107
|
+
|
|
108
|
+
await userEvent.click(await toggle());
|
|
109
|
+
expect(banner()).toHaveTextContent("Unknown email or password");
|
|
110
|
+
expect(document.querySelectorAll("#error")).toHaveLength(1);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("AC15 · un 403 con el panel plegado (sin abrirlo) sale en el hueco de encima del botón y no abre el panel", async () => {
|
|
114
|
+
const store = await renderLogin();
|
|
115
|
+
|
|
116
|
+
await store.dispatch(appActions.login({ email: "ana@uni.es", password: "mala" }) as never);
|
|
117
|
+
await waitFor(() => expect(banner()).not.toBeNull());
|
|
118
|
+
|
|
119
|
+
expect((await toggle()).getAttribute("aria-expanded")).toBe("false");
|
|
120
|
+
expect(document.querySelectorAll("#error")).toHaveLength(1);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("AC15 · errorSSO con el panel plegado: se ve encima del dropdown y el panel sigue plegado", async () => {
|
|
124
|
+
await renderLogin("/login/noregistered+ana@uni.es");
|
|
125
|
+
|
|
126
|
+
expect(screen.getByText(/isn't registered in Griddo/)).toBeVisible();
|
|
127
|
+
expect(await toggle()).toHaveAttribute("aria-expanded", "false");
|
|
128
|
+
expect(card()).not.toContainElement(screen.getByText(/isn't registered in Griddo/));
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("AC15 · errorSSO y un 403 a la vez: se muestran ambos sin pisarse", async () => {
|
|
132
|
+
await renderLogin("/login/noregistered+ana@uni.es");
|
|
133
|
+
await openPanel();
|
|
134
|
+
|
|
135
|
+
await failLogin();
|
|
136
|
+
|
|
137
|
+
expect(screen.getByText(/isn't registered in Griddo/)).toBeVisible();
|
|
138
|
+
expect(banner()).toHaveTextContent("Unknown email or password");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it.each([
|
|
142
|
+
["el email", () => emailInput(), "x"],
|
|
143
|
+
["la contraseña", () => passwordInput(), "x"],
|
|
144
|
+
])("AC15 · escribir en %s limpia el banner", async (_name, field, key) => {
|
|
145
|
+
await renderLogin();
|
|
146
|
+
await openPanel();
|
|
147
|
+
await failLogin();
|
|
148
|
+
|
|
149
|
+
await userEvent.type(field(), key);
|
|
150
|
+
|
|
151
|
+
expect(banner()).toBeNull();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("AC15 · «Remember me» NO limpia el error (decisión de AC: solo los campos de credenciales lo limpian)", async () => {
|
|
155
|
+
await renderLogin();
|
|
156
|
+
await openPanel();
|
|
157
|
+
await failLogin();
|
|
158
|
+
|
|
159
|
+
await userEvent.click(screen.getByText("Remember me"));
|
|
160
|
+
|
|
161
|
+
expect(banner()).toHaveTextContent("Unknown email or password");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("AC15 · cerrar el banner con la X y repetir el mismo 403 lo vuelve a mostrar", async () => {
|
|
165
|
+
await renderLogin();
|
|
166
|
+
await openPanel();
|
|
167
|
+
await failLogin();
|
|
168
|
+
|
|
169
|
+
await userEvent.click(screen.getByTestId("close-button"));
|
|
170
|
+
expect(banner()).toBeNull();
|
|
171
|
+
|
|
172
|
+
await userEvent.click(screen.getByRole("button", { name: "Login" }));
|
|
173
|
+
|
|
174
|
+
await waitFor(() => expect(banner()).toHaveTextContent("Unknown email or password"));
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("AC15 · sin respuesta de la API: aviso 503 en el #error único", async () => {
|
|
178
|
+
loginResponse = undefined;
|
|
179
|
+
await renderLogin();
|
|
180
|
+
await openPanel();
|
|
181
|
+
|
|
182
|
+
await failLogin();
|
|
183
|
+
|
|
184
|
+
expect(banner()).toHaveTextContent("An error has occurred. Please contact your system administrator.");
|
|
185
|
+
expect(document.querySelectorAll("#error")).toHaveLength(1);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("AC15 · 500: no hay banner (redirige a /500)", async () => {
|
|
189
|
+
loginResponse = { status: 500, data: { code: 500, message: "boom" } };
|
|
190
|
+
const store = await renderLogin();
|
|
191
|
+
await openPanel();
|
|
192
|
+
|
|
193
|
+
await userEvent.type(emailInput(), "ana@uni.es");
|
|
194
|
+
await userEvent.type(passwordInput(), "x");
|
|
195
|
+
await userEvent.click(screen.getByRole("button", { name: "Login" }));
|
|
196
|
+
|
|
197
|
+
await waitFor(() => expect(global.login).toHaveBeenCalled());
|
|
198
|
+
expect(banner()).toBeNull();
|
|
199
|
+
expect((store.getState() as { app: IAppState }).app.error.code).toBeUndefined();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("AC15 · el banner se anuncia a lectores de pantalla (role=alert en el #error)", async () => {
|
|
203
|
+
await renderLogin();
|
|
204
|
+
await openPanel();
|
|
205
|
+
|
|
206
|
+
await failLogin();
|
|
207
|
+
|
|
208
|
+
expect(document.querySelector("#error")).toHaveAttribute("role", "alert");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("AC15 · un error persistido de la sesión anterior no se pinta al cargar /login", async () => {
|
|
212
|
+
// `error` está fuera de lo que `redux-persist` guarda (blacklist de `GlobalStore`): un store nuevo nace sin él.
|
|
213
|
+
await renderLogin();
|
|
214
|
+
|
|
215
|
+
expect(banner()).toBeNull();
|
|
216
|
+
expect(appInitialState.error.text).toBe("");
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe("[UC-AX-sign-in-out] «Lost your password?» fiable (AC16)", () => {
|
|
221
|
+
it("AC16 · tras escribir → 403 → clic en «Lost your password?» del aviso se abre el modal de recuperación", async () => {
|
|
222
|
+
await renderLogin();
|
|
223
|
+
await openPanel();
|
|
224
|
+
await failLogin();
|
|
225
|
+
|
|
226
|
+
await userEvent.click(screen.getByTestId("action-button"));
|
|
227
|
+
|
|
228
|
+
expect(await screen.findByText("Recover Password")).toBeInTheDocument();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("AC16 · sin depender de window.handleErrorClick: con el global undefined el botón abre el modal", async () => {
|
|
232
|
+
await renderLogin();
|
|
233
|
+
await openPanel();
|
|
234
|
+
await failLogin();
|
|
235
|
+
(window as { handleErrorClick?: () => void }).handleErrorClick = undefined;
|
|
236
|
+
|
|
237
|
+
await userEvent.click(screen.getByTestId("action-button"));
|
|
238
|
+
|
|
239
|
+
expect(await screen.findByText("Recover Password")).toBeInTheDocument();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("AC16 · el clic en el aviso sigue funcionando tras cerrar el modal y repetir el fallo", async () => {
|
|
243
|
+
await renderLogin();
|
|
244
|
+
await openPanel();
|
|
245
|
+
await failLogin();
|
|
246
|
+
await userEvent.click(screen.getByTestId("action-button"));
|
|
247
|
+
await userEvent.click(await screen.findByText("Cancel"));
|
|
248
|
+
await waitFor(() => expect(screen.queryByText("Recover Password")).toBeNull());
|
|
249
|
+
|
|
250
|
+
await userEvent.click(screen.getByRole("button", { name: "Login" }));
|
|
251
|
+
await waitFor(() => expect(banner()).not.toBeNull());
|
|
252
|
+
await userEvent.click(screen.getByTestId("action-button"));
|
|
253
|
+
|
|
254
|
+
expect(await screen.findByText("Recover Password")).toBeInTheDocument();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("AC16 · si falla el envío de recuperación, el error sale en el modal y no en el #error del login", async () => {
|
|
258
|
+
vi.spyOn(global, "forgotPassword").mockResolvedValue({ status: 404, data: {} } as never);
|
|
259
|
+
await renderLogin();
|
|
260
|
+
await openPanel();
|
|
261
|
+
await userEvent.click(screen.getByTestId("forgot-button"));
|
|
262
|
+
|
|
263
|
+
const modal = within(await screen.findByTestId("recovery-modal-content"));
|
|
264
|
+
|
|
265
|
+
fireEvent.change(modal.getByPlaceholderText("Type your email"), { target: { value: "nadie@uni.es" } });
|
|
266
|
+
const reset = screen.getByRole("button", { name: "Reset Password" });
|
|
267
|
+
|
|
268
|
+
await waitFor(() => expect(reset).not.toBeDisabled());
|
|
269
|
+
await userEvent.click(reset);
|
|
270
|
+
|
|
271
|
+
expect(await screen.findByText("Sorry, this email doesn't exist.")).toBeInTheDocument();
|
|
272
|
+
expect(banner()).toBeNull();
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
describe("[UC-AX-sign-in-out] flujo integrado Griddo ID (AC8, AC15, AC16, AC17)", () => {
|
|
277
|
+
it("abrir el dropdown → 403 → «Lost your password?» → cerrar el modal → login correcto con la animación de éxito y el pie", async () => {
|
|
278
|
+
vi.spyOn(languages, "getLanguages").mockResolvedValue({ status: 200, data: { items: [] } } as never);
|
|
279
|
+
vi.spyOn(users, "getUser").mockResolvedValue({ status: 200, data: { id: 1, roles: [] } } as never);
|
|
280
|
+
await renderLogin();
|
|
281
|
+
await openPanel();
|
|
282
|
+
await failLogin();
|
|
283
|
+
await userEvent.click(screen.getByTestId("action-button"));
|
|
284
|
+
await userEvent.click(await screen.findByText("Cancel"));
|
|
285
|
+
await waitFor(() => expect(screen.queryByText("Recover Password")).toBeNull());
|
|
286
|
+
|
|
287
|
+
loginResponse = { status: 200, data: { id: 1, token: "tok" } };
|
|
288
|
+
await userEvent.click(screen.getByRole("button", { name: "Login" }));
|
|
289
|
+
|
|
290
|
+
await waitFor(() => expect(screen.getByTestId("login-left")).toHaveClass("animate"));
|
|
291
|
+
expect(screen.getAllByTestId("login-footer")).toHaveLength(1);
|
|
292
|
+
expect(screen.getByTestId("login-footer")).toHaveTextContent("Edit. See. Publish");
|
|
293
|
+
});
|
|
294
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Provider } from "react-redux";
|
|
2
|
+
import { MemoryRouter, Route } from "react-router-dom";
|
|
3
|
+
|
|
4
|
+
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
5
|
+
import configureStore from "redux-mock-store";
|
|
6
|
+
import thunk from "redux-thunk";
|
|
7
|
+
import { ThemeProvider } from "styled-components";
|
|
8
|
+
import "@testing-library/jest-dom";
|
|
9
|
+
|
|
10
|
+
import { appInitialState } from "@ax/containers/App/reducer";
|
|
11
|
+
import { parseTheme } from "@ax/helpers";
|
|
12
|
+
import LoginModule from "@ax/modules/Login";
|
|
13
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
14
|
+
|
|
15
|
+
const SSO_URL = "https://sso.uni.es/start";
|
|
16
|
+
|
|
17
|
+
const actions = vi.hoisted(() => ({
|
|
18
|
+
login: vi.fn(),
|
|
19
|
+
loginSSO: vi.fn(),
|
|
20
|
+
setHistoryPush: vi.fn(),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
vi.mock("@ax/containers/App", async (importOriginal) => {
|
|
24
|
+
const original = await importOriginal<typeof import("@ax/containers/App")>();
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
...original,
|
|
28
|
+
appActions: {
|
|
29
|
+
...original.appActions,
|
|
30
|
+
login: (data: unknown) => {
|
|
31
|
+
actions.login(data);
|
|
32
|
+
|
|
33
|
+
return async () => true;
|
|
34
|
+
},
|
|
35
|
+
loginSSO: () => {
|
|
36
|
+
actions.loginSSO();
|
|
37
|
+
|
|
38
|
+
return async () => SSO_URL;
|
|
39
|
+
},
|
|
40
|
+
setHistoryPush: (path: string) => {
|
|
41
|
+
actions.setHistoryPush(path);
|
|
42
|
+
|
|
43
|
+
return { type: "test/setHistoryPush" };
|
|
44
|
+
},
|
|
45
|
+
resetError: () => ({ type: "test/resetError" }),
|
|
46
|
+
getGlobalSettings: () => ({ type: "test/getGlobalSettings" }),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
cleanup();
|
|
53
|
+
vi.clearAllMocks();
|
|
54
|
+
vi.unstubAllGlobals();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const renderAt = (path: string, globalSettings: Partial<typeof appInitialState.globalSettings> = {}) => {
|
|
58
|
+
const store = configureStore([thunk])({
|
|
59
|
+
app: { isLoggingIn: false, globalSettings: { ...appInitialState.globalSettings, ...globalSettings } },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return render(
|
|
63
|
+
<Provider store={store}>
|
|
64
|
+
<MemoryRouter initialEntries={[path]}>
|
|
65
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
66
|
+
<Route path={["/login/:petitionId", "/login"]}>
|
|
67
|
+
<LoginModule />
|
|
68
|
+
</Route>
|
|
69
|
+
</ThemeProvider>
|
|
70
|
+
</MemoryRouter>
|
|
71
|
+
</Provider>,
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
describe("[UC-AX-sign-in-out] módulo Login", () => {
|
|
76
|
+
it("AC1 · tras iniciar sesión y acabar la animación redirige a /sites", async () => {
|
|
77
|
+
const { container } = renderAt("/login");
|
|
78
|
+
|
|
79
|
+
fireEvent.submit(screen.getByPlaceholderText("Type your email").closest("form") as HTMLFormElement);
|
|
80
|
+
await waitFor(() => expect(container.querySelector(".animate")).not.toBeNull());
|
|
81
|
+
|
|
82
|
+
expect(actions.setHistoryPush).not.toHaveBeenCalled();
|
|
83
|
+
|
|
84
|
+
fireEvent.animationEnd(container.querySelector(".animate") as Element);
|
|
85
|
+
|
|
86
|
+
expect(actions.setHistoryPush).toHaveBeenCalledExactlyOnceWith("/sites");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("AC6 · con SSO activado, el botón llama a loginSSO() y navega a la URL", async () => {
|
|
90
|
+
const open = vi.fn();
|
|
91
|
+
|
|
92
|
+
vi.stubGlobal("open", open);
|
|
93
|
+
renderAt("/login", { SSOActivated: true });
|
|
94
|
+
const button = screen.getAllByRole("button")[0];
|
|
95
|
+
|
|
96
|
+
fireEvent.click(button);
|
|
97
|
+
|
|
98
|
+
await waitFor(() => expect(open).toHaveBeenCalledExactlyOnceWith(SSO_URL, "_self"));
|
|
99
|
+
expect(actions.loginSSO).toHaveBeenCalledTimes(1);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it.each([
|
|
103
|
+
["noemail", "No email found in token"],
|
|
104
|
+
["noregistered+ana@uni.es", "The email ana@uni.es isn't registered in Griddo."],
|
|
105
|
+
])("AC6 · retorno con %s muestra el mensaje y no hay auto-login", (petition, message) => {
|
|
106
|
+
renderAt(`/login/${petition}`, { SSOActivated: true });
|
|
107
|
+
|
|
108
|
+
expect(screen.getByText(new RegExp(message))).toBeInTheDocument();
|
|
109
|
+
expect(actions.login).not.toHaveBeenCalled();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("AC6 (borde) · un email con «+» se muestra entero en el mensaje", () => {
|
|
113
|
+
renderAt("/login/noregistered+ana+x@uni.es", { SSOActivated: true });
|
|
114
|
+
|
|
115
|
+
expect(screen.getByText(/The email ana\+x@uni\.es isn't registered/)).toBeInTheDocument();
|
|
116
|
+
expect(actions.login).not.toHaveBeenCalled();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("AC6 (borde) · código desconocido: canje normal con petitionId y sin mensaje de SSO", async () => {
|
|
120
|
+
renderAt("/login/abc123", { SSOActivated: true });
|
|
121
|
+
|
|
122
|
+
await waitFor(() => expect(actions.login).toHaveBeenCalledExactlyOnceWith({ petitionId: "abc123" }));
|
|
123
|
+
expect(screen.queryByText(/No email found in token/)).toBeNull();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -10,6 +10,15 @@ vi.mock("@ax/containers/Redirects", () => ({
|
|
|
10
10
|
},
|
|
11
11
|
}));
|
|
12
12
|
|
|
13
|
+
// El PageFinder (vía UrlField) pide páginas y content types al montarse. Sin
|
|
14
|
+
// mock esas promesas se resuelven tras el teardown de jsdom y rompen el run
|
|
15
|
+
// con `window is not defined` (unhandled rejection).
|
|
16
|
+
vi.mock("@ax/api", async (importOriginal) => ({
|
|
17
|
+
...(await importOriginal<typeof import("@ax/api")>()),
|
|
18
|
+
sites: { getSitePages: vi.fn().mockResolvedValue({ status: 200, data: { items: [], totalItems: 0 } }) },
|
|
19
|
+
structuredData: { getData: vi.fn().mockResolvedValue({ data: { items: [] } }) },
|
|
20
|
+
}));
|
|
21
|
+
|
|
13
22
|
import { parseTheme } from "@ax/helpers";
|
|
14
23
|
import RedirectPanel from "@ax/modules/Redirects/RedirectPanel";
|
|
15
24
|
import globalTheme from "@ax/themes/theme.json";
|
|
@@ -14,6 +14,25 @@ vi.mock("@ax/containers/Redirects", () => ({
|
|
|
14
14
|
},
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
+
// RedirectPanel monta UrlField → PageFinder, que pide páginas y tipos de contenido
|
|
18
|
+
// al montarse y hace setState al resolver. Con la API real esa petición acababa
|
|
19
|
+
// después de que vitest desmontara jsdom y reventaba con "window is not defined".
|
|
20
|
+
vi.mock("@ax/api", async (importOriginal) => {
|
|
21
|
+
const actual = (await importOriginal()) as any;
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
...actual,
|
|
25
|
+
sites: {
|
|
26
|
+
...actual.sites,
|
|
27
|
+
getSitePages: () => Promise.resolve({ status: 200, data: { items: [], totalItems: 0 } }),
|
|
28
|
+
},
|
|
29
|
+
structuredData: {
|
|
30
|
+
...actual.structuredData,
|
|
31
|
+
getData: () => Promise.resolve({ status: 200, data: { items: [] } }),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
|
|
17
36
|
import { MemoryRouter } from "react-router-dom";
|
|
18
37
|
|
|
19
38
|
import { parseTheme } from "@ax/helpers";
|
|
@@ -10,6 +10,25 @@ vi.mock("@ax/containers/Redirects", () => ({
|
|
|
10
10
|
},
|
|
11
11
|
}));
|
|
12
12
|
|
|
13
|
+
// RedirectPanel monta UrlField → PageFinder, que pide páginas y tipos de contenido
|
|
14
|
+
// al montarse y hace setState al resolver. Con la API real esa petición acababa
|
|
15
|
+
// después de que vitest desmontara jsdom y reventaba con "window is not defined".
|
|
16
|
+
vi.mock("@ax/api", async (importOriginal) => {
|
|
17
|
+
const actual = (await importOriginal()) as any;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
...actual,
|
|
21
|
+
sites: {
|
|
22
|
+
...actual.sites,
|
|
23
|
+
getSitePages: () => Promise.resolve({ status: 200, data: { items: [], totalItems: 0 } }),
|
|
24
|
+
},
|
|
25
|
+
structuredData: {
|
|
26
|
+
...actual.structuredData,
|
|
27
|
+
getData: () => Promise.resolve({ status: 200, data: { items: [] } }),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
|
|
13
32
|
import { MemoryRouter } from "react-router-dom";
|
|
14
33
|
|
|
15
34
|
import { parseTheme } from "@ax/helpers";
|
|
@@ -14,6 +14,25 @@ vi.mock("@ax/containers/Redirects", () => ({
|
|
|
14
14
|
},
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
+
// RedirectPanel monta UrlField → PageFinder, que pide páginas y tipos de contenido
|
|
18
|
+
// al montarse y hace setState al resolver. Con la API real esa petición acababa
|
|
19
|
+
// después de que vitest desmontara jsdom y reventaba con "window is not defined".
|
|
20
|
+
vi.mock("@ax/api", async (importOriginal) => {
|
|
21
|
+
const actual = (await importOriginal()) as any;
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
...actual,
|
|
25
|
+
sites: {
|
|
26
|
+
...actual.sites,
|
|
27
|
+
getSitePages: () => Promise.resolve({ status: 200, data: { items: [], totalItems: 0 } }),
|
|
28
|
+
},
|
|
29
|
+
structuredData: {
|
|
30
|
+
...actual.structuredData,
|
|
31
|
+
getData: () => Promise.resolve({ status: 200, data: { items: [] } }),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
|
|
17
36
|
import { MemoryRouter } from "react-router-dom";
|
|
18
37
|
|
|
19
38
|
import { parseTheme } from "@ax/helpers";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import { ThemeProvider } from "styled-components";
|
|
3
|
+
import "@testing-library/jest-dom";
|
|
4
|
+
|
|
5
|
+
import { parseTheme } from "@ax/helpers";
|
|
6
|
+
import SsoDeniedModule from "@ax/modules/SsoDenied";
|
|
7
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
cleanup();
|
|
11
|
+
vi.unstubAllEnvs();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe("módulo SsoDenied", () => {
|
|
15
|
+
it("enlaza «Sign in with another account» a /sso/switch-account de la API configurada", () => {
|
|
16
|
+
vi.stubEnv("GRIDDO_API_URL", "https://api.uni.es");
|
|
17
|
+
vi.spyOn(window.navigator, "language", "get").mockReturnValue("es-ES");
|
|
18
|
+
|
|
19
|
+
render(
|
|
20
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
21
|
+
<SsoDeniedModule />
|
|
22
|
+
</ThemeProvider>,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
expect(screen.getByRole("link", { name: "Sign in with another account" })).toHaveAttribute(
|
|
26
|
+
"href",
|
|
27
|
+
"https://api.uni.es/sso/switch-account",
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { matchPath } from "react-router-dom";
|
|
2
|
+
|
|
3
|
+
import publicRoutes from "@ax/routes/publicRoutes";
|
|
4
|
+
|
|
5
|
+
// Solo se comprueba la tabla de rutas: los módulos se sustituyen para no arrastrar el grafo de contenedores.
|
|
6
|
+
vi.mock("@ax/modules/CreatePass", () => ({ default: () => null }));
|
|
7
|
+
vi.mock("@ax/modules/Login", () => ({ default: () => null }));
|
|
8
|
+
vi.mock("@ax/modules/PublicPreview", () => ({ default: () => null }));
|
|
9
|
+
vi.mock("@ax/modules/ResetPass", () => ({ default: () => null }));
|
|
10
|
+
vi.mock("@ax/modules/SsoDenied", () => ({ default: () => null }));
|
|
11
|
+
|
|
12
|
+
describe("publicRoutes", () => {
|
|
13
|
+
const sso = publicRoutes.find((route) => route.path === "/sso-denied");
|
|
14
|
+
|
|
15
|
+
it("declara /sso-denied sin menú de navegación", () => {
|
|
16
|
+
expect(sso).toMatchObject({ path: "/sso-denied", hideNav: true });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("/sso-denied no la captura /login/:petitionId (se montaría Login y canjearía «sso-denied» como uuid)", () => {
|
|
20
|
+
expect(matchPath("/sso-denied", { path: "/login/:petitionId", exact: true })).toBeNull();
|
|
21
|
+
expect(matchPath("/sso-denied", { path: "/login", exact: true })).toBeNull();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("un uuid de petición sigue llegando a Login y no a la pantalla de acceso denegado", () => {
|
|
25
|
+
expect(
|
|
26
|
+
matchPath("/login/0b6f4b52-5d2a-4c7e-9a38-1c5f6a2e7d10", { path: "/login/:petitionId", exact: true }),
|
|
27
|
+
).not.toBeNull();
|
|
28
|
+
expect(matchPath("/login/0b6f4b52-5d2a-4c7e-9a38-1c5f6a2e7d10", { path: "/sso-denied", exact: true })).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("ninguna otra ruta pública coincide con /sso-denied", () => {
|
|
32
|
+
const matching = publicRoutes.filter((route) => matchPath("/sso-denied", { path: route.path, exact: true }));
|
|
33
|
+
|
|
34
|
+
expect(matching).toHaveLength(1);
|
|
35
|
+
});
|
|
36
|
+
});
|
package/src/api/global.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ICreatePasswordParams } from "@ax/types";
|
|
2
|
+
|
|
2
3
|
import { template } from "./config";
|
|
3
|
-
import { type IServiceConfig, sendRequest } from "./utils";
|
|
4
|
+
import { type IServiceConfig, sendInitialRequest, sendRequest } from "./utils";
|
|
4
5
|
|
|
5
6
|
const SERVICES: { [key: string]: IServiceConfig } = {
|
|
6
7
|
LOGIN: {
|
|
@@ -8,6 +9,14 @@ const SERVICES: { [key: string]: IServiceConfig } = {
|
|
|
8
9
|
endpoint: "/login_check",
|
|
9
10
|
method: "POST",
|
|
10
11
|
hasToken: false,
|
|
12
|
+
skipAuthRenewal: true,
|
|
13
|
+
},
|
|
14
|
+
LOGOUT: {
|
|
15
|
+
...template,
|
|
16
|
+
endpoint: "/logout",
|
|
17
|
+
method: "POST",
|
|
18
|
+
hasToken: true,
|
|
19
|
+
skipAuthRenewal: true,
|
|
11
20
|
},
|
|
12
21
|
GET_SETTINGS: {
|
|
13
22
|
...template,
|
|
@@ -32,6 +41,7 @@ const SERVICES: { [key: string]: IServiceConfig } = {
|
|
|
32
41
|
endpoint: ["/user/", "/password/init"],
|
|
33
42
|
method: "POST",
|
|
34
43
|
hasToken: true,
|
|
44
|
+
skipAuthRenewal: true,
|
|
35
45
|
},
|
|
36
46
|
};
|
|
37
47
|
|
|
@@ -76,8 +86,21 @@ const createPassword = async (userID: number, data: ICreatePasswordParams) => {
|
|
|
76
86
|
return sendRequest(SERVICES.CREATE_PASSWORD, { ...data });
|
|
77
87
|
};
|
|
78
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Cierra la sesión en la API (idempotente, 204). Acepta el acceso aunque esté caducado y/o el refresh del
|
|
91
|
+
* cuerpo; no dispara renovación (`skipAuthRenewal`) para no entrar en bucle si responde 401.
|
|
92
|
+
*/
|
|
93
|
+
const logout = async (session: { token: string; refreshToken: string | null }) => {
|
|
94
|
+
return sendInitialRequest(
|
|
95
|
+
SERVICES.LOGOUT,
|
|
96
|
+
session.token,
|
|
97
|
+
session.refreshToken ? { refreshToken: session.refreshToken } : {},
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
79
101
|
export default {
|
|
80
102
|
login,
|
|
103
|
+
logout,
|
|
81
104
|
getSettings,
|
|
82
105
|
forgotPassword,
|
|
83
106
|
resetPassword,
|