Simplify wagtailConfig.ts mocks in unit tests

- Avoid mock values that are already in the stub
- Only mock values that are needing to be mocked for unit tess
pull/11166/head
LB Johnston 2024-09-19 18:58:48 +10:00 zatwierdzone przez Sage Abdullah
rodzic 4bb47f7e25
commit fa8fdaf72d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: EB1A33CC51CC0217
2 zmienionych plików z 5 dodań i 17 usunięć

Wyświetl plik

@ -6,9 +6,8 @@ import {
jest.mock('../config/wagtailConfig.ts', () => ({
WAGTAIL_CONFIG: {
...jest.requireActual('../config/wagtailConfig.ts').WAGTAIL_CONFIG,
ADMIN_URLS: { DISMISSIBLES: '/admin/dismissibles/' },
CSRF_HEADER_NAME: 'X-CSRFToken',
CSRF_TOKEN: 'test-token',
},
}));
@ -63,7 +62,7 @@ describe('DismissibleController', () => {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': 'test-token',
'x-xsrf-token': 'potato',
},
body: JSON.stringify(data),
mode: 'same-origin',
@ -84,7 +83,7 @@ describe('updateDismissibles', () => {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': 'test-token',
'x-xsrf-token': 'potato',
},
body: JSON.stringify(data),
mode: 'same-origin',

Wyświetl plik

@ -2,13 +2,6 @@ import { Application } from '@hotwired/stimulus';
import { ProgressController } from './ProgressController';
import { PreviewController } from './PreviewController';
jest.mock('../config/wagtailConfig.ts', () => ({
WAGTAIL_CONFIG: {
CSRF_HEADER_NAME: 'X-CSRFToken',
CSRF_TOKEN: 'test-token',
},
}));
jest.useFakeTimers();
jest.spyOn(global, 'setTimeout');
@ -537,9 +530,7 @@ describe('PreviewController', () => {
// Should NOT send a request to clear the preview data, as there is no
// stale data that needs to be cleared
expect(global.fetch).not.toHaveBeenCalledWith(url, {
headers: {
'X-CSRFToken': 'test-token',
},
headers: { 'x-xsrf-token': 'potato' },
method: 'DELETE',
});
@ -686,9 +677,7 @@ describe('PreviewController', () => {
// Should send a request to clear the preview data
expect(global.fetch).toHaveBeenCalledWith(url, {
headers: {
'X-CSRFToken': 'test-token',
},
headers: { 'x-xsrf-token': 'potato' },
method: 'DELETE',
});
// Should not try to reload the iframe yet