@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,373 @@
|
|
|
1
|
+
import { SET_ERROR } from "@ax/containers/App/constants";
|
|
2
|
+
|
|
3
|
+
import type { Mock } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { registerSessionBridge, resetSessionState, setSession } from "../../api/session";
|
|
6
|
+
import utils, {
|
|
7
|
+
getToken,
|
|
8
|
+
handleResponse,
|
|
9
|
+
type IServiceConfig,
|
|
10
|
+
sendInitialRequest,
|
|
11
|
+
sendRequest,
|
|
12
|
+
sendUploadRequest,
|
|
13
|
+
} from "../../api/utils";
|
|
14
|
+
import { setStore } from "../../storeRegistry";
|
|
15
|
+
|
|
16
|
+
// Mock compartido con el módulo de renovación (mismo `axios` en toda la cadena).
|
|
17
|
+
const mockedAxios = vi.hoisted(() => vi.fn());
|
|
18
|
+
vi.mock("axios", () => ({ default: mockedAxios }));
|
|
19
|
+
|
|
20
|
+
const httpError = (status: number | undefined) =>
|
|
21
|
+
Object.assign(
|
|
22
|
+
new Error(`HTTP ${status}`),
|
|
23
|
+
status === undefined ? {} : { response: { status, data: { code: status } } },
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const service = (extra: Partial<IServiceConfig> = {}): IServiceConfig => ({
|
|
27
|
+
host: "http://api",
|
|
28
|
+
endpoint: "/pages",
|
|
29
|
+
method: "GET",
|
|
30
|
+
headers: { "Content-type": "application/json", accept: "application/json" },
|
|
31
|
+
hasToken: true,
|
|
32
|
+
dynamicUrl: "",
|
|
33
|
+
...extra,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** Las peticiones con el token viejo dan 401; con el nuevo, 200. La renovación devuelve el par nuevo. */
|
|
37
|
+
const stage = () => {
|
|
38
|
+
mockedAxios.mockImplementation(async (config: any) => {
|
|
39
|
+
if (String(config.url).endsWith("/login_refresh"))
|
|
40
|
+
return { status: 200, data: { token: "new", refreshToken: "r-new" } };
|
|
41
|
+
if (config.headers?.Authorization === "bearer old") throw httpError(401);
|
|
42
|
+
return { status: 200, data: { ok: config.headers?.Authorization } };
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const refreshCalls = () => mockedAxios.mock.calls.filter(([c]: any[]) => String(c.url).endsWith("/login_refresh"));
|
|
47
|
+
|
|
48
|
+
let onExpired: Mock<() => void>;
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
localStorage.clear();
|
|
52
|
+
resetSessionState();
|
|
53
|
+
onExpired = vi.fn();
|
|
54
|
+
registerSessionBridge({ onExpired });
|
|
55
|
+
setSession("old", "r-old");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("getToken", () => {
|
|
59
|
+
it("devuelve la cabecera con el token de la sesión vigente", () => {
|
|
60
|
+
expect(getToken()).toEqual({ Authorization: "bearer old" });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("sin sesión devuelve null", () => {
|
|
64
|
+
resetSessionState();
|
|
65
|
+
expect(getToken()).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("las tres vías de petición renuevan y reintentan ante 401", () => {
|
|
70
|
+
it("sendRequest", async () => {
|
|
71
|
+
stage();
|
|
72
|
+
const response = await sendRequest(service());
|
|
73
|
+
expect(response.status).toBe(200);
|
|
74
|
+
expect(response.data).toEqual({ ok: "bearer new" });
|
|
75
|
+
expect(refreshCalls()).toHaveLength(1);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("sendRequest con cuerpo (POST) conserva los datos al reintentar", async () => {
|
|
79
|
+
stage();
|
|
80
|
+
await sendRequest(service({ method: "POST" }), { a: 1 });
|
|
81
|
+
const retry = mockedAxios.mock.calls.at(-1)?.[0] as any;
|
|
82
|
+
expect(retry.data).toEqual({ a: 1 });
|
|
83
|
+
expect(retry.headers.Authorization).toBe("bearer new");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("sendInitialRequest (token explícito)", async () => {
|
|
87
|
+
stage();
|
|
88
|
+
const response = await sendInitialRequest(service(), "old");
|
|
89
|
+
expect(response.data).toEqual({ ok: "bearer new" });
|
|
90
|
+
expect(refreshCalls()).toHaveLength(1);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("sendInitialRequest con PUT envía los datos también en el reintento", async () => {
|
|
94
|
+
stage();
|
|
95
|
+
await sendInitialRequest(service({ method: "PUT" }), "old", { x: 2 });
|
|
96
|
+
const retry = mockedAxios.mock.calls.at(-1)?.[0] as any;
|
|
97
|
+
expect(retry.data).toEqual({ x: 2 });
|
|
98
|
+
expect(retry.headers.Authorization).toBe("bearer new");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("sendUploadRequest conserva el FormData al reintentar", async () => {
|
|
102
|
+
stage();
|
|
103
|
+
const form = new FormData();
|
|
104
|
+
form.append("file", new File(["x"], "a.txt"));
|
|
105
|
+
const response = await sendUploadRequest(service({ method: "POST" }), form);
|
|
106
|
+
expect(response.status).toBe(200);
|
|
107
|
+
expect((mockedAxios.mock.calls[mockedAxios.mock.calls.length - 1][0] as any).data).toBe(form);
|
|
108
|
+
expect(refreshCalls()).toHaveLength(1);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe("sin renovación posible", () => {
|
|
113
|
+
it("devuelve la respuesta 401 original al llamante (como antes) y cierra la sesión una vez", async () => {
|
|
114
|
+
mockedAxios.mockImplementation(async () => {
|
|
115
|
+
throw httpError(401);
|
|
116
|
+
});
|
|
117
|
+
setSession("old", null);
|
|
118
|
+
|
|
119
|
+
const response = await sendRequest(service());
|
|
120
|
+
|
|
121
|
+
expect(response.status).toBe(401);
|
|
122
|
+
expect(onExpired).toHaveBeenCalledTimes(1);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("un servicio con skipAuthRenewal (login, password/init, logout) no renueva ni cierra", async () => {
|
|
126
|
+
mockedAxios.mockImplementation(async () => {
|
|
127
|
+
throw httpError(401);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const response = await sendRequest(service({ skipAuthRenewal: true }));
|
|
131
|
+
const initial = await sendInitialRequest(service({ skipAuthRenewal: true }), "old");
|
|
132
|
+
const upload = await sendUploadRequest(service({ skipAuthRenewal: true, method: "POST" }), new FormData());
|
|
133
|
+
|
|
134
|
+
expect([response.status, initial.status, upload.status]).toEqual([401, 401, 401]);
|
|
135
|
+
expect(refreshCalls()).toHaveLength(0);
|
|
136
|
+
expect(onExpired).not.toHaveBeenCalled();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("una petición sin token (hasToken false) con 401 es un error normal", async () => {
|
|
140
|
+
mockedAxios.mockImplementation(async () => {
|
|
141
|
+
throw httpError(401);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const response = await sendRequest(service({ hasToken: false }));
|
|
145
|
+
|
|
146
|
+
expect(response.status).toBe(401);
|
|
147
|
+
expect(refreshCalls()).toHaveLength(0);
|
|
148
|
+
expect(onExpired).not.toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it.each([403, 404, 500])("%s llega al llamante sin tocar la sesión", async (status) => {
|
|
152
|
+
mockedAxios.mockImplementation(async () => {
|
|
153
|
+
throw httpError(status);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const response = await sendRequest(service());
|
|
157
|
+
|
|
158
|
+
expect(response.status).toBe(status);
|
|
159
|
+
expect(refreshCalls()).toHaveLength(0);
|
|
160
|
+
expect(onExpired).not.toHaveBeenCalled();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("la red caída sigue devolviendo undefined como antes", async () => {
|
|
164
|
+
mockedAxios.mockImplementation(async () => {
|
|
165
|
+
throw Object.assign(new Error("Network Error"), {});
|
|
166
|
+
});
|
|
167
|
+
expect(await sendRequest(service())).toBeUndefined();
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe("compatibilidad con la API actual", () => {
|
|
172
|
+
it("si nunca responde 401 funciona igual que antes", async () => {
|
|
173
|
+
setSession("legacy", null);
|
|
174
|
+
mockedAxios.mockResolvedValue({ status: 200, data: { fine: true } });
|
|
175
|
+
|
|
176
|
+
const response = await sendRequest(service());
|
|
177
|
+
|
|
178
|
+
expect(response.data).toEqual({ fine: true });
|
|
179
|
+
expect(mockedAxios).toHaveBeenCalledTimes(1);
|
|
180
|
+
expect((mockedAxios.mock.calls[0][0] as any).headers.Authorization).toBe("bearer legacy");
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("peticiones fuera del interceptor", () => {
|
|
185
|
+
it("una llamada directa a axios con 401 no renueva (comportamiento documentado)", async () => {
|
|
186
|
+
const { default: axios } = await import("axios");
|
|
187
|
+
mockedAxios.mockRejectedValue(httpError(401));
|
|
188
|
+
|
|
189
|
+
await expect(axios({ url: "http://api/x", headers: { Authorization: "bearer old" } })).rejects.toMatchObject({
|
|
190
|
+
response: { status: 401 },
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
expect(refreshCalls()).toHaveLength(0);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const lastConfig = () => mockedAxios.mock.calls[mockedAxios.mock.calls.length - 1][0] as any;
|
|
198
|
+
|
|
199
|
+
describe("cabeceras y URL de las peticiones", () => {
|
|
200
|
+
beforeEach(() => {
|
|
201
|
+
mockedAxios.mockResolvedValue({ status: 200, data: {} });
|
|
202
|
+
setStore(null);
|
|
203
|
+
sessionStorage.clear();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("usa host + endpoint, o dynamicUrl si existe, con método y responseType", async () => {
|
|
207
|
+
await sendRequest(service({ responseType: "blob" }));
|
|
208
|
+
expect(lastConfig()).toMatchObject({ url: "http://api/pages", method: "GET", responseType: "blob" });
|
|
209
|
+
|
|
210
|
+
await sendRequest(service({ dynamicUrl: "http://api/custom?x=1" }));
|
|
211
|
+
expect(lastConfig().url).toBe("http://api/custom?x=1");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("incluye el token solo si el servicio lo pide", async () => {
|
|
215
|
+
await sendRequest(service({ hasToken: true }));
|
|
216
|
+
expect(lastConfig().headers.Authorization).toBe("bearer old");
|
|
217
|
+
|
|
218
|
+
await sendRequest(service({ hasToken: false }));
|
|
219
|
+
expect(lastConfig().headers.Authorization).toBeUndefined();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("lang y site salen del store si existe", async () => {
|
|
223
|
+
setStore({ getState: () => ({ app: { lang: { id: 9 } }, sites: { currentSiteInfo: { id: 5 } } }) });
|
|
224
|
+
|
|
225
|
+
await sendRequest(service());
|
|
226
|
+
|
|
227
|
+
expect(lastConfig().headers).toMatchObject({ lang: 9, site: 5 });
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("con store pero sin idioma o site, lang y site son null", async () => {
|
|
231
|
+
setStore({ getState: () => ({}) });
|
|
232
|
+
|
|
233
|
+
await sendRequest(service());
|
|
234
|
+
|
|
235
|
+
expect(lastConfig().headers).toMatchObject({ lang: null, site: null });
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("con store que devuelve undefined no revienta", async () => {
|
|
239
|
+
setStore({ getState: () => undefined });
|
|
240
|
+
|
|
241
|
+
await sendRequest(service());
|
|
242
|
+
|
|
243
|
+
expect(lastConfig().headers).toMatchObject({ lang: null, site: null });
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("sin store lee langID y siteID de localStorage", async () => {
|
|
247
|
+
localStorage.setItem("langID", "3");
|
|
248
|
+
localStorage.setItem("siteID", "8");
|
|
249
|
+
|
|
250
|
+
await sendRequest(service());
|
|
251
|
+
|
|
252
|
+
expect(lastConfig().headers).toMatchObject({ lang: 3, site: 8 });
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("sin store ni localStorage envía objetos vacíos", async () => {
|
|
256
|
+
await sendRequest(service());
|
|
257
|
+
|
|
258
|
+
expect(lastConfig().headers).toMatchObject({ lang: {}, site: {} });
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("añade las cabeceras de previsualización solo si hay página y entidad", async () => {
|
|
262
|
+
sessionStorage.setItem("previewPageId", "12");
|
|
263
|
+
sessionStorage.setItem("previewEntity", "page");
|
|
264
|
+
await sendRequest(service());
|
|
265
|
+
expect(lastConfig().headers).toMatchObject({ "x-preview-share-page-id": "12", "x-preview-share-entity": "page" });
|
|
266
|
+
|
|
267
|
+
await sendRequest(service({ hasToken: false }));
|
|
268
|
+
expect(lastConfig().headers).toMatchObject({ "x-preview-share-page-id": "12", "x-preview-share-entity": "page" });
|
|
269
|
+
|
|
270
|
+
sessionStorage.removeItem("previewEntity");
|
|
271
|
+
await sendRequest(service());
|
|
272
|
+
expect(lastConfig().headers["x-preview-share-page-id"]).toBeUndefined();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("sendRequest: dataHeader se funde con las cabeceras y los datos solo viajan si no es GET", async () => {
|
|
276
|
+
await sendRequest(service({ method: "POST" }), { a: 1 }, { "x-custom": "v" });
|
|
277
|
+
expect(lastConfig().headers["x-custom"]).toBe("v");
|
|
278
|
+
expect(lastConfig().headers.Authorization).toBe("bearer old");
|
|
279
|
+
expect(lastConfig().data).toEqual({ a: 1 });
|
|
280
|
+
|
|
281
|
+
await sendRequest(service(), { a: 1 });
|
|
282
|
+
expect(lastConfig().data).toBeUndefined();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("sendInitialRequest: token explícito, datos solo en PUT y POST", async () => {
|
|
286
|
+
await sendInitialRequest(service({ method: "GET" }), "tk", { z: 1 });
|
|
287
|
+
expect(lastConfig().headers.Authorization).toBe("bearer tk");
|
|
288
|
+
expect(lastConfig().data).toBeUndefined();
|
|
289
|
+
|
|
290
|
+
await sendInitialRequest(service({ method: "DELETE" }), "tk", { z: 1 });
|
|
291
|
+
expect(lastConfig().data).toBeUndefined();
|
|
292
|
+
|
|
293
|
+
await sendInitialRequest(service({ method: "POST", dynamicUrl: "http://api/dyn" }), "tk", { z: 1 });
|
|
294
|
+
expect(lastConfig()).toMatchObject({ url: "http://api/dyn", data: { z: 1 } });
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("sendUploadRequest: el progreso se informa en porcentaje y solo si se pide", async () => {
|
|
298
|
+
const setProgress = vi.fn();
|
|
299
|
+
await sendUploadRequest(service({ method: "POST" }), new FormData(), setProgress);
|
|
300
|
+
lastConfig().onUploadProgress({ loaded: 50, total: 200 });
|
|
301
|
+
expect(setProgress).toHaveBeenCalledTimes(1);
|
|
302
|
+
expect(setProgress).toHaveBeenCalledWith(25);
|
|
303
|
+
|
|
304
|
+
await sendUploadRequest(service({ method: "POST" }), new FormData());
|
|
305
|
+
expect(lastConfig().onUploadProgress).toBeUndefined();
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe("errores sin respuesta de la API", () => {
|
|
310
|
+
const platformError = (extra: Record<string, unknown> = {}) => Object.assign(new Error("boom"), extra);
|
|
311
|
+
|
|
312
|
+
it.each([
|
|
313
|
+
["sendRequest", () => sendRequest(service())],
|
|
314
|
+
["sendInitialRequest", () => sendInitialRequest(service(), "old")],
|
|
315
|
+
["sendUploadRequest", () => sendUploadRequest(service({ method: "POST" }), new FormData())],
|
|
316
|
+
])("%s devuelve un error de plataforma con código y mensaje", async (_n, call) => {
|
|
317
|
+
mockedAxios.mockRejectedValue(platformError({ code: "ECONNABORTED", status: 0 }));
|
|
318
|
+
|
|
319
|
+
expect(await call()).toEqual({ status: 0, data: { code: "ECONNABORTED", message: "boom" } });
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it.each([
|
|
323
|
+
["sendRequest", () => sendRequest(service())],
|
|
324
|
+
["sendInitialRequest", () => sendInitialRequest(service(), "old")],
|
|
325
|
+
["sendUploadRequest", () => sendUploadRequest(service({ method: "POST" }), new FormData())],
|
|
326
|
+
])("%s usa valores por defecto si el error no trae código ni mensaje", async (_n, call) => {
|
|
327
|
+
mockedAxios.mockRejectedValue({});
|
|
328
|
+
|
|
329
|
+
expect(await call()).toEqual({ status: undefined, data: { code: "unknown", message: "Platform error" } });
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("Network Error devuelve la respuesta (undefined) en las tres vías", async () => {
|
|
333
|
+
mockedAxios.mockRejectedValue(new Error("Network Error"));
|
|
334
|
+
|
|
335
|
+
expect(await sendInitialRequest(service(), "old")).toBeUndefined();
|
|
336
|
+
expect(await sendUploadRequest(service({ method: "POST" }), new FormData())).toBeUndefined();
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
describe("handleResponse", () => {
|
|
341
|
+
it.each([
|
|
342
|
+
[199, false],
|
|
343
|
+
[200, true],
|
|
344
|
+
[399, true],
|
|
345
|
+
[400, false],
|
|
346
|
+
])("isSuccessful(%s) = %s", (status, expected) => {
|
|
347
|
+
expect(utils.isSuccessful(status)).toBe(expected);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("una respuesta correcta pasa sus datos al successHandler", () => {
|
|
351
|
+
const successHandler = vi.fn().mockReturnValue({ ok: true });
|
|
352
|
+
|
|
353
|
+
expect(handleResponse({ status: 200, data: { a: 1 } } as any, successHandler)).toEqual({ ok: true });
|
|
354
|
+
expect(successHandler).toHaveBeenCalledWith({ a: 1 });
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("un error usa el handler propio con el status", () => {
|
|
358
|
+
const customErrorHandler = vi.fn().mockReturnValue({ custom: true });
|
|
359
|
+
|
|
360
|
+
expect(handleResponse({ status: 404, data: {} } as any, vi.fn(), customErrorHandler)).toEqual({ custom: true });
|
|
361
|
+
expect(customErrorHandler).toHaveBeenCalledWith(404);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("un error sin handler propio devuelve la acción de error genérica", () => {
|
|
365
|
+
const successHandler = vi.fn();
|
|
366
|
+
|
|
367
|
+
expect(handleResponse({ status: 500, data: {} } as any, successHandler)).toEqual({
|
|
368
|
+
type: SET_ERROR,
|
|
369
|
+
payload: { errorType: 500, errorText: "This is a generic error" },
|
|
370
|
+
});
|
|
371
|
+
expect(successHandler).not.toHaveBeenCalled();
|
|
372
|
+
});
|
|
373
|
+
});
|
|
@@ -1,18 +1,43 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import FileField, { type IFileFieldProps } from "@ax/components/Fields/FileField";
|
|
3
4
|
import { parseTheme } from "@ax/helpers";
|
|
4
5
|
import globalTheme from "@ax/themes/theme.json";
|
|
5
|
-
|
|
6
|
-
import { render, screen, cleanup } from "../../../../../config/tests/test-utils";
|
|
7
|
-
import FileField, { type IFileFieldProps } from "@ax/components/Fields/FileField";
|
|
6
|
+
|
|
8
7
|
import { act } from "react-dom/test-utils";
|
|
9
|
-
import thunk from "redux-thunk";
|
|
10
8
|
import configureStore from "redux-mock-store";
|
|
9
|
+
import thunk from "redux-thunk";
|
|
10
|
+
import { ThemeProvider } from "styled-components";
|
|
11
|
+
import { mock } from "vitest-mock-extended";
|
|
11
12
|
|
|
13
|
+
import { cleanup, render, screen } from "../../../../../config/tests/test-utils";
|
|
12
14
|
import { defaultStore } from "./../../../../__mocks__/store/GenericStore";
|
|
13
15
|
|
|
16
|
+
// FileGallery pide la carpeta y el árbol al montarse y, al resolver, hace
|
|
17
|
+
// `setIsLoading(false)`. Con la API real esa petición acababa después de que
|
|
18
|
+
// vitest desmontara jsdom y reventaba con "window is not defined" (flaky en CI).
|
|
19
|
+
vi.mock("@ax/api", async (importOriginal) => {
|
|
20
|
+
const actual = (await importOriginal()) as any;
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
...actual,
|
|
24
|
+
files: {
|
|
25
|
+
...actual.files,
|
|
26
|
+
getFolderContent: () => Promise.resolve({ status: 200, data: { folders: [], files: [] } }),
|
|
27
|
+
getFoldersTree: () => Promise.resolve({ status: 200, data: [] }),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
|
|
14
32
|
afterEach(cleanup);
|
|
15
33
|
|
|
34
|
+
// Deja que se asienten las peticiones simuladas del FileGallery antes de que
|
|
35
|
+
// acabe el test: un macrotask vacía toda la cadena de promesas ya resueltas.
|
|
36
|
+
const flushRequests = () =>
|
|
37
|
+
act(async () => {
|
|
38
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
39
|
+
});
|
|
40
|
+
|
|
16
41
|
// Props por test. Antes se compartía un objeto mutable: el segundo test dejaba
|
|
17
42
|
// `value` en undefined y los dos de "onClick events" contaban con eso sin
|
|
18
43
|
// decirlo, así que al reordenarlos se caían.
|
|
@@ -70,7 +95,7 @@ describe("FileField component rendering", () => {
|
|
|
70
95
|
});
|
|
71
96
|
|
|
72
97
|
describe("onClick events", () => {
|
|
73
|
-
it("should open FileDragAndDrop when clicking the file button", () => {
|
|
98
|
+
it("should open FileDragAndDrop when clicking the file button", async () => {
|
|
74
99
|
const Component = (
|
|
75
100
|
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
76
101
|
<FileField {...makeProps({ value: undefined })} />
|
|
@@ -84,6 +109,8 @@ describe("onClick events", () => {
|
|
|
84
109
|
|
|
85
110
|
rerender(Component);
|
|
86
111
|
|
|
112
|
+
await flushRequests();
|
|
113
|
+
|
|
87
114
|
const fileDragAndDropWrapper = screen.queryByTestId("file-drag-and-drop-wrapper");
|
|
88
115
|
expect(fileDragAndDropWrapper).toBeTruthy();
|
|
89
116
|
});
|
|
@@ -3,7 +3,7 @@ import "@testing-library/jest-dom";
|
|
|
3
3
|
|
|
4
4
|
import FieldsBehavior from "@ax/components/FieldsBehavior";
|
|
5
5
|
import { getValidity } from "@ax/forms";
|
|
6
|
-
import {
|
|
6
|
+
import { isEmptyContainer, parseTheme, slugify } from "@ax/helpers";
|
|
7
7
|
import globalTheme from "@ax/themes/theme.json";
|
|
8
8
|
|
|
9
9
|
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
@@ -15,13 +15,15 @@ vi.mock("@ax/forms", async () => ({
|
|
|
15
15
|
}));
|
|
16
16
|
vi.mock("@ax/helpers", async () => ({
|
|
17
17
|
...(await vi.importActual("@ax/helpers")),
|
|
18
|
-
getFieldByPath: vi.fn(() => () => <div data-testid="mock-field" />),
|
|
19
18
|
isEmptyContainer: vi.fn(() => ({ isEmpty: false })),
|
|
20
19
|
slugify: vi.fn((text: string) => (text || "").toLowerCase().replace(/\s+/g, "-")),
|
|
21
20
|
}));
|
|
22
21
|
|
|
22
|
+
vi.mock("@ax/components/FieldsBehavior/getFieldByPath", () => ({
|
|
23
|
+
getFieldByPath: vi.fn(() => () => <div data-testid="mock-field" />),
|
|
24
|
+
}));
|
|
25
|
+
|
|
23
26
|
const mockGetValidity = getValidity as MockedFunction<typeof getValidity>;
|
|
24
|
-
const _mockGetFieldByPath = getFieldByPath as MockedFunction<typeof getFieldByPath>;
|
|
25
27
|
const mockIsEmptyContainer = isEmptyContainer as MockedFunction<typeof isEmptyContainer>;
|
|
26
28
|
const mockSlugify = slugify as MockedFunction<typeof slugify>;
|
|
27
29
|
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { MemoryRouter } from "react-router-dom";
|
|
2
|
+
|
|
3
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import { ThemeProvider } from "styled-components";
|
|
5
|
+
import "@testing-library/jest-dom";
|
|
6
|
+
|
|
7
|
+
import ErrorPage from "@ax/components/ErrorPage";
|
|
8
|
+
import Login, { type ILoginProps } from "@ax/components/Login";
|
|
9
|
+
import SsoDenied from "@ax/components/SsoDenied";
|
|
10
|
+
import { parseTheme } from "@ax/helpers";
|
|
11
|
+
import { BRAND_PALETTE } from "@ax/themes/brandPalette";
|
|
12
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
13
|
+
|
|
14
|
+
afterEach(cleanup);
|
|
15
|
+
|
|
16
|
+
const settings = {
|
|
17
|
+
cloudinaryName: "cloudinary",
|
|
18
|
+
globalLogoBig: "https://images.dev.griddo.io/big",
|
|
19
|
+
globalLogoMini: "https://images.dev.griddo.io/mini",
|
|
20
|
+
siteLogoBig: "https://images.dev.griddo.io/sbig",
|
|
21
|
+
siteLogoMini: "https://images.dev.griddo.io/smini",
|
|
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 loginProps = (overrides: Partial<ILoginProps["settings"]> = {}): ILoginProps => ({
|
|
33
|
+
handleSubmit: vi.fn((e) => e.preventDefault()),
|
|
34
|
+
email: "",
|
|
35
|
+
handleEmail: vi.fn(),
|
|
36
|
+
password: "",
|
|
37
|
+
handlePassword: vi.fn(),
|
|
38
|
+
isLoggingIn: false,
|
|
39
|
+
settings: { ...settings, ...overrides },
|
|
40
|
+
rememberMe: false,
|
|
41
|
+
handleRememberMe: vi.fn(),
|
|
42
|
+
handleGriddoId: vi.fn(),
|
|
43
|
+
isLoginSuccess: false,
|
|
44
|
+
handleLoginSuccess: vi.fn(),
|
|
45
|
+
handleSSO: vi.fn(),
|
|
46
|
+
errorSSO: "",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const theme = parseTheme(globalTheme);
|
|
50
|
+
|
|
51
|
+
const renderLogin = (overrides: Partial<ILoginProps["settings"]> = {}) =>
|
|
52
|
+
render(
|
|
53
|
+
<ThemeProvider theme={theme}>
|
|
54
|
+
<Login {...loginProps(overrides)} />
|
|
55
|
+
</ThemeProvider>,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const circles = () => screen.getAllByTestId("circle");
|
|
59
|
+
|
|
60
|
+
describe("[UC-AX-sign-in-out] paleta de marca: constantes", () => {
|
|
61
|
+
it("AC13 · expone los tonos de marca", () => {
|
|
62
|
+
expect(BRAND_PALETTE.navy).toBe("#001B3C");
|
|
63
|
+
expect(BRAND_PALETTE.navyControl).toBe("#022958");
|
|
64
|
+
expect(BRAND_PALETTE.cyan).toBe("#3CC3DD");
|
|
65
|
+
expect(BRAND_PALETTE.purple).toBe("#A950CF");
|
|
66
|
+
expect(BRAND_PALETTE.turquoise).toBe("#40E0D0");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("[UC-AX-sign-in-out] Login: paleta de marca", () => {
|
|
71
|
+
it("AC13 · columna izquierda con el azul de marca", () => {
|
|
72
|
+
renderLogin();
|
|
73
|
+
expect(screen.getByTestId("login-left")).toHaveStyle({ background: "#001B3C" });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("AC13 · blur cyan en lugar del amarillo, con blur 50px (el 100 de Figma) y opacidad .5", () => {
|
|
77
|
+
const { container } = renderLogin();
|
|
78
|
+
const backgrounds = circles().map((c) => getComputedStyle(c).backgroundColor);
|
|
79
|
+
expect(backgrounds).toContain("rgb(60, 195, 221)");
|
|
80
|
+
expect(container.innerHTML).not.toMatch(/FBE15C/i);
|
|
81
|
+
for (const c of circles()) {
|
|
82
|
+
expect(c).toHaveStyle({ filter: "blur(50px)", opacity: "0.5" });
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("AC13 · el halo de marca es turquesa, queda por debajo del contenido y no captura clics", () => {
|
|
87
|
+
renderLogin({ GriddoIdEnabled: true });
|
|
88
|
+
const halo = screen.getByTestId("login-halo");
|
|
89
|
+
expect(halo).toHaveStyle({ pointerEvents: "none", zIndex: "0", backgroundColor: "#40E0D0" });
|
|
90
|
+
expect(halo.parentElement).toBe(screen.getByTestId("login-left"));
|
|
91
|
+
expect(screen.getByTestId("login-left")).toHaveStyle({ overflow: "hidden" });
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("AC13 · el clic llega al botón SSO pese al halo", () => {
|
|
95
|
+
const props = loginProps({ GriddoIdEnabled: true });
|
|
96
|
+
render(
|
|
97
|
+
<ThemeProvider theme={theme}>
|
|
98
|
+
<Login {...props} />
|
|
99
|
+
</ThemeProvider>,
|
|
100
|
+
);
|
|
101
|
+
fireEvent.click(screen.getByRole("button", { name: /sign in with griddo/i }));
|
|
102
|
+
expect(props.handleGriddoId).toHaveBeenCalledTimes(1);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it.each([
|
|
106
|
+
["Griddo ID", { GriddoIdEnabled: true }],
|
|
107
|
+
["normal", {}],
|
|
108
|
+
["Comillas", { SSOActivated: true }],
|
|
109
|
+
])("AC13 · variante %s usa la paleta", (_n, overrides) => {
|
|
110
|
+
renderLogin(overrides);
|
|
111
|
+
expect(screen.getByTestId("login-left")).toHaveStyle({ background: "#001B3C" });
|
|
112
|
+
expect(circles().map((c) => getComputedStyle(c).backgroundColor)).toContain("rgb(60, 195, 221)");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("AC13 · el halo y el logo no quedan huérfanos en la animación de éxito: viven dentro de la columna que se expande", () => {
|
|
116
|
+
renderLogin({ GriddoIdEnabled: true });
|
|
117
|
+
const left = screen.getByTestId("login-left");
|
|
118
|
+
expect(left).toContainElement(screen.getByTestId("login-halo"));
|
|
119
|
+
expect(left).toContainElement(screen.getByAltText("Griddo DXP"));
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("[UC-AX-sign-in-out] pantallas que comparten estilos", () => {
|
|
124
|
+
it("AC13 · SsoDenied usa el fondo y el círculo de marca", () => {
|
|
125
|
+
render(
|
|
126
|
+
<ThemeProvider theme={theme}>
|
|
127
|
+
<SsoDenied switchAccountUrl="https://api/sso/switch-account" />
|
|
128
|
+
</ThemeProvider>,
|
|
129
|
+
);
|
|
130
|
+
expect(screen.getByTestId("sso-denied-wrapper").firstElementChild).toHaveStyle({ background: "#001B3C" });
|
|
131
|
+
expect(circles().map((c) => getComputedStyle(c).backgroundColor)).toContain("rgb(60, 195, 221)");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("AC13 · ErrorPage saca su fondo de la constante compartida y usa el círculo de marca", () => {
|
|
135
|
+
render(
|
|
136
|
+
<ThemeProvider theme={theme}>
|
|
137
|
+
<MemoryRouter>
|
|
138
|
+
<ErrorPage type="404" />
|
|
139
|
+
</MemoryRouter>
|
|
140
|
+
</ThemeProvider>,
|
|
141
|
+
);
|
|
142
|
+
expect(screen.getByTestId("error-page-wrapper")).toHaveStyle({ backgroundColor: BRAND_PALETTE.navy });
|
|
143
|
+
expect(circles().map((c) => getComputedStyle(c).backgroundColor)).toContain("rgb(60, 195, 221)");
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
2
2
|
import { ThemeProvider } from "styled-components";
|
|
3
|
-
import { render, cleanup, screen, fireEvent } from "@testing-library/react";
|
|
4
3
|
import "@testing-library/jest-dom";
|
|
5
4
|
|
|
6
|
-
import { parseTheme } from "@ax/helpers";
|
|
7
5
|
import Login, { type ILoginProps } from "@ax/components/Login";
|
|
6
|
+
import { parseTheme } from "@ax/helpers";
|
|
8
7
|
import globalTheme from "@ax/themes/theme.json";
|
|
9
8
|
|
|
10
9
|
afterEach(cleanup);
|
|
@@ -180,36 +179,6 @@ describe("Login component events", () => {
|
|
|
180
179
|
fireEvent.click(input);
|
|
181
180
|
expect(handleRememberMeMock).toBeCalledTimes(1);
|
|
182
181
|
});
|
|
183
|
-
|
|
184
|
-
it("should change input type on button click", () => {
|
|
185
|
-
const defaultProps: ILoginProps = {
|
|
186
|
-
handleSubmit: vi.fn((e) => e.preventDefault()),
|
|
187
|
-
email: "hola@secuoyas.com",
|
|
188
|
-
handleEmail: vi.fn(),
|
|
189
|
-
password: "",
|
|
190
|
-
handlePassword: vi.fn(),
|
|
191
|
-
isLoggingIn: false,
|
|
192
|
-
settings,
|
|
193
|
-
rememberMe: false,
|
|
194
|
-
handleRememberMe: vi.fn(),
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
render(
|
|
198
|
-
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
199
|
-
<Login {...defaultProps} />
|
|
200
|
-
</ThemeProvider>,
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
const input = screen.getByLabelText("password");
|
|
204
|
-
expect(input).toBeTruthy();
|
|
205
|
-
expect(input).toHaveAttribute("type", "password");
|
|
206
|
-
|
|
207
|
-
const button = screen.getByTestId("icon-component-view");
|
|
208
|
-
expect(button).toBeTruthy();
|
|
209
|
-
fireEvent.click(button);
|
|
210
|
-
|
|
211
|
-
expect(input).toHaveAttribute("type", "text");
|
|
212
|
-
});
|
|
213
182
|
});
|
|
214
183
|
|
|
215
184
|
describe("Recovery Modal rendering", () => {
|