From 599eaf495a62da460c89794adbd3d7b26394b9ea Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 23 Nov 2021 12:16:18 +0100 Subject: [PATCH] test window location assign --- .../src/components/SidebarPlugin/SideBar.spec.js | 15 ++++++++------- frontend/src/components/SidebarPlugin/SideBar.vue | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/SidebarPlugin/SideBar.spec.js b/frontend/src/components/SidebarPlugin/SideBar.spec.js index 0a3b0ec1a..a129f4660 100644 --- a/frontend/src/components/SidebarPlugin/SideBar.spec.js +++ b/frontend/src/components/SidebarPlugin/SideBar.spec.js @@ -160,25 +160,26 @@ describe('SideBar', () => { it('is not visible when not an admin', () => { expect(wrapper.findAll('li').at(1).text()).not.toBe('admin_area') }) + describe('logged in as admin', () => { const assignLocationSpy = jest.fn() beforeEach(() => { mocks.$store.state.isAdmin = true - mocks.$store.state.token = 'valid token' - // const { location } = window; - delete window.location - window.location = {} - Object.defineProperty(window, 'location', assignLocationSpy) + mocks.$store.state.token = 'valid-token' + window.location.assign = assignLocationSpy wrapper = Wrapper() }) it('is visible', () => { expect(wrapper.findAll('li').at(1).text()).toBe('admin_area') }) - it.skip('opens a new window when clicked', async () => { + + it('opens a new window when clicked', async () => { wrapper.findAll('li').at(1).find('a').trigger('click') await wrapper.vm.$nextTick() - expect(assignLocationSpy).toHaveBeenCalledWith('peter') + expect(assignLocationSpy).toHaveBeenCalledWith( + 'http://localhost/admin/authenticate?token=valid-token', + ) }) }) }) diff --git a/frontend/src/components/SidebarPlugin/SideBar.vue b/frontend/src/components/SidebarPlugin/SideBar.vue index 9cf6b6185..96882e816 100755 --- a/frontend/src/components/SidebarPlugin/SideBar.vue +++ b/frontend/src/components/SidebarPlugin/SideBar.vue @@ -122,7 +122,7 @@ export default { this.$emit('logout') }, admin() { - window.location = CONFIG.ADMIN_AUTH_URL.replace('$1', this.$store.state.token) + window.location.assign(CONFIG.ADMIN_AUTH_URL.replace('$1', this.$store.state.token)) this.$store.dispatch('logout') // logout without redirect }, getElopageLink() {