fix: clear all localstorage when logging out
This commit is contained in:
parent
3440d71e74
commit
51ffe93048
3 changed files with 45 additions and 11 deletions
|
@ -3,14 +3,19 @@ import {UserFactory} from '../../factories/user'
|
||||||
import {NamespaceFactory} from '../../factories/namespace'
|
import {NamespaceFactory} from '../../factories/namespace'
|
||||||
import {TaskFactory} from '../../factories/task'
|
import {TaskFactory} from '../../factories/task'
|
||||||
|
|
||||||
|
export function createLists() {
|
||||||
|
UserFactory.create(1)
|
||||||
|
NamespaceFactory.create(1)
|
||||||
|
const lists = ListFactory.create(1, {
|
||||||
|
title: 'First List'
|
||||||
|
})
|
||||||
|
TaskFactory.truncate()
|
||||||
|
return lists
|
||||||
|
}
|
||||||
|
|
||||||
export function prepareLists(setLists = () => {}) {
|
export function prepareLists(setLists = () => {}) {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
UserFactory.create(1)
|
const lists = createLists()
|
||||||
NamespaceFactory.create(1)
|
|
||||||
const lists = ListFactory.create(1, {
|
|
||||||
title: 'First List'
|
|
||||||
})
|
|
||||||
setLists(lists)
|
setLists(lists)
|
||||||
TaskFactory.truncate()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -1,16 +1,44 @@
|
||||||
import '../../support/authenticateUser'
|
import '../../support/authenticateUser'
|
||||||
|
import {createLists} from '../list/prepareLists'
|
||||||
|
|
||||||
|
function logout() {
|
||||||
|
cy.get('.navbar .user .username')
|
||||||
|
.click()
|
||||||
|
cy.get('.navbar .user .dropdown-menu .dropdown-item')
|
||||||
|
.contains('Logout')
|
||||||
|
.click()
|
||||||
|
}
|
||||||
|
|
||||||
describe('Log out', () => {
|
describe('Log out', () => {
|
||||||
it('Logs the user out', () => {
|
it('Logs the user out', () => {
|
||||||
cy.visit('/')
|
cy.visit('/')
|
||||||
|
|
||||||
cy.get('.navbar .user .username')
|
expect(localStorage.getItem('token')).to.not.eq(null)
|
||||||
.click()
|
|
||||||
cy.get('.navbar .user .dropdown-menu .dropdown-item')
|
logout()
|
||||||
.contains('Logout')
|
|
||||||
.click()
|
|
||||||
|
|
||||||
cy.url()
|
cy.url()
|
||||||
.should('contain', '/login')
|
.should('contain', '/login')
|
||||||
|
.then(() => {
|
||||||
|
expect(localStorage.getItem('token')).to.eq(null)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it.skip('Should clear the list history after logging the user out', () => {
|
||||||
|
const lists = createLists()
|
||||||
|
cy.visit(`/lists/${lists[0].id}`)
|
||||||
|
.then(() => {
|
||||||
|
expect(localStorage.getItem('listHistory')).to.not.eq(null)
|
||||||
|
})
|
||||||
|
|
||||||
|
logout()
|
||||||
|
|
||||||
|
cy.wait(1000) // This makes re-loading of the list and associated entities (and the resulting error) visible
|
||||||
|
|
||||||
|
cy.url()
|
||||||
|
.should('contain', '/login')
|
||||||
|
.then(() => {
|
||||||
|
expect(localStorage.getItem('listHistory')).to.eq(null)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -287,6 +287,7 @@ export default {
|
||||||
},
|
},
|
||||||
logout(ctx) {
|
logout(ctx) {
|
||||||
removeToken()
|
removeToken()
|
||||||
|
window.localStorage.clear() // Clear all settings and history we might have saved in local storage.
|
||||||
ctx.dispatch('checkAuth')
|
ctx.dispatch('checkAuth')
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue