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 prepareLists(setLists = () => {}) {
|
export function createLists() {
|
||||||
beforeEach(() => {
|
|
||||||
UserFactory.create(1)
|
UserFactory.create(1)
|
||||||
NamespaceFactory.create(1)
|
NamespaceFactory.create(1)
|
||||||
const lists = ListFactory.create(1, {
|
const lists = ListFactory.create(1, {
|
||||||
title: 'First List'
|
title: 'First List'
|
||||||
})
|
})
|
||||||
setLists(lists)
|
|
||||||
TaskFactory.truncate()
|
TaskFactory.truncate()
|
||||||
|
return lists
|
||||||
|
}
|
||||||
|
|
||||||
|
export function prepareLists(setLists = () => {}) {
|
||||||
|
beforeEach(() => {
|
||||||
|
const lists = createLists()
|
||||||
|
setLists(lists)
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -1,16 +1,44 @@
|
||||||
import '../../support/authenticateUser'
|
import '../../support/authenticateUser'
|
||||||
|
import {createLists} from '../list/prepareLists'
|
||||||
|
|
||||||
describe('Log out', () => {
|
function logout() {
|
||||||
it('Logs the user out', () => {
|
|
||||||
cy.visit('/')
|
|
||||||
|
|
||||||
cy.get('.navbar .user .username')
|
cy.get('.navbar .user .username')
|
||||||
.click()
|
.click()
|
||||||
cy.get('.navbar .user .dropdown-menu .dropdown-item')
|
cy.get('.navbar .user .dropdown-menu .dropdown-item')
|
||||||
.contains('Logout')
|
.contains('Logout')
|
||||||
.click()
|
.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Log out', () => {
|
||||||
|
it('Logs the user out', () => {
|
||||||
|
cy.visit('/')
|
||||||
|
|
||||||
|
expect(localStorage.getItem('token')).to.not.eq(null)
|
||||||
|
|
||||||
|
logout()
|
||||||
|
|
||||||
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