mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-07 10:23:20 +02:00
parent
2671b997f2
commit
2f42c8cf72
@ -1,4 +1,4 @@
|
|||||||
import {execPseudoSelectorCommands} from './common-fetch-action.ts';
|
import {execPseudoSelectorCommands, handleFetchActionSuccessJson} from './common-fetch-action.ts';
|
||||||
|
|
||||||
test('execPseudoSelectorCommands', () => {
|
test('execPseudoSelectorCommands', () => {
|
||||||
window.document.body.innerHTML = `
|
window.document.body.innerHTML = `
|
||||||
@ -37,3 +37,23 @@ test('execPseudoSelectorCommands', () => {
|
|||||||
expect(ret.targets.length).toEqual(2);
|
expect(ret.targets.length).toEqual(2);
|
||||||
expect(ret.targets).toEqual(Array.from(document.querySelectorAll('#d1 .x')));
|
expect(ret.targets).toEqual(Array.from(document.querySelectorAll('#d1 .x')));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('handleFetchActionSuccessJson', async () => {
|
||||||
|
const spyAssign = vi.spyOn(window.location, 'assign').mockImplementation(() => {});
|
||||||
|
const spyReload = vi.spyOn(window.location, 'reload').mockImplementation(() => {});
|
||||||
|
|
||||||
|
await handleFetchActionSuccessJson(document.body, {redirect: '/'});
|
||||||
|
expect(spyAssign).toHaveBeenCalledTimes(1);
|
||||||
|
expect(spyReload).toHaveBeenCalledTimes(0);
|
||||||
|
vi.resetAllMocks();
|
||||||
|
|
||||||
|
await handleFetchActionSuccessJson(document.body, {redirect: ''});
|
||||||
|
expect(spyAssign).toHaveBeenCalledTimes(0);
|
||||||
|
expect(spyReload).toHaveBeenCalledTimes(1);
|
||||||
|
vi.resetAllMocks();
|
||||||
|
|
||||||
|
await handleFetchActionSuccessJson(document.body, {});
|
||||||
|
expect(spyAssign).toHaveBeenCalledTimes(0);
|
||||||
|
expect(spyReload).toHaveBeenCalledTimes(1);
|
||||||
|
vi.resetAllMocks();
|
||||||
|
});
|
||||||
|
|||||||
@ -34,7 +34,7 @@ function fetchActionDoRedirect(redirect: string) {
|
|||||||
// * Also do so in development, to make sure the redirection logic is always tested by real users
|
// * Also do so in development, to make sure the redirection logic is always tested by real users
|
||||||
const needBackendHelp = redirect.includes('#');
|
const needBackendHelp = redirect.includes('#');
|
||||||
if (runModeIsProd && !needBackendHelp) {
|
if (runModeIsProd && !needBackendHelp) {
|
||||||
window.location.href = redirect;
|
window.location.assign(redirect);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,11 +66,13 @@ function toggleLoadingIndicator(el: HTMLElement, opt: FetchActionOpts, isLoading
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleFetchActionSuccessJson(el: HTMLElement, respJson: any) {
|
export async function handleFetchActionSuccessJson(el: HTMLElement, respJson: any) {
|
||||||
ignoreAreYouSure(el); // ignore the areYouSure check before reloading
|
ignoreAreYouSure(el); // ignore the areYouSure check before reloading
|
||||||
if (typeof respJson?.redirect === 'string') {
|
const redirect = respJson?.redirect;
|
||||||
fetchActionDoRedirect(respJson.redirect);
|
if (typeof redirect === 'string' && redirect) {
|
||||||
|
fetchActionDoRedirect(redirect);
|
||||||
} else {
|
} else {
|
||||||
|
// reserved behavior, in the future, there can be more fields to introduce more behaviors
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user