From 79ec6e206aab462bdd4333ee4677984ca676805a Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 22 Aug 2021 10:50:58 +0800 Subject: [PATCH] fix duplicated logout modal (fix #332) --- resources/assets/src/scripts/homePage.ts | 18 ----------------- .../assets/tests/scripts/homePage.test.ts | 20 +------------------ resources/views/home.twig | 20 ------------------- resources/views/shared/user-menu.twig | 2 +- 4 files changed, 2 insertions(+), 58 deletions(-) diff --git a/resources/assets/src/scripts/homePage.ts b/resources/assets/src/scripts/homePage.ts index b8ba8f38..b8dad290 100644 --- a/resources/assets/src/scripts/homePage.ts +++ b/resources/assets/src/scripts/homePage.ts @@ -1,4 +1,3 @@ -import './i18n' import { getExtraData } from './extra' export function scrollHander() { @@ -15,19 +14,6 @@ export function scrollHander() { } } -export async function logout() { - await fetch(`${blessing.base_url}/auth/logout`, { - method: 'POST', - credentials: 'same-origin', - headers: { - 'X-CSRF-TOKEN': document.querySelector( - 'meta[name="csrf-token"]', - )!.content, - }, - }) - window.location.href = blessing.base_url -} - /* istanbul ignore next */ if (process.env.NODE_ENV !== 'test') { const { transparent_navbar } = getExtraData() as { @@ -37,7 +23,3 @@ if (process.env.NODE_ENV !== 'test') { window.addEventListener('load', scrollHander) } } -/* istanbul ignore next */ -document - .querySelector('#btn-logout') - ?.addEventListener('click', logout) diff --git a/resources/assets/tests/scripts/homePage.test.ts b/resources/assets/tests/scripts/homePage.test.ts index 9caaefa2..c22df08f 100644 --- a/resources/assets/tests/scripts/homePage.test.ts +++ b/resources/assets/tests/scripts/homePage.test.ts @@ -1,22 +1,4 @@ -import { scrollHander, logout } from '@/scripts/homePage' - -test('logout', async () => { - const meta = document.createElement('meta') - meta.name = 'csrf-token' - meta.content = 'token' - document.head.appendChild(meta) - - window.fetch = jest.fn() - - await logout() - expect(window.fetch).toBeCalledWith('/auth/logout', { - method: 'POST', - credentials: 'same-origin', - headers: { - 'X-CSRF-TOKEN': 'token', - }, - }) -}) +import { scrollHander } from '@/scripts/homePage' describe('scroll handler', () => { beforeAll(() => { diff --git a/resources/views/home.twig b/resources/views/home.twig index 61d27228..0316df0f 100644 --- a/resources/views/home.twig +++ b/resources/views/home.twig @@ -128,26 +128,6 @@ {% endif %} - - diff --git a/resources/views/shared/user-menu.twig b/resources/views/shared/user-menu.twig index 5e728cf4..bf16299e 100644 --- a/resources/views/shared/user-menu.twig +++ b/resources/views/shared/user-menu.twig @@ -31,7 +31,7 @@ {% endif %} {% endif %} - + {{ trans('general.logout') }}