Changeset View
Changeset View
Standalone View
Standalone View
cypress/e2e/add-forge-now-request-create.cy.js
Show All 37 Lines | describe('Browse requests list tests', function() { | ||||
it('should only display user requests when filter is activated', function() { | it('should only display user requests when filter is activated', function() { | ||||
// Clean up previous state | // Clean up previous state | ||||
cy.task('db:add_forge_now:delete'); | cy.task('db:add_forge_now:delete'); | ||||
// 'user2' logs in and create requests | // 'user2' logs in and create requests | ||||
cy.user2Login(); | cy.user2Login(); | ||||
cy.visit(this.addForgeNowUrl); | cy.visit(this.addForgeNowUrl); | ||||
// create requests for the user 'user' | // create requests for the user 'user' | ||||
populateForm('gitlab', 'gitlab.org', 'admin', 'admin@example.org', 'on', ''); | populateForm('gitlab', 'https://gitlab.org', 'admin', 'admin@example.org', 'on', ''); | ||||
cy.get('#requestCreateForm').submit(); | cy.get('#requestCreateForm').submit(); | ||||
// user requests filter checkbox should be in the DOM | // user requests filter checkbox should be in the DOM | ||||
cy.get('#swh-add-forge-requests-list-tab').click(); | cy.get('#swh-add-forge-requests-list-tab').click(); | ||||
cy.get('#swh-add-forge-user-filter').should('exist').should('be.checked'); | cy.get('#swh-add-forge-user-filter').should('exist').should('be.checked'); | ||||
// check unfiltered user requests | // check unfiltered user requests | ||||
cy.get('tbody tr').then(rows => { | cy.get('tbody tr').then(rows => { | ||||
expect(rows.length).to.eq(1); | expect(rows.length).to.eq(1); | ||||
}); | }); | ||||
// user1 logout | // user1 logout | ||||
cy.contains('a', 'logout').click(); | cy.contains('a', 'logout').click(); | ||||
// user logs in | // user logs in | ||||
cy.userLogin(); | cy.userLogin(); | ||||
cy.visit(this.addForgeNowUrl); | cy.visit(this.addForgeNowUrl); | ||||
populateForm('gitea', 'gitea.org', 'admin', 'admin@example.org', 'on', ''); | populateForm('gitea', 'https://gitea.org', 'admin', 'admin@example.org', 'on', ''); | ||||
cy.get('#requestCreateForm').submit(); | cy.get('#requestCreateForm').submit(); | ||||
populateForm('cgit', 'cgit.org', 'admin', 'admin@example.org', 'on', ''); | populateForm('cgit', 'https://cgit.org', 'admin', 'admin@example.org', 'on', ''); | ||||
cy.get('#requestCreateForm').submit(); | cy.get('#requestCreateForm').submit(); | ||||
// user requests filter checkbox should be in the DOM | // user requests filter checkbox should be in the DOM | ||||
cy.get('#swh-add-forge-requests-list-tab').click(); | cy.get('#swh-add-forge-requests-list-tab').click(); | ||||
cy.get('#swh-add-forge-user-filter').should('exist').should('be.checked'); | cy.get('#swh-add-forge-user-filter').should('exist').should('be.checked'); | ||||
// check unfiltered user requests | // check unfiltered user requests | ||||
cy.get('tbody tr').then(rows => { | cy.get('tbody tr').then(rows => { | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | it('should show browse requests table for every user', function() { | ||||
cy.get('#loginLink') | cy.get('#loginLink') | ||||
.should('not.exist'); | .should('not.exist'); | ||||
}); | }); | ||||
it('should update browse list on successful submission', function() { | it('should update browse list on successful submission', function() { | ||||
cy.userLogin(); | cy.userLogin(); | ||||
cy.visit(this.addForgeNowUrl); | cy.visit(this.addForgeNowUrl); | ||||
populateForm('bitbucket', 'gitlab.com', 'test', 'test@example.com', 'on', 'test comment'); | populateForm('bitbucket', 'https://gitlab.com', 'test', 'test@example.com', 'on', 'test comment'); | ||||
cy.get('#requestCreateForm').submit(); | cy.get('#requestCreateForm').submit(); | ||||
cy.visit(this.addForgeNowUrl); | cy.visit(this.addForgeNowUrl); | ||||
cy.get('#swh-add-forge-requests-list-tab').click(); | cy.get('#swh-add-forge-requests-list-tab').click(); | ||||
cy.get('#add-forge-request-browse') | cy.get('#add-forge-request-browse') | ||||
.should('be.visible') | .should('be.visible') | ||||
.should('contain', 'gitlab.com'); | .should('contain', 'gitlab.com'); | ||||
cy.get('#add-forge-request-browse') | cy.get('#add-forge-request-browse') | ||||
.should('be.visible') | .should('be.visible') | ||||
.should('contain', 'Pending'); | .should('contain', 'Pending'); | ||||
}); | }); | ||||
it('should show error message on conflict', function() { | it('should show error message on conflict', function() { | ||||
cy.userLogin(); | cy.userLogin(); | ||||
cy.visit(this.addForgeNowUrl); | cy.visit(this.addForgeNowUrl); | ||||
populateForm('bitbucket', 'gitlab.com', 'test', 'test@example.com', 'on', 'test comment'); | populateForm('bitbucket', 'https://gitlab.com', 'test', 'test@example.com', 'on', 'test comment'); | ||||
cy.get('#requestCreateForm').submit(); | cy.get('#requestCreateForm').submit(); | ||||
cy.get('#requestCreateForm').submit(); // Submitting the same data again | cy.get('#requestCreateForm').submit(); // Submitting the same data again | ||||
cy.get('#userMessage') | cy.get('#userMessage') | ||||
.should('have.class', 'badge-danger') | .should('have.class', 'badge-danger') | ||||
.should('contain', 'already exists'); | .should('contain', 'already exists'); | ||||
}); | }); | ||||
it('should show error message', function() { | it('should show error message', function() { | ||||
cy.userLogin(); | cy.userLogin(); | ||||
cy.intercept('POST', `${this.Urls.api_1_add_forge_request_create()}**`, | cy.intercept('POST', `${this.Urls.api_1_add_forge_request_create()}**`, | ||||
{ | { | ||||
body: { | body: { | ||||
'exception': 'BadInputExc', | 'exception': 'BadInputExc', | ||||
'reason': '{"add-forge-comment": ["This field is required"]}' | 'reason': '{"add-forge-comment": ["This field is required"]}' | ||||
}, | }, | ||||
statusCode: 400 | statusCode: 400 | ||||
}).as('errorRequest'); | }).as('errorRequest'); | ||||
cy.visit(this.addForgeNowUrl); | cy.visit(this.addForgeNowUrl); | ||||
populateForm( | populateForm( | ||||
'bitbucket', 'gitlab.com', 'test', 'test@example.com', 'off', 'comment' | 'bitbucket', 'https://gitlab.com', 'test', 'test@example.com', 'off', 'comment' | ||||
); | ); | ||||
cy.get('#requestCreateForm').submit(); | cy.get('#requestCreateForm').submit(); | ||||
cy.wait('@errorRequest').then((xhr) => { | cy.wait('@errorRequest').then((xhr) => { | ||||
cy.get('#userMessage') | cy.get('#userMessage') | ||||
.should('have.class', 'badge-danger') | .should('have.class', 'badge-danger') | ||||
.should('contain', 'field is required'); | .should('contain', 'field is required'); | ||||
}); | }); | ||||
}); | }); | ||||
it('should bot validate form when forge URL is invalid', function() { | |||||
cy.userLogin(); | |||||
cy.visit(this.addForgeNowUrl); | |||||
populateForm('bitbucket', 'bitbucket.org', 'test', 'test@example.com', 'on', 'test comment'); | |||||
cy.get('#requestCreateForm').submit(); | |||||
cy.get('#swh-input-forge-url') | |||||
.then(input => { | |||||
assert.isFalse(input[0].checkValidity()); | |||||
}); | |||||
}); | |||||
}); | }); |