Fix saving showing archived setting

This commit is contained in:
kolaente 2021-06-03 15:31:39 +02:00
parent 0f42ed3cf7
commit 4a3b4982ab
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 51 additions and 8 deletions

View File

@ -3,7 +3,6 @@ import {UserFactory} from '../../factories/user'
import '../../support/authenticateUser' import '../../support/authenticateUser'
import {ListFactory} from '../../factories/list' import {ListFactory} from '../../factories/list'
import {NamespaceFactory} from '../../factories/namespace' import {NamespaceFactory} from '../../factories/namespace'
import {TaskFactory} from '../../factories/task'
describe('Namepaces', () => { describe('Namepaces', () => {
let namespaces let namespaces
@ -99,4 +98,48 @@ describe('Namepaces', () => {
cy.get('.namespace-container .menu.namespaces-lists') cy.get('.namespace-container .menu.namespaces-lists')
.should('not.contain', newNamespaces[0].title) .should('not.contain', newNamespaces[0].title)
}) })
it('Should not show archived lists & namespaces if the filter is not checked', () => {
const n = NamespaceFactory.create(1, {
id: 2,
is_archived: true,
}, false)
ListFactory.create(1, {
id: 2,
namespace_id: n[0].id,
}, false)
ListFactory.create(1, {
id: 3,
is_archived: true,
}, false)
// Initial
cy.visit('/namespaces')
cy.get('.namespaces-list .namespace')
.should('not.contain', 'Archived')
// Show archived
cy.get('.namespaces-list .fancycheckbox.show-archived-check label.check span')
.should('be.visible')
.click()
cy.get('.namespaces-list .fancycheckbox.show-archived-check input')
.should('be.checked')
cy.get('.namespaces-list .namespace')
.should('contain', 'Archived')
// Don't show archived
cy.get('.namespaces-list .fancycheckbox.show-archived-check label.check span')
.should('be.visible')
.click()
cy.get('.namespaces-list .fancycheckbox.show-archived-check input')
.should('not.be.checked')
// Second time visiting after unchecking
cy.visit('/namespaces')
cy.get('.namespaces-list .fancycheckbox.show-archived-check input')
.should('not.be.checked')
cy.get('.namespaces-list .namespace')
.should('not.contain', 'Archived')
})
}) })

View File

@ -21,7 +21,7 @@ export class Factory {
* @param override * @param override
* @returns {[]} * @returns {[]}
*/ */
static create(count = 1, override = {}) { static create(count = 1, override = {}, truncate = true) {
const data = [] const data = []
for (let i = 1; i <= count; i++) { for (let i = 1; i <= count; i++) {
@ -38,7 +38,7 @@ export class Factory {
data.push(entry) data.push(entry)
} }
seed(this.table, data) seed(this.table, data, truncate)
return data return data
} }

View File

@ -8,14 +8,14 @@
* @param table * @param table
* @param data * @param data
*/ */
export function seed(table, data = {}) { export function seed(table, data = {}, truncate = true) {
if(data === null) { if (data === null) {
data = [] data = []
} }
cy.request({ cy.request({
method: 'PATCH', method: 'PATCH',
url: `${Cypress.env('API_URL')}/test/${table}`, url: `${Cypress.env('API_URL')}/test/${table}?truncate=${truncate ? 'true' : 'false'}`,
headers: { headers: {
'Authorization': Cypress.env('TEST_SECRET'), 'Authorization': Cypress.env('TEST_SECRET'),
}, },

View File

@ -108,7 +108,7 @@ export default {
} }
}, },
created() { created() {
this.showArchived = localStorage.getItem('showArchived') ?? false this.showArchived = JSON.parse(localStorage.getItem('showArchived')) ?? false
this.loadBackgroundsForLists() this.loadBackgroundsForLists()
}, },
mounted() { mounted() {
@ -147,7 +147,7 @@ export default {
.catch(e => this.error(e, this)) .catch(e => this.error(e, this))
}, },
saveShowArchivedState() { saveShowArchivedState() {
localStorage.setItem('showArchived', this.showArchived) localStorage.setItem('showArchived', JSON.stringify(this.showArchived))
}, },
}, },
} }