@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,169 @@
|
|
|
1
|
+
import { Provider } from "react-redux";
|
|
2
|
+
import { Router } from "react-router-dom";
|
|
3
|
+
|
|
4
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
5
|
+
import configureStore from "redux-mock-store";
|
|
6
|
+
import { ThemeProvider } from "styled-components";
|
|
7
|
+
import "@testing-library/jest-dom";
|
|
8
|
+
|
|
9
|
+
import { appInitialState } from "@ax/containers/App/reducer";
|
|
10
|
+
import { parseTheme } from "@ax/helpers";
|
|
11
|
+
import LoginModule from "@ax/modules/Login";
|
|
12
|
+
import history from "@ax/routes/history";
|
|
13
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
14
|
+
|
|
15
|
+
vi.mock("@ax/containers/App", async (importOriginal) => ({
|
|
16
|
+
...(await importOriginal<typeof import("@ax/containers/App")>()),
|
|
17
|
+
appActions: {
|
|
18
|
+
...(await importOriginal<typeof import("@ax/containers/App")>()).appActions,
|
|
19
|
+
login: () => ({ type: "test/login" }),
|
|
20
|
+
loginSSO: () => ({ type: "test/loginSSO" }),
|
|
21
|
+
resetError: () => ({ type: "test/resetError" }),
|
|
22
|
+
getGlobalSettings: () => ({ type: "test/getGlobalSettings" }),
|
|
23
|
+
setHistoryPush: () => ({ type: "test/setHistoryPush" }),
|
|
24
|
+
},
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
cleanup();
|
|
29
|
+
vi.unstubAllGlobals();
|
|
30
|
+
vi.unstubAllEnvs();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const renderModule = (globalSettings: Partial<typeof appInitialState.globalSettings>) => {
|
|
34
|
+
const store = configureStore([])({
|
|
35
|
+
app: { isLoggingIn: false, globalSettings: { ...appInitialState.globalSettings, ...globalSettings } },
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
render(
|
|
39
|
+
<Provider store={store}>
|
|
40
|
+
<Router history={history}>
|
|
41
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
42
|
+
<LoginModule />
|
|
43
|
+
</ThemeProvider>
|
|
44
|
+
</Router>
|
|
45
|
+
</Provider>,
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
describe("módulo Login con auth.griddo.io", () => {
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
vi.stubEnv("GRIDDO_API_URL", "https://api.uni.es");
|
|
52
|
+
vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("«Entrar con Griddo» navega a /sso/start de la API configurada, una sola vez con doble clic", () => {
|
|
56
|
+
const assign = vi.fn();
|
|
57
|
+
|
|
58
|
+
vi.stubGlobal("location", { ...window.location, assign });
|
|
59
|
+
renderModule({ GriddoIdEnabled: true });
|
|
60
|
+
|
|
61
|
+
const button = screen.getByRole("button", { name: "Sign in with Griddo" });
|
|
62
|
+
|
|
63
|
+
fireEvent.click(button);
|
|
64
|
+
fireEvent.click(button);
|
|
65
|
+
|
|
66
|
+
expect(assign).toHaveBeenCalledTimes(1);
|
|
67
|
+
expect(assign).toHaveBeenCalledWith("https://api.uni.es/sso/start");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const openForm = () => fireEvent.click(screen.getByRole("button", { name: "Login with email and password" }));
|
|
71
|
+
|
|
72
|
+
const typeEmail = (value: string) => {
|
|
73
|
+
openForm();
|
|
74
|
+
fireEvent.change(screen.getByPlaceholderText("Type your email"), { target: { value } });
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const clickGriddoId = () => {
|
|
78
|
+
const assign = vi.fn();
|
|
79
|
+
|
|
80
|
+
vi.stubGlobal("location", { ...window.location, assign });
|
|
81
|
+
renderModule({ GriddoIdEnabled: true });
|
|
82
|
+
|
|
83
|
+
return { assign, button: screen.getByRole("button", { name: "Sign in with Griddo" }) };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
it("envía el email escrito como login_hint, recortado y codificado", () => {
|
|
87
|
+
const { assign, button } = clickGriddoId();
|
|
88
|
+
|
|
89
|
+
typeEmail(" ana+x@uni.es ");
|
|
90
|
+
fireEvent.click(button);
|
|
91
|
+
|
|
92
|
+
expect(assign).toHaveBeenCalledWith("https://api.uni.es/sso/start?login_hint=ana%2Bx%40uni.es");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("con el campo vacío o sin arroba navega sin query", () => {
|
|
96
|
+
for (const typed of ["", "ana"]) {
|
|
97
|
+
const { assign, button } = clickGriddoId();
|
|
98
|
+
|
|
99
|
+
typeEmail(typed);
|
|
100
|
+
fireEvent.click(button);
|
|
101
|
+
|
|
102
|
+
expect(assign).toHaveBeenCalledWith("https://api.uni.es/sso/start");
|
|
103
|
+
cleanup();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("la contraseña no viaja en la URL", () => {
|
|
108
|
+
const { assign, button } = clickGriddoId();
|
|
109
|
+
const password = document.querySelector<HTMLInputElement>('input[name="password"]') as HTMLInputElement;
|
|
110
|
+
|
|
111
|
+
typeEmail("ana@uni.es");
|
|
112
|
+
fireEvent.change(password, { target: { value: "s3cr3t-pass" } });
|
|
113
|
+
fireEvent.click(button);
|
|
114
|
+
|
|
115
|
+
const url = assign.mock.calls[0][0] as string;
|
|
116
|
+
|
|
117
|
+
expect(url).toBe("https://api.uni.es/sso/start?login_hint=ana%40uni.es");
|
|
118
|
+
expect(url).not.toContain("s3cr3t");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("con email escrito, un doble clic navega una sola vez", () => {
|
|
122
|
+
const { assign, button } = clickGriddoId();
|
|
123
|
+
|
|
124
|
+
typeEmail("ana@uni.es");
|
|
125
|
+
fireEvent.click(button);
|
|
126
|
+
fireEvent.click(button);
|
|
127
|
+
|
|
128
|
+
expect(assign).toHaveBeenCalledTimes(1);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("sin GRIDDO_API_URL el destino cuelga de REACT_APP_API_ENDPOINT", () => {
|
|
132
|
+
vi.stubEnv("GRIDDO_API_URL", "");
|
|
133
|
+
vi.stubEnv("REACT_APP_API_ENDPOINT", "https://fallback.uni.es");
|
|
134
|
+
const { assign, button } = clickGriddoId();
|
|
135
|
+
|
|
136
|
+
typeEmail("ana@uni.es");
|
|
137
|
+
fireEvent.click(button);
|
|
138
|
+
|
|
139
|
+
expect(assign).toHaveBeenCalledWith("https://fallback.uni.es/sso/start?login_hint=ana%40uni.es");
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("con el flag activo el formulario está plegado bajo el botón hasta pulsar el desplegable", () => {
|
|
143
|
+
renderModule({ GriddoIdEnabled: true });
|
|
144
|
+
|
|
145
|
+
expect(screen.getByPlaceholderText("Type your email")).not.toBeVisible();
|
|
146
|
+
openForm();
|
|
147
|
+
expect(screen.getByPlaceholderText("Type your email")).toBeVisible();
|
|
148
|
+
expect(screen.getByRole("button", { name: "Sign in with Griddo" })).toBeInTheDocument();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("con el flag activo muestra el logo «griddo dxp» arriba a la izquierda", () => {
|
|
152
|
+
renderModule({ GriddoIdEnabled: true });
|
|
153
|
+
|
|
154
|
+
expect(screen.getByAltText("Griddo DXP")).toHaveAttribute("src", "/img/logos/logoGriddoDxp.svg");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("con el flag apagado no muestra el logo «griddo dxp»: ese login ya lleva su «Welcome to»", () => {
|
|
158
|
+
renderModule({ GriddoIdEnabled: false });
|
|
159
|
+
|
|
160
|
+
expect(screen.queryByAltText("Griddo DXP")).toBeNull();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("con el flag apagado (o sin settings) muestra el formulario de siempre", () => {
|
|
164
|
+
renderModule({ GriddoIdEnabled: false });
|
|
165
|
+
|
|
166
|
+
expect(screen.queryByText("Sign in with Griddo")).toBeNull();
|
|
167
|
+
expect(screen.getByPlaceholderText("Type your email")).toBeInTheDocument();
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -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";
|