Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from unikubehq/project-form-test
tests: tests for project form
- Loading branch information
Showing
5 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import project from '../../fixtures/projects/cypressProject.json'; | ||
|
||
describe('ProjectDetail', () => { | ||
beforeEach(() => { | ||
cy.viewport('macbook-15'); | ||
cy.setupInterceptors(); | ||
cy.login(true, false, true); | ||
cy.visit('/overview'); | ||
cy.get('.projects__createButton').first().click(); | ||
cy.get('[name=projectName]').type('Some project name'); | ||
cy.get('[name=specRepo]').type('https://github.com/unikubehq/frontend'); | ||
}); | ||
|
||
it('Does not submit project id when in creation mode', () => { | ||
cy.intercept('POST', '/graphql', (req) => { | ||
if (req.body.operationName === 'CreateProject') { | ||
expect(req.body.variables).to.not.have.any.key('id'); | ||
} | ||
}); | ||
cy.get('.projectForm__submit').click(); | ||
}); | ||
|
||
it('Refreshes token after project creation', () => { | ||
cy.intercept('POST', '/graphql', (req) => { | ||
if (req.body.operationName === 'CreateProject') { | ||
req.reply({ | ||
data: project, | ||
}); | ||
} | ||
}); | ||
cy.get('.projectForm__submit').click(); | ||
cy.get('@updateToken').should('have.been.called'); | ||
}); | ||
|
||
it('Continues to add member form when creation was successful.', () => { | ||
cy.intercept('POST', '/graphql', (req) => { | ||
if (req.body.operationName === 'CreateProject') { | ||
req.reply({ | ||
data: { | ||
createUpdateProject: project, | ||
}, | ||
}); | ||
} | ||
}); | ||
cy.get('.projectForm__submit').click(); | ||
cy.get('@updateToken').should('have.been.called'); | ||
cy.location('pathname').should('contain', '/add-members'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { GraphQLError } from 'graphql'; | ||
import project from '../../fixtures/projects/cypressProject.json'; | ||
|
||
describe('ProjectDetail', () => { | ||
beforeEach(() => { | ||
cy.viewport('macbook-15'); | ||
cy.setupInterceptors(); | ||
cy.login(true, false, true); | ||
cy.visit('/overview'); | ||
cy.wait('@ProjectsQuery'); | ||
cy.intercept('POST', '/graphql', (req) => { | ||
if (req.body.operationName === 'ProjectDetailQuery') { | ||
// eslint-disable-next-line no-param-reassign | ||
req.alias = 'ProjectDetailQuery'; | ||
req.reply({ | ||
data: project, | ||
}); | ||
} | ||
}); | ||
cy.get('.project-card__wrapper .project-card__edit').first().click(); | ||
cy.location('pathname').should('contain', '/project/'); | ||
cy.wait('@ProjectDetailQuery'); | ||
}); | ||
|
||
it('Submits access token only when changed', () => { | ||
cy.intercept('POST', '/graphql', (req) => { | ||
if (req.body.operationName === 'UpdateProject') { | ||
expect(req.body.variables).to.not.have.any.key('accessToken'); | ||
} | ||
}); | ||
cy.get('.projectForm__submit').click(); | ||
}); | ||
|
||
it('Submits project id when in edit mode', () => { | ||
cy.intercept('POST', '/graphql', (req) => { | ||
if (req.body.operationName === 'UpdateProject') { | ||
expect(req.body.variables).to.have.any.key('id'); | ||
} | ||
}); | ||
cy.get('.projectForm__submit').click(); | ||
}); | ||
|
||
it('Continues to overview when project was edited.', () => { | ||
cy.intercept('POST', '/graphql', (req) => { | ||
if (req.body.operationName === 'UpdateProject') { | ||
req.reply({ | ||
data: { | ||
createUpdateProject: project, | ||
}, | ||
}); | ||
} | ||
}); | ||
cy.get('.projectForm__submit').click(); | ||
cy.location('pathname').should('contain', '/overview'); | ||
}); | ||
|
||
it('Prefills form when in edit mode', () => { | ||
cy.get('[name=projectName]').should('have.value', project.project.title); | ||
cy.get('[name=specRepo]').should('have.value', project.project.specRepository); | ||
}); | ||
it('Disables submit button when form is invalid', () => { | ||
cy.get('.projectForm__submit').should('not.be.disabled'); | ||
cy.get('[name=projectName]').clear(); | ||
cy.get('.projectForm__submit').should('be.disabled'); | ||
}); | ||
|
||
it('Displays input field errors', () => { | ||
cy.get('[name=projectName]').clear().blur().parents('.v-input__control') | ||
.find('.v-messages__message') | ||
.should('contain.text', 'This field is required.'); | ||
}); | ||
|
||
it('Displays submission error when something went wrong', () => { | ||
const errorMessage = 'Something went wrong'; | ||
cy.intercept('POST', '/graphql', (req) => { | ||
if (req.body.operationName === 'UpdateProject') { | ||
req.reply(200, { errors: [new GraphQLError(errorMessage)] }); | ||
} | ||
}); | ||
cy.get('.projectForm__submit').click(); | ||
cy.get('.v-alert__content').should('contain.text', errorMessage); | ||
}); | ||
}); |