Changeset View
Changeset View
Standalone View
Standalone View
cypress/e2e/add-forge-now-requests-moderation.cy.js
/** | /** | ||||
* Copyright (C) 2022 The Software Heritage developers | * Copyright (C) 2022 The Software Heritage developers | ||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
const defaultRedirect = '/login/'; | |||||
let addForgeModerationUrl; | |||||
let listAddForgeRequestsUrl; | |||||
function logout() { | function logout() { | ||||
cy.contains('a', 'logout') | cy.contains('a', 'logout') | ||||
.click(); | .click(); | ||||
} | } | ||||
describe('Test "Add Forge Now" moderation Login/logout', function() { | describe('Test "Add Forge Now" moderation Login/logout', function() { | ||||
before(function() { | beforeEach(function() { | ||||
addForgeModerationUrl = this.Urls.add_forge_now_requests_moderation(); | this.addForgeModerationUrl = this.Urls.add_forge_now_requests_moderation(); | ||||
}); | }); | ||||
it('should redirect to default page', function() { | it('should redirect to default page', function() { | ||||
cy.visit(addForgeModerationUrl) | cy.visit(this.addForgeModerationUrl) | ||||
.get('input[name="username"]') | .get('input[name="username"]') | ||||
.type('admin') | .type('admin') | ||||
.get('input[name="password"]') | .get('input[name="password"]') | ||||
.type('admin') | .type('admin') | ||||
.get('.container form') | .get('.container form') | ||||
.submit(); | .submit(); | ||||
cy.location('pathname') | cy.location('pathname') | ||||
.should('be.equal', addForgeModerationUrl); | .should('be.equal', this.addForgeModerationUrl); | ||||
}); | }); | ||||
it('should redirect to correct page after login', function() { | it('should redirect to correct page after login', function() { | ||||
cy.visit(addForgeModerationUrl) | cy.visit(this.addForgeModerationUrl) | ||||
.location('pathname') | .location('pathname') | ||||
.should('be.equal', defaultRedirect); | .should('be.equal', this.Urls.login()); | ||||
cy.adminLogin(); | cy.adminLogin(); | ||||
cy.visit(addForgeModerationUrl) | cy.visit(this.addForgeModerationUrl) | ||||
.location('pathname') | .location('pathname') | ||||
.should('be.equal', addForgeModerationUrl); | .should('be.equal', this.addForgeModerationUrl); | ||||
logout(); | logout(); | ||||
}); | }); | ||||
it('should not display moderation link in sidebar when anonymous', function() { | it('should not display moderation link in sidebar when anonymous', function() { | ||||
cy.visit(addForgeModerationUrl); | cy.visit(this.addForgeModerationUrl); | ||||
cy.get(`.sidebar a[href="${addForgeModerationUrl}"]`) | cy.get(`.sidebar a[href="${this.addForgeModerationUrl}"]`) | ||||
.should('not.exist'); | .should('not.exist'); | ||||
}); | }); | ||||
it('should not display moderation link when connected as unprivileged user', function() { | it('should not display moderation link when connected as unprivileged user', function() { | ||||
cy.userLogin(); | cy.userLogin(); | ||||
cy.visit(addForgeModerationUrl); | cy.visit(this.addForgeModerationUrl); | ||||
cy.get(`.sidebar a[href="${addForgeModerationUrl}"]`) | cy.get(`.sidebar a[href="${this.addForgeModerationUrl}"]`) | ||||
.should('not.exist'); | .should('not.exist'); | ||||
}); | }); | ||||
it('should display moderation link in sidebar when connected as privileged user', function() { | it('should display moderation link in sidebar when connected as privileged user', function() { | ||||
cy.addForgeModeratorLogin(); | cy.addForgeModeratorLogin(); | ||||
cy.visit(addForgeModerationUrl); | cy.visit(this.addForgeModerationUrl); | ||||
cy.get(`.sidebar a[href="${addForgeModerationUrl}"]`) | cy.get(`.sidebar a[href="${this.addForgeModerationUrl}"]`) | ||||
.should('exist'); | .should('exist'); | ||||
}); | }); | ||||
it('should display moderation link in sidebar when connected as staff member', function() { | it('should display moderation link in sidebar when connected as staff member', function() { | ||||
cy.adminLogin(); | cy.adminLogin(); | ||||
cy.visit(addForgeModerationUrl); | cy.visit(this.addForgeModerationUrl); | ||||
cy.get(`.sidebar a[href="${addForgeModerationUrl}"]`) | cy.get(`.sidebar a[href="${this.addForgeModerationUrl}"]`) | ||||
.should('exist'); | .should('exist'); | ||||
}); | }); | ||||
}); | }); | ||||
describe('Test "Add Forge Now" moderation listing', function() { | describe('Test "Add Forge Now" moderation listing', function() { | ||||
before(function() { | beforeEach(function() { | ||||
addForgeModerationUrl = this.Urls.add_forge_now_requests_moderation(); | this.addForgeModerationUrl = this.Urls.add_forge_now_requests_moderation(); | ||||
listAddForgeRequestsUrl = this.Urls.add_forge_request_list_datatables(); | this.listAddForgeRequestsUrl = this.Urls.add_forge_request_list_datatables(); | ||||
}); | }); | ||||
it('should list add-forge-now requests', function() { | it('should list add-forge-now requests', function() { | ||||
cy.intercept(`${listAddForgeRequestsUrl}**`, {fixture: 'add-forge-now-requests'}).as('listRequests'); | cy.intercept(`${this.listAddForgeRequestsUrl}**`, {fixture: 'add-forge-now-requests'}).as('listRequests'); | ||||
let expectedRequests; | let expectedRequests; | ||||
cy.readFile('cypress/fixtures/add-forge-now-requests.json').then((result) => { | cy.readFile('cypress/fixtures/add-forge-now-requests.json').then((result) => { | ||||
expectedRequests = result['data']; | expectedRequests = result['data']; | ||||
}); | }); | ||||
cy.addForgeModeratorLogin(); | cy.addForgeModeratorLogin(); | ||||
cy.visit(addForgeModerationUrl); | cy.visit(this.addForgeModerationUrl); | ||||
cy.get('.swh-add-forge-now-moderation-item') | cy.get('.swh-add-forge-now-moderation-item') | ||||
.should('have.class', 'active'); | .should('have.class', 'active'); | ||||
cy.wait('@listRequests').then((xhr) => { | cy.wait('@listRequests').then((xhr) => { | ||||
cy.log('response:', xhr.response); | cy.log('response:', xhr.response); | ||||
cy.log(xhr.response.body); | cy.log(xhr.response.body); | ||||
const requests = xhr.response.body.data; | const requests = xhr.response.body.data; | ||||
Show All 21 Lines |