mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
feat(users): add e2e tests
This commit is contained in:
parent
62b31347ab
commit
6335230f4b
4 changed files with 106 additions and 1 deletions
7
cypress/fixtures/user.post.200.json
Normal file
7
cypress/fixtures/user.post.200.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"id": 4,
|
||||
"name": "Charles",
|
||||
"email": "charles@koel.test",
|
||||
"is_admin": true,
|
||||
"preferences": []
|
||||
}
|
7
cypress/fixtures/user.put.200.json
Normal file
7
cypress/fixtures/user.put.200.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"id": 2,
|
||||
"name": "Adriana",
|
||||
"email": "adriana@koel.test",
|
||||
"is_admin": false,
|
||||
"preferences": []
|
||||
}
|
91
cypress/integration/users.spec.ts
Normal file
91
cypress/integration/users.spec.ts
Normal file
|
@ -0,0 +1,91 @@
|
|||
context('User Management', () => {
|
||||
beforeEach(() => {
|
||||
cy.$login()
|
||||
cy.$clickSidebarItem('Users')
|
||||
})
|
||||
|
||||
it('shows the list of users', () => {
|
||||
cy.get('#usersWrapper').within(() => {
|
||||
cy.get('[data-test=user-card]')
|
||||
.should('have.length', 3)
|
||||
.and('be.visible')
|
||||
|
||||
cy.get('[data-test=user-card].me').within(() => {
|
||||
cy.get('[data-test=current-user-indicator]').should('be.visible')
|
||||
cy.get('[data-test=admin-indicator]').should('be.visible')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('adds a user', () => {
|
||||
cy.intercept('POST', '/api/user', {
|
||||
fixture: 'user.post.200.json'
|
||||
})
|
||||
|
||||
cy.findByTestId('add-user-btn').click()
|
||||
cy.findByTestId('add-user-form').within(() => {
|
||||
cy.get('[name=name]')
|
||||
.should('be.focused')
|
||||
.type('Charles')
|
||||
|
||||
cy.get('[name=email]').type('charles@koel.test')
|
||||
cy.get('[name=password]').type('a-secure-password')
|
||||
cy.get('[name=is_admin]').check()
|
||||
cy.get('[type=submit]').click()
|
||||
})
|
||||
|
||||
cy.findByText('New user "Charles" created.').should('be.visible')
|
||||
cy.get('#usersWrapper [data-test=user-card]').should('have.length', 4)
|
||||
|
||||
cy.get('#usersWrapper [data-test=user-card]:first-child').within(() => {
|
||||
cy.findByText('Charles').should('be.visible')
|
||||
cy.findByText('charles@koel.test').should('be.visible')
|
||||
cy.get('[data-test=admin-indicator]').should('be.visible')
|
||||
})
|
||||
})
|
||||
|
||||
it('redirects to profile for current user', () => {
|
||||
cy.get('#usersWrapper [data-test=user-card].me [data-test=edit-user-btn]').click({ force: true })
|
||||
cy.url().should('contain', '/#!/profile')
|
||||
})
|
||||
|
||||
it('edits a user', () => {
|
||||
cy.intercept('PUT', '/api/user/2', {
|
||||
fixture: 'user.put.200.json'
|
||||
})
|
||||
|
||||
cy.get('#usersWrapper [data-test=user-card]:nth-child(2) [data-test=edit-user-btn]').click({ force: true })
|
||||
|
||||
cy.findByTestId('edit-user-form').within(() => {
|
||||
cy.get('[name=name]')
|
||||
.should('be.focused')
|
||||
.and('have.value', 'Alice')
|
||||
.clear()
|
||||
.type('Adriana')
|
||||
|
||||
cy.get('[name=email]')
|
||||
.should('have.value', 'alice@koel.test')
|
||||
.clear()
|
||||
.type('adriana@koel.test')
|
||||
|
||||
cy.get('[name=password]').should('have.value', '')
|
||||
cy.get('[type=submit]').click()
|
||||
})
|
||||
|
||||
cy.findByText('User profile updated.').should('be.visible')
|
||||
|
||||
cy.get('#usersWrapper [data-test=user-card]:nth-child(2)').within(() => {
|
||||
cy.findByText('Adriana').should('be.visible')
|
||||
cy.findByText('adriana@koel.test').should('be.visible')
|
||||
})
|
||||
})
|
||||
|
||||
it('deletes a user', () => {
|
||||
cy.intercept('DELETE', '/api/user/2', {})
|
||||
|
||||
cy.get('#usersWrapper [data-test=user-card]:nth-child(2) [data-test=delete-user-btn]').click({ force: true })
|
||||
cy.$confirm()
|
||||
cy.findByText('User "Alice" deleted.').should('be.visible')
|
||||
cy.get('#usersWrapper [data-test=user-card]').should('have.length', 2)
|
||||
})
|
||||
})
|
|
@ -1 +1 @@
|
|||
Subproject commit a1e24168a3bf83cb3ca4d99de0b09806fc1bfac9
|
||||
Subproject commit 68a91c872839cc73dc341b24d68c2b927fc6a911
|
Loading…
Reference in a new issue