@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,397 @@
|
|
|
1
|
+
import { global, languages, users } from "@ax/api";
|
|
2
|
+
import { appActions } from "@ax/containers/App";
|
|
3
|
+
import { LOGOUT, SET_TOKEN } from "@ax/containers/App/constants";
|
|
4
|
+
import { appReducer } from "@ax/containers/App/reducer";
|
|
5
|
+
import { usersActions } from "@ax/containers/Users";
|
|
6
|
+
|
|
7
|
+
import type { Mock } from "vitest";
|
|
8
|
+
|
|
9
|
+
import { getSession, registerSessionBridge, resetSessionState, setSession } from "../../../api/session";
|
|
10
|
+
import history from "../../../routes/history";
|
|
11
|
+
|
|
12
|
+
const persisted = (token: string, refreshToken: string, sessionUpdatedAt: number) =>
|
|
13
|
+
JSON.stringify({
|
|
14
|
+
token: JSON.stringify(token),
|
|
15
|
+
refreshToken: JSON.stringify(refreshToken),
|
|
16
|
+
sessionUpdatedAt: JSON.stringify(sessionUpdatedAt),
|
|
17
|
+
_persist: JSON.stringify({ version: -1, rehydrated: true }),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
let onExpired: Mock<() => void>;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
localStorage.clear();
|
|
24
|
+
resetSessionState();
|
|
25
|
+
onExpired = vi.fn();
|
|
26
|
+
registerSessionBridge({ onExpired });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("login guarda el par de sesión", () => {
|
|
30
|
+
const runLogin = async (data: Record<string, unknown>) => {
|
|
31
|
+
const dispatch = vi.fn();
|
|
32
|
+
vi.spyOn(global, "login").mockResolvedValue({ status: 200, data } as any);
|
|
33
|
+
vi.spyOn(languages, "getLanguages").mockResolvedValue({ status: 200, data: { items: [] } } as any);
|
|
34
|
+
vi.spyOn(usersActions, "getUser").mockReturnValue((async () => undefined) as any);
|
|
35
|
+
const result = await appActions.login({ email: "a@b.c", password: "x" })(dispatch, vi.fn() as any);
|
|
36
|
+
return { dispatch, result };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
it("login con refresh: acción SET_TOKEN con acceso, refresh y versión; sesión en memoria", async () => {
|
|
40
|
+
const { dispatch, result } = await runLogin({ id: 7, token: "jwt", refreshToken: "r1" });
|
|
41
|
+
|
|
42
|
+
expect(result).toBe(true);
|
|
43
|
+
const setToken = dispatch.mock.calls.map(([a]) => a).find((a) => a.type === SET_TOKEN);
|
|
44
|
+
expect(setToken.payload).toEqual({ token: "jwt", refreshToken: "r1", sessionUpdatedAt: expect.any(Number) });
|
|
45
|
+
expect(setToken.payload.sessionUpdatedAt).toBeGreaterThan(0);
|
|
46
|
+
expect(getSession()).toMatchObject({ token: "jwt", refreshToken: "r1" });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("login con API antigua (sin refresh): refresh vacío y sesión sin refresh", async () => {
|
|
50
|
+
const { dispatch } = await runLogin({ id: 7, token: "jwt" });
|
|
51
|
+
|
|
52
|
+
const setToken = dispatch.mock.calls.map(([a]) => a).find((a) => a.type === SET_TOKEN);
|
|
53
|
+
expect(setToken.payload.refreshToken).toBe("");
|
|
54
|
+
expect(getSession()).toMatchObject({ token: "jwt", refreshToken: null });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("el login SSO (petitionId) usa el mismo camino y guarda el refresh", async () => {
|
|
58
|
+
const dispatch = vi.fn();
|
|
59
|
+
const login = vi.spyOn(global, "login").mockResolvedValue({
|
|
60
|
+
status: 200,
|
|
61
|
+
data: { id: 1, token: "sso-jwt", refreshToken: "sso-r" },
|
|
62
|
+
} as any);
|
|
63
|
+
vi.spyOn(languages, "getLanguages").mockResolvedValue({ status: 200, data: { items: [] } } as any);
|
|
64
|
+
vi.spyOn(usersActions, "getUser").mockReturnValue((async () => undefined) as any);
|
|
65
|
+
|
|
66
|
+
await appActions.login({ petitionId: "abc" })(dispatch, vi.fn() as any);
|
|
67
|
+
|
|
68
|
+
expect(login).toHaveBeenCalledWith({ username: undefined, password: undefined, petitionId: "abc" });
|
|
69
|
+
expect(getSession()).toMatchObject({ token: "sso-jwt", refreshToken: "sso-r" });
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("createPassword y cambio de contraseña guardan la sesión nueva", () => {
|
|
74
|
+
it("createPassword guarda acceso y refresh", async () => {
|
|
75
|
+
const dispatch = vi.fn();
|
|
76
|
+
vi.spyOn(global, "createPassword").mockResolvedValue({
|
|
77
|
+
status: 200,
|
|
78
|
+
data: { token: "t", refreshToken: "r" },
|
|
79
|
+
} as any);
|
|
80
|
+
vi.spyOn(usersActions, "getRoles").mockReturnValue((async () => undefined) as any);
|
|
81
|
+
vi.spyOn(usersActions, "getUser").mockReturnValue((async () => undefined) as any);
|
|
82
|
+
|
|
83
|
+
await usersActions.createPassword(5, { password: "p" } as any)(dispatch, vi.fn() as any);
|
|
84
|
+
|
|
85
|
+
const setToken = dispatch.mock.calls.map(([a]) => a).find((a) => a?.type === SET_TOKEN);
|
|
86
|
+
expect(setToken.payload).toMatchObject({ token: "t", refreshToken: "r" });
|
|
87
|
+
expect(getSession()).toMatchObject({ token: "t", refreshToken: "r" });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("cambiar la contraseña devuelve par nuevo y AX sustituye la sesión", async () => {
|
|
91
|
+
setSession("old", "r-old");
|
|
92
|
+
const dispatch = vi.fn();
|
|
93
|
+
vi.spyOn(users, "updatePassword").mockResolvedValue({
|
|
94
|
+
status: 200,
|
|
95
|
+
data: { token: "new", refreshToken: "r-new" },
|
|
96
|
+
} as any);
|
|
97
|
+
|
|
98
|
+
const ok = await usersActions.updatePassword(5, { password: "x" })(dispatch);
|
|
99
|
+
|
|
100
|
+
expect(ok).toBe(true);
|
|
101
|
+
expect(getSession()).toMatchObject({ token: "new", refreshToken: "r-new" });
|
|
102
|
+
expect(dispatch.mock.calls.map(([a]) => a).some((a) => a?.type === SET_TOKEN && a.payload.token === "new")).toBe(
|
|
103
|
+
true,
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("cambiar la contraseña de otra persona (sin par en la respuesta) no toca la sesión", async () => {
|
|
108
|
+
setSession("mine", "r-mine");
|
|
109
|
+
const dispatch = vi.fn();
|
|
110
|
+
vi.spyOn(users, "updatePassword").mockResolvedValue({ status: 200, data: {} } as any);
|
|
111
|
+
|
|
112
|
+
await usersActions.updatePassword(9, { password: "x" })(dispatch);
|
|
113
|
+
|
|
114
|
+
expect(getSession()).toMatchObject({ token: "mine", refreshToken: "r-mine" });
|
|
115
|
+
expect(dispatch.mock.calls.some(([a]) => a?.type === SET_TOKEN)).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("un cambio de contraseña fallido no toca la sesión", async () => {
|
|
119
|
+
setSession("mine", "r-mine");
|
|
120
|
+
vi.spyOn(users, "updatePassword").mockResolvedValue({ status: 400, data: { code: 400, message: "x" } } as any);
|
|
121
|
+
|
|
122
|
+
await usersActions.updatePassword(5, { password: "x" })(vi.fn());
|
|
123
|
+
|
|
124
|
+
expect(getSession()).toMatchObject({ token: "mine" });
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("logout", () => {
|
|
129
|
+
it("avisa a la API con el acceso (aunque esté caducado) y el refresh, y limpia el estado local", () => {
|
|
130
|
+
localStorage.setItem("persist:app", persisted("expired-jwt", "r1", 5));
|
|
131
|
+
localStorage.setItem("sitesConfig", "keep");
|
|
132
|
+
localStorage.setItem("other", "drop");
|
|
133
|
+
const logoutApi = vi.spyOn(global, "logout").mockResolvedValue({ status: 204 } as any);
|
|
134
|
+
|
|
135
|
+
const action = appActions.logout();
|
|
136
|
+
|
|
137
|
+
expect(logoutApi).toHaveBeenCalledWith({ token: "expired-jwt", refreshToken: "r1" });
|
|
138
|
+
expect(action).toEqual({ type: LOGOUT, payload: { token: "", refreshToken: "", sessionUpdatedAt: 0 } });
|
|
139
|
+
expect(localStorage.getItem("other")).toBeNull();
|
|
140
|
+
expect(localStorage.getItem("sitesConfig")).toBe("keep");
|
|
141
|
+
expect(getSession()).toBeNull();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("sin sesión no llama a la API", () => {
|
|
145
|
+
const logoutApi = vi.spyOn(global, "logout").mockResolvedValue({ status: 204 } as any);
|
|
146
|
+
|
|
147
|
+
appActions.logout();
|
|
148
|
+
|
|
149
|
+
expect(logoutApi).not.toHaveBeenCalled();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("si la API de logout falla o rechaza, el cierre local no se rompe", async () => {
|
|
153
|
+
setSession("jwt", "r");
|
|
154
|
+
vi.spyOn(global, "logout").mockRejectedValue(new Error("boom"));
|
|
155
|
+
|
|
156
|
+
expect(() => appActions.logout()).not.toThrow();
|
|
157
|
+
await Promise.resolve();
|
|
158
|
+
expect(getSession()).toBeNull();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("un 401 del logout no vuelve a despachar el cierre de sesión", async () => {
|
|
162
|
+
setSession("jwt", "r");
|
|
163
|
+
vi.spyOn(global, "logout").mockResolvedValue({ status: 401 } as any);
|
|
164
|
+
|
|
165
|
+
appActions.logout();
|
|
166
|
+
await Promise.resolve();
|
|
167
|
+
|
|
168
|
+
expect(onExpired).not.toHaveBeenCalled();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("el reducer vacía acceso, refresh y versión", () => {
|
|
172
|
+
const state = appReducer(
|
|
173
|
+
{ ...appReducer(undefined, { type: "x" }), token: "t", refreshToken: "r", sessionUpdatedAt: 9 } as Parameters<
|
|
174
|
+
typeof appReducer
|
|
175
|
+
>[0],
|
|
176
|
+
appActions.logout(),
|
|
177
|
+
);
|
|
178
|
+
expect(state).toMatchObject({ token: "", refreshToken: "", sessionUpdatedAt: 0 });
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe("logoutAndNavigate", () => {
|
|
183
|
+
it("navega a /logout y marca la sesión como cerrada (un cierre remoto no lanza otro)", async () => {
|
|
184
|
+
const push = vi.spyOn(history, "push").mockImplementation(() => undefined);
|
|
185
|
+
|
|
186
|
+
await appActions.logoutAndNavigate()(vi.fn());
|
|
187
|
+
|
|
188
|
+
expect(push).toHaveBeenCalledWith("/logout", undefined);
|
|
189
|
+
// después de un cierre manual/remoto, un 401 en vuelo no vuelve a despachar
|
|
190
|
+
const { endSession } = await import("../../../api/session");
|
|
191
|
+
endSession();
|
|
192
|
+
expect(onExpired).not.toHaveBeenCalled();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe("logoutAndEndCentralSession (botón «Logout» del menú)", () => {
|
|
197
|
+
const URL_OK = "https://api.uni.es/sso/logout";
|
|
198
|
+
let assign: Mock<(url: string) => void>;
|
|
199
|
+
let push: ReturnType<typeof vi.spyOn>;
|
|
200
|
+
|
|
201
|
+
const state = (GriddoIdEnabled: boolean) => () => ({ app: { globalSettings: { GriddoIdEnabled } } }) as never;
|
|
202
|
+
const run = (dispatch = vi.fn(), enabled = true) => appActions.logoutAndEndCentralSession()(dispatch, state(enabled));
|
|
203
|
+
|
|
204
|
+
beforeEach(() => {
|
|
205
|
+
assign = vi.fn();
|
|
206
|
+
vi.stubGlobal("location", { ...window.location, assign });
|
|
207
|
+
push = vi.spyOn(history, "push").mockImplementation(() => undefined);
|
|
208
|
+
setSession("jwt", "r1");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
afterEach(() => {
|
|
212
|
+
vi.useRealTimers();
|
|
213
|
+
vi.unstubAllGlobals();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("sesión de Griddo ID: limpia lo local, navega a la URL de cierre central y no pasa por /logout", async () => {
|
|
217
|
+
localStorage.setItem("sitesConfig", "keep");
|
|
218
|
+
localStorage.setItem("other", "drop");
|
|
219
|
+
const logoutApi = vi
|
|
220
|
+
.spyOn(global, "logout")
|
|
221
|
+
.mockResolvedValue({ status: 200, data: { endSessionUrl: URL_OK } } as any);
|
|
222
|
+
const dispatch = vi.fn();
|
|
223
|
+
|
|
224
|
+
await run(dispatch);
|
|
225
|
+
|
|
226
|
+
expect(logoutApi).toHaveBeenCalledTimes(1);
|
|
227
|
+
expect(logoutApi).toHaveBeenCalledWith({ token: "jwt", refreshToken: "r1" });
|
|
228
|
+
expect(assign).toHaveBeenCalledExactlyOnceWith(URL_OK);
|
|
229
|
+
expect(push).not.toHaveBeenCalled();
|
|
230
|
+
expect(getSession()).toBeNull();
|
|
231
|
+
expect(localStorage.getItem("other")).toBeNull();
|
|
232
|
+
expect(localStorage.getItem("sitesConfig")).toBe("keep");
|
|
233
|
+
expect(dispatch).toHaveBeenCalledWith({
|
|
234
|
+
type: LOGOUT,
|
|
235
|
+
payload: { token: "", refreshToken: "", sessionUpdatedAt: 0 },
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("marca la sesión como cerrada: un 401 en vuelo no lanza otro cierre", async () => {
|
|
240
|
+
vi.spyOn(global, "logout").mockResolvedValue({ status: 200, data: { endSessionUrl: URL_OK } } as any);
|
|
241
|
+
|
|
242
|
+
await run();
|
|
243
|
+
const { endSession } = await import("../../../api/session");
|
|
244
|
+
|
|
245
|
+
endSession();
|
|
246
|
+
|
|
247
|
+
expect(onExpired).not.toHaveBeenCalled();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it.each([
|
|
251
|
+
["204", { status: 204 }],
|
|
252
|
+
["401", { status: 401 }],
|
|
253
|
+
["200 sin endSessionUrl", { status: 200, data: {} }],
|
|
254
|
+
["200 con endSessionUrl vacío", { status: 200, data: { endSessionUrl: "" } }],
|
|
255
|
+
["endSessionUrl que no es una URL", { status: 200, data: { endSessionUrl: "no-es-una-url" } }],
|
|
256
|
+
["endSessionUrl javascript:", { status: 200, data: { endSessionUrl: "javascript:alert(1)" } }],
|
|
257
|
+
["endSessionUrl data:", { status: 200, data: { endSessionUrl: "data:text/html,x" } }],
|
|
258
|
+
["204 con endSessionUrl en el cuerpo", { status: 204, data: { endSessionUrl: URL_OK } }],
|
|
259
|
+
])("%s: limpia lo local y navega a /logout como hoy", async (_name, response) => {
|
|
260
|
+
vi.spyOn(global, "logout").mockResolvedValue(response as any);
|
|
261
|
+
|
|
262
|
+
await run();
|
|
263
|
+
|
|
264
|
+
expect(assign).not.toHaveBeenCalled();
|
|
265
|
+
expect(push).toHaveBeenCalledWith("/logout", undefined);
|
|
266
|
+
expect(getSession()).toBeNull();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("si la API rechaza, el cierre local sigue y navega a /logout", async () => {
|
|
270
|
+
vi.spyOn(global, "logout").mockRejectedValue(new Error("Network Error"));
|
|
271
|
+
|
|
272
|
+
await run();
|
|
273
|
+
|
|
274
|
+
expect(assign).not.toHaveBeenCalled();
|
|
275
|
+
expect(push).toHaveBeenCalledWith("/logout", undefined);
|
|
276
|
+
expect(getSession()).toBeNull();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("si la API no responde en 5 s, no se queda esperando: cierra lo local y navega a /logout", async () => {
|
|
280
|
+
vi.useFakeTimers();
|
|
281
|
+
vi.spyOn(global, "logout").mockReturnValue(new Promise(() => undefined) as any);
|
|
282
|
+
|
|
283
|
+
const pending = run();
|
|
284
|
+
|
|
285
|
+
await vi.advanceTimersByTimeAsync(4999);
|
|
286
|
+
expect(push).not.toHaveBeenCalled();
|
|
287
|
+
|
|
288
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
289
|
+
await pending;
|
|
290
|
+
|
|
291
|
+
expect(assign).not.toHaveBeenCalled();
|
|
292
|
+
expect(push).toHaveBeenCalledWith("/logout", undefined);
|
|
293
|
+
expect(getSession()).toBeNull();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("sin sesión no llama a la API y navega a /logout", async () => {
|
|
297
|
+
resetSessionState();
|
|
298
|
+
const logoutApi = vi.spyOn(global, "logout").mockResolvedValue({ status: 204 } as any);
|
|
299
|
+
|
|
300
|
+
await run();
|
|
301
|
+
|
|
302
|
+
expect(logoutApi).not.toHaveBeenCalled();
|
|
303
|
+
expect(assign).not.toHaveBeenCalled();
|
|
304
|
+
expect(push).toHaveBeenCalledWith("/logout", undefined);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("una URL http también se acepta (entornos locales)", async () => {
|
|
308
|
+
vi.spyOn(global, "logout").mockResolvedValue({
|
|
309
|
+
status: 200,
|
|
310
|
+
data: { endSessionUrl: "http://localhost:3001/sso/logout" },
|
|
311
|
+
} as any);
|
|
312
|
+
|
|
313
|
+
await run();
|
|
314
|
+
|
|
315
|
+
expect(assign).toHaveBeenCalledExactlyOnceWith("http://localhost:3001/sso/logout");
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
describe("logoutAndEndCentralSession sin Griddo ID (Comillas o contraseña): como en producción", () => {
|
|
320
|
+
let assign: Mock<(url: string) => void>;
|
|
321
|
+
let push: ReturnType<typeof vi.spyOn>;
|
|
322
|
+
|
|
323
|
+
const run = () =>
|
|
324
|
+
appActions.logoutAndEndCentralSession()(vi.fn(), (() => ({
|
|
325
|
+
app: { globalSettings: { GriddoIdEnabled: false } },
|
|
326
|
+
})) as never);
|
|
327
|
+
|
|
328
|
+
beforeEach(() => {
|
|
329
|
+
assign = vi.fn();
|
|
330
|
+
vi.stubGlobal("location", { ...window.location, assign });
|
|
331
|
+
push = vi.spyOn(history, "push").mockImplementation(() => undefined);
|
|
332
|
+
setSession("jwt", "r1");
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
336
|
+
|
|
337
|
+
it("navega a /logout sin esperar a la API (aunque no responda) y no llama a la API desde la acción", async () => {
|
|
338
|
+
const logoutApi = vi.spyOn(global, "logout").mockReturnValue(new Promise(() => undefined) as any);
|
|
339
|
+
|
|
340
|
+
await run();
|
|
341
|
+
|
|
342
|
+
expect(push).toHaveBeenCalledWith("/logout", undefined);
|
|
343
|
+
expect(logoutApi).not.toHaveBeenCalled();
|
|
344
|
+
expect(assign).not.toHaveBeenCalled();
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it("no usa endSessionUrl aunque la API lo devolviera", async () => {
|
|
348
|
+
vi.spyOn(global, "logout").mockResolvedValue({
|
|
349
|
+
status: 200,
|
|
350
|
+
data: { endSessionUrl: "https://api.uni.es/sso/logout" },
|
|
351
|
+
} as any);
|
|
352
|
+
|
|
353
|
+
await run();
|
|
354
|
+
|
|
355
|
+
expect(assign).not.toHaveBeenCalled();
|
|
356
|
+
expect(push).toHaveBeenCalledWith("/logout", undefined);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("marca la sesión como cerrada (un 401 en vuelo no lanza otro cierre)", async () => {
|
|
360
|
+
await run();
|
|
361
|
+
const { endSession } = await import("../../../api/session");
|
|
362
|
+
|
|
363
|
+
endSession();
|
|
364
|
+
|
|
365
|
+
expect(onExpired).not.toHaveBeenCalled();
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
describe("estado de sesión en el reducer", () => {
|
|
370
|
+
it("SET_TOKEN con par y versión se funde en el estado", () => {
|
|
371
|
+
const state = appReducer(undefined, {
|
|
372
|
+
type: SET_TOKEN,
|
|
373
|
+
payload: { token: "t", refreshToken: "r", sessionUpdatedAt: 4 },
|
|
374
|
+
});
|
|
375
|
+
expect(state).toMatchObject({ token: "t", refreshToken: "r", sessionUpdatedAt: 4 });
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("el estado inicial no tiene refresh ni versión", () => {
|
|
379
|
+
expect(appReducer(undefined, { type: "x" })).toMatchObject({ token: "", refreshToken: "", sessionUpdatedAt: 0 });
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("applySession guarda el par y lo despacha con su versión", () => {
|
|
383
|
+
const dispatch = vi.fn();
|
|
384
|
+
appActions.applySession("a", "b")(dispatch);
|
|
385
|
+
expect(dispatch).toHaveBeenCalledWith({
|
|
386
|
+
type: SET_TOKEN,
|
|
387
|
+
payload: { token: "a", refreshToken: "b", sessionUpdatedAt: getSession()?.updatedAt },
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("applySession sin refresh despacha cadena vacía", () => {
|
|
392
|
+
const dispatch = vi.fn();
|
|
393
|
+
appActions.applySession("a")(dispatch);
|
|
394
|
+
expect(dispatch.mock.calls[0][0].payload.refreshToken).toBe("");
|
|
395
|
+
expect(getSession()?.refreshToken).toBeNull();
|
|
396
|
+
});
|
|
397
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { global, languages } from "@ax/api";
|
|
2
|
+
import { appActions } from "@ax/containers/App";
|
|
3
|
+
import { SET_GLOBAL_SETTINGS, SET_TOKEN } from "@ax/containers/App/constants";
|
|
4
|
+
import { usersActions } from "@ax/containers/Users";
|
|
5
|
+
import { SET_USERS } from "@ax/containers/Users/constants";
|
|
6
|
+
|
|
7
|
+
import { createMemoryHistory } from "history";
|
|
8
|
+
|
|
9
|
+
import { getSession, resetSessionState, setSession } from "../../../api/session";
|
|
10
|
+
import { GlobalStore } from "../../../GlobalStore";
|
|
11
|
+
import history from "../../../routes/history";
|
|
12
|
+
|
|
13
|
+
// Trazabilidad de UC-AX-sign-in-out (AC1, AC2, AC3, AC5) sobre el store real de la app: las acciones
|
|
14
|
+
// se despachan contra `GlobalStore` y se asierta el estado resultante, no las acciones sueltas.
|
|
15
|
+
|
|
16
|
+
const bootstrap = async () => {
|
|
17
|
+
const { store, persistor } = new GlobalStore().configureStore(createMemoryHistory() as never);
|
|
18
|
+
|
|
19
|
+
await vi.waitFor(() => expect(persistor.getState().bootstrapped).toBe(true));
|
|
20
|
+
|
|
21
|
+
return store;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
localStorage.clear();
|
|
26
|
+
resetSessionState();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("[UC-AX-sign-in-out] iniciar sesión", () => {
|
|
30
|
+
const mockOkLogin = () => {
|
|
31
|
+
vi.spyOn(global, "login").mockResolvedValue({
|
|
32
|
+
status: 200,
|
|
33
|
+
data: { id: 7, token: "jwt", refreshToken: "r1" },
|
|
34
|
+
} as never);
|
|
35
|
+
vi.spyOn(languages, "getLanguages").mockResolvedValue({
|
|
36
|
+
status: 200,
|
|
37
|
+
data: { items: [{ id: 1, locale: "es" }] },
|
|
38
|
+
} as never);
|
|
39
|
+
|
|
40
|
+
return vi.spyOn(usersActions, "getUser").mockReturnValue((async () => undefined) as never);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
it("AC1 · login válido: guarda el token, carga idiomas y usuario, marca sessionStartedAt y devuelve true", async () => {
|
|
44
|
+
const getUser = mockOkLogin();
|
|
45
|
+
const store = await bootstrap();
|
|
46
|
+
const before = Date.now();
|
|
47
|
+
|
|
48
|
+
const result = await store.dispatch(appActions.login({ email: "a@b.c", password: "x" }) as never);
|
|
49
|
+
const { app } = store.getState();
|
|
50
|
+
|
|
51
|
+
expect(result).toBe(true);
|
|
52
|
+
expect(app.token).toBe("jwt");
|
|
53
|
+
expect(getSession()).toMatchObject({ token: "jwt", refreshToken: "r1" });
|
|
54
|
+
expect(app.globalLangs).toEqual([{ id: 1, locale: "es" }]);
|
|
55
|
+
expect(getUser).toHaveBeenCalledWith(7, "jwt", false);
|
|
56
|
+
expect(new Date(app.sessionStartedAt as never).getTime()).toBeGreaterThanOrEqual(before);
|
|
57
|
+
expect(app.hasAnimation).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("AC2 · credenciales inválidas (403): no guarda token, muestra «Lost your password?» y devuelve false", async () => {
|
|
61
|
+
vi.spyOn(global, "login").mockResolvedValue({
|
|
62
|
+
status: 403,
|
|
63
|
+
data: { code: 403, message: "Bad credentials" },
|
|
64
|
+
} as never);
|
|
65
|
+
const store = await bootstrap();
|
|
66
|
+
|
|
67
|
+
// el persist diferido de un store anterior puede reescribir la sesión: se parte de limpio
|
|
68
|
+
localStorage.clear();
|
|
69
|
+
resetSessionState();
|
|
70
|
+
const result = await store.dispatch(appActions.login({ email: "a@b.c", password: "mala" }) as never);
|
|
71
|
+
const { app } = store.getState();
|
|
72
|
+
|
|
73
|
+
expect(result).toBe(false);
|
|
74
|
+
expect(app.token).toBe("");
|
|
75
|
+
expect(getSession()).toBeNull();
|
|
76
|
+
expect(app.error).toMatchObject({ code: 403, text: "Bad credentials", btnText: "Lost your password?" });
|
|
77
|
+
expect(app.isLoggingIn).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("AC3 · «Remember me» guarda localStorage.user = { token }", async () => {
|
|
81
|
+
mockOkLogin();
|
|
82
|
+
const store = await bootstrap();
|
|
83
|
+
|
|
84
|
+
await store.dispatch(appActions.login({ email: "a@b.c", password: "x", rememberMe: true }) as never);
|
|
85
|
+
|
|
86
|
+
expect(JSON.parse(localStorage.getItem("user") as string)).toEqual({ token: "jwt" });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("AC3 (borde) · sin «Remember me» no se persiste el token", async () => {
|
|
90
|
+
mockOkLogin();
|
|
91
|
+
const store = await bootstrap();
|
|
92
|
+
|
|
93
|
+
await store.dispatch(appActions.login({ email: "a@b.c", password: "x", rememberMe: false }) as never);
|
|
94
|
+
|
|
95
|
+
expect(localStorage.getItem("user")).toBeNull();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("[UC-AX-sign-in-out] cerrar sesión", () => {
|
|
100
|
+
const URL_OK = "https://api.uni.es/sso/logout";
|
|
101
|
+
let assign: ReturnType<typeof vi.fn>;
|
|
102
|
+
let push: ReturnType<typeof vi.spyOn>;
|
|
103
|
+
|
|
104
|
+
beforeEach(() => {
|
|
105
|
+
assign = vi.fn();
|
|
106
|
+
vi.stubGlobal("location", { ...window.location, assign });
|
|
107
|
+
push = vi.spyOn(history, "push").mockImplementation(() => undefined);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
afterEach(() => {
|
|
111
|
+
vi.unstubAllGlobals();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/** Store con sesión iniciada, Griddo ID activo y algo en los slices que el logout debe vaciar. */
|
|
115
|
+
const loggedInStore = async () => {
|
|
116
|
+
setSession("jwt", "r1");
|
|
117
|
+
localStorage.setItem("sitesConfig", "keep");
|
|
118
|
+
localStorage.setItem("other", "drop");
|
|
119
|
+
const store = await bootstrap();
|
|
120
|
+
|
|
121
|
+
store.dispatch({ type: SET_TOKEN, payload: { token: "jwt", refreshToken: "r1", sessionUpdatedAt: 1 } });
|
|
122
|
+
store.dispatch({ type: SET_GLOBAL_SETTINGS, payload: { globalSettings: { GriddoIdEnabled: true } } });
|
|
123
|
+
store.dispatch({ type: SET_USERS, payload: { users: [{ id: 1 }] } });
|
|
124
|
+
|
|
125
|
+
return store;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
it("AC5 · logout: limpia localStorage salvo sitesConfig, vacía los slices salvo router/app, token vacío y cierra la sesión central", async () => {
|
|
129
|
+
const logoutApi = vi
|
|
130
|
+
.spyOn(global, "logout")
|
|
131
|
+
.mockResolvedValue({ status: 200, data: { endSessionUrl: URL_OK } } as never);
|
|
132
|
+
const store = await loggedInStore();
|
|
133
|
+
const router = store.getState().router;
|
|
134
|
+
|
|
135
|
+
await store.dispatch(appActions.logoutAndEndCentralSession() as never);
|
|
136
|
+
const state = store.getState();
|
|
137
|
+
|
|
138
|
+
expect(logoutApi).toHaveBeenCalledWith({ token: "jwt", refreshToken: "r1" });
|
|
139
|
+
expect(assign).toHaveBeenCalledExactlyOnceWith(URL_OK);
|
|
140
|
+
expect(localStorage.getItem("other")).toBeNull();
|
|
141
|
+
expect(localStorage.getItem("sitesConfig")).toBe("keep");
|
|
142
|
+
expect(state.app.token).toBe("");
|
|
143
|
+
expect(state.users.users).toEqual([]);
|
|
144
|
+
expect(state.router).toBe(router);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("AC5 (borde) · si el cierre de la sesión central falla, el estado local queda limpio y se llega a /logout", async () => {
|
|
148
|
+
vi.spyOn(global, "logout").mockRejectedValue(new Error("boom"));
|
|
149
|
+
const store = await loggedInStore();
|
|
150
|
+
|
|
151
|
+
await store.dispatch(appActions.logoutAndEndCentralSession() as never);
|
|
152
|
+
|
|
153
|
+
expect(store.getState().app.token).toBe("");
|
|
154
|
+
expect(getSession()).toBeNull();
|
|
155
|
+
expect(localStorage.getItem("other")).toBeNull();
|
|
156
|
+
expect(assign).not.toHaveBeenCalled();
|
|
157
|
+
expect(push).toHaveBeenCalledWith("/logout", undefined);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { buildGriddoIdStartUrl, MAX_LOGIN_HINT_LENGTH } from "@ax/helpers";
|
|
2
|
+
|
|
3
|
+
const API = "https://api.uni.es";
|
|
4
|
+
const START = `${API}/sso/start`;
|
|
5
|
+
|
|
6
|
+
const emailOfLength = (length: number) => `${"a".repeat(length - "@uni.es".length)}@uni.es`;
|
|
7
|
+
|
|
8
|
+
describe("buildGriddoIdStartUrl", () => {
|
|
9
|
+
it.each([
|
|
10
|
+
["ana@uni.es", `${START}?login_hint=ana%40uni.es`],
|
|
11
|
+
[" ana@uni.es ", `${START}?login_hint=ana%40uni.es`],
|
|
12
|
+
["\t\nana@uni.es\r\n", `${START}?login_hint=ana%40uni.es`],
|
|
13
|
+
["Ana@UNI.es", `${START}?login_hint=Ana%40UNI.es`],
|
|
14
|
+
["ana @uni.es", `${START}?login_hint=ana%20%40uni.es`],
|
|
15
|
+
["ana+x@uni.es", `${START}?login_hint=ana%2Bx%40uni.es`],
|
|
16
|
+
["a&b=c@uni.es", `${START}?login_hint=a%26b%3Dc%40uni.es`],
|
|
17
|
+
["ñandú@uni.es", `${START}?login_hint=%C3%B1and%C3%BA%40uni.es`],
|
|
18
|
+
])("con %j navega con el hint codificado", (typed, expected) => {
|
|
19
|
+
expect(buildGriddoIdStartUrl(API, typed)).toBe(expected);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("el tope es 254 caracteres", () => {
|
|
23
|
+
expect(MAX_LOGIN_HINT_LENGTH).toBe(254);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("254 caracteres con @ llevan el hint", () => {
|
|
27
|
+
const email = emailOfLength(254);
|
|
28
|
+
|
|
29
|
+
expect(buildGriddoIdStartUrl(API, email)).toBe(`${START}?login_hint=${encodeURIComponent(email)}`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("254 caracteres con espacios en los extremos llevan el hint recortado", () => {
|
|
33
|
+
const email = emailOfLength(254);
|
|
34
|
+
|
|
35
|
+
expect(buildGriddoIdStartUrl(API, ` ${email} `)).toBe(`${START}?login_hint=${encodeURIComponent(email)}`);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it.each([
|
|
39
|
+
["vacío", ""],
|
|
40
|
+
["solo espacios", " "],
|
|
41
|
+
["sin arroba", "ana"],
|
|
42
|
+
["255 caracteres con @", emailOfLength(255)],
|
|
43
|
+
["un texto de 20 KB con @", `${"a".repeat(20 * 1024)}@uni.es`],
|
|
44
|
+
["un sustituto suelto", "\uD800@uni.es"],
|
|
45
|
+
])("con %s navega a /sso/start sin query", (_case, typed) => {
|
|
46
|
+
expect(buildGriddoIdStartUrl(API, typed)).toBe(START);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("no cambia mayúsculas ni espacios interiores (la normalización es de la app de login)", () => {
|
|
50
|
+
expect(buildGriddoIdStartUrl(API, "A B@UNI.es")).toBe(`${START}?login_hint=A%20%20B%40UNI.es`);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("con una URL de API sin definir no inventa un host", () => {
|
|
54
|
+
expect(buildGriddoIdStartUrl("", "ana@uni.es")).toBe("/sso/start?login_hint=ana%40uni.es");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { act, renderHook } from "@testing-library/react";
|
|
4
|
+
|
|
5
|
+
import "@testing-library/jest-dom";
|
|
6
|
+
|
|
7
|
+
import { useShouldBeSaved } from "@ax/hooks";
|
|
8
|
+
|
|
9
|
+
type Form = Record<string, unknown>;
|
|
10
|
+
|
|
11
|
+
const setup = (initial: Form) =>
|
|
12
|
+
renderHook(() => {
|
|
13
|
+
const [form, setForm] = useState<Form>(initial);
|
|
14
|
+
const saved = useShouldBeSaved(form);
|
|
15
|
+
|
|
16
|
+
return { form, setForm, ...saved };
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const A: Form = { id: 1, name: "Ana", sites: [] };
|
|
20
|
+
const B: Form = { id: 1, name: "Ana", sites: [10] }; // lo que edita el usuario
|
|
21
|
+
const C: Form = { id: 1, name: "Ana", sites: [10], modifiedBy: "server" }; // lo que devuelve el servidor tras guardar
|
|
22
|
+
|
|
23
|
+
describe("useShouldBeSaved", () => {
|
|
24
|
+
it("marca dirty al editar y limpio al volver al original", () => {
|
|
25
|
+
const { result } = setup(A);
|
|
26
|
+
|
|
27
|
+
act(() => result.current.setForm(B));
|
|
28
|
+
expect(result.current.isDirty).toBe(true);
|
|
29
|
+
|
|
30
|
+
act(() => result.current.setForm(A));
|
|
31
|
+
expect(result.current.isDirty).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("setIsDirty(false) sin base toma el form de ese render como referencia", () => {
|
|
35
|
+
const { result } = setup(A);
|
|
36
|
+
|
|
37
|
+
act(() => result.current.setForm(B));
|
|
38
|
+
act(() => result.current.setIsDirty(false));
|
|
39
|
+
|
|
40
|
+
expect(result.current.isDirty).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("tras guardar, si el servidor devuelve el form ya sincronizado y se fija como base, queda limpio (respuesta ANTES del setIsDirty)", () => {
|
|
44
|
+
const { result } = setup(A);
|
|
45
|
+
|
|
46
|
+
act(() => result.current.setForm(B));
|
|
47
|
+
const staleSetIsDirty = result.current.setIsDirty; // el del render del clic en guardar
|
|
48
|
+
|
|
49
|
+
act(() => result.current.setForm(C)); // llega la respuesta y el form se sincroniza
|
|
50
|
+
act(() => staleSetIsDirty(false, C));
|
|
51
|
+
|
|
52
|
+
expect(result.current.isDirty).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("tras guardar, la respuesta DESPUÉS del setIsDirty tampoco deja el form sucio si la base es la del servidor", () => {
|
|
56
|
+
const { result } = setup(A);
|
|
57
|
+
|
|
58
|
+
act(() => result.current.setForm(B));
|
|
59
|
+
const staleSetIsDirty = result.current.setIsDirty;
|
|
60
|
+
|
|
61
|
+
act(() => staleSetIsDirty(false, C)); // se guarda y se fija ya la base que traerá el servidor
|
|
62
|
+
act(() => result.current.setForm(C)); // la respuesta llega después
|
|
63
|
+
|
|
64
|
+
expect(result.current.isDirty).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("sin pasar la base del servidor, ese orden deja el botón sucio (el bug que se corrige)", () => {
|
|
68
|
+
const { result } = setup(A);
|
|
69
|
+
|
|
70
|
+
act(() => result.current.setForm(B));
|
|
71
|
+
const staleSetIsDirty = result.current.setIsDirty;
|
|
72
|
+
|
|
73
|
+
act(() => staleSetIsDirty(false)); // base = B (form viejo del cierre)
|
|
74
|
+
act(() => result.current.setForm(C)); // el servidor devuelve C ≠ B
|
|
75
|
+
|
|
76
|
+
expect(result.current.isDirty).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
});
|