test window location assign

This commit is contained in:
Moriz Wahl 2021-11-23 12:16:18 +01:00 committed by Ulf Gebhardt
parent c1381da240
commit 599eaf495a
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
2 changed files with 9 additions and 8 deletions

View File

@ -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',
)
})
})
})

View File

@ -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() {