diff --git a/cypress/e2e/add-forge-now-request-dashboard.cy.js b/cypress/e2e/add-forge-now-request-dashboard.cy.js --- a/cypress/e2e/add-forge-now-request-dashboard.cy.js +++ b/cypress/e2e/add-forge-now-request-dashboard.cy.js @@ -89,19 +89,16 @@ describe('Test add forge now request dashboard load', function() { - before(function() { - // Create an add-forge-request object in the DB - createDummyRequest(this.Urls); - }); - beforeEach(function() { - const url = this.Urls.add_forge_now_request_dashboard(requestId); - // request dashboard require admin permissions to view - cy.adminLogin(); - cy.intercept(`${this.Urls.api_1_add_forge_request_get(requestId)}**`).as('forgeRequestGet'); - cy.visit(url); - cy.get('.swh-add-forge-now-moderation-item') - .should('have.class', 'active'); + createDummyRequest(this.Urls).then(() => { + const url = this.Urls.add_forge_now_request_dashboard(requestId); + // request dashboard require admin permissions to view + cy.adminLogin(); + cy.intercept(`${this.Urls.api_1_add_forge_request_get(requestId)}**`).as('forgeRequestGet'); + cy.visit(url); + cy.get('.swh-add-forge-now-moderation-item') + .should('have.class', 'active'); + }); }); it('should load add forge request details', function() { diff --git a/cypress/e2e/add-forge-now-requests-moderation.cy.js b/cypress/e2e/add-forge-now-requests-moderation.cy.js --- a/cypress/e2e/add-forge-now-requests-moderation.cy.js +++ b/cypress/e2e/add-forge-now-requests-moderation.cy.js @@ -5,23 +5,18 @@ * See top-level LICENSE file for more information */ -const defaultRedirect = '/login/'; - -let addForgeModerationUrl; -let listAddForgeRequestsUrl; - function logout() { cy.contains('a', 'logout') .click(); } describe('Test "Add Forge Now" moderation Login/logout', function() { - before(function() { - addForgeModerationUrl = this.Urls.add_forge_now_requests_moderation(); + beforeEach(function() { + this.addForgeModerationUrl = this.Urls.add_forge_now_requests_moderation(); }); it('should redirect to default page', function() { - cy.visit(addForgeModerationUrl) + cy.visit(this.addForgeModerationUrl) .get('input[name="username"]') .type('admin') .get('input[name="password"]') @@ -30,62 +25,62 @@ .submit(); cy.location('pathname') - .should('be.equal', addForgeModerationUrl); + .should('be.equal', this.addForgeModerationUrl); }); it('should redirect to correct page after login', function() { - cy.visit(addForgeModerationUrl) + cy.visit(this.addForgeModerationUrl) .location('pathname') - .should('be.equal', defaultRedirect); + .should('be.equal', this.Urls.login()); cy.adminLogin(); - cy.visit(addForgeModerationUrl) + cy.visit(this.addForgeModerationUrl) .location('pathname') - .should('be.equal', addForgeModerationUrl); + .should('be.equal', this.addForgeModerationUrl); logout(); }); it('should not display moderation link in sidebar when anonymous', function() { - cy.visit(addForgeModerationUrl); - cy.get(`.sidebar a[href="${addForgeModerationUrl}"]`) + cy.visit(this.addForgeModerationUrl); + cy.get(`.sidebar a[href="${this.addForgeModerationUrl}"]`) .should('not.exist'); }); it('should not display moderation link when connected as unprivileged user', function() { 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'); }); it('should display moderation link in sidebar when connected as privileged user', function() { cy.addForgeModeratorLogin(); - cy.visit(addForgeModerationUrl); + cy.visit(this.addForgeModerationUrl); - cy.get(`.sidebar a[href="${addForgeModerationUrl}"]`) + cy.get(`.sidebar a[href="${this.addForgeModerationUrl}"]`) .should('exist'); }); it('should display moderation link in sidebar when connected as staff member', function() { cy.adminLogin(); - cy.visit(addForgeModerationUrl); + cy.visit(this.addForgeModerationUrl); - cy.get(`.sidebar a[href="${addForgeModerationUrl}"]`) + cy.get(`.sidebar a[href="${this.addForgeModerationUrl}"]`) .should('exist'); }); }); describe('Test "Add Forge Now" moderation listing', function() { - before(function() { - addForgeModerationUrl = this.Urls.add_forge_now_requests_moderation(); - listAddForgeRequestsUrl = this.Urls.add_forge_request_list_datatables(); + beforeEach(function() { + this.addForgeModerationUrl = this.Urls.add_forge_now_requests_moderation(); + this.listAddForgeRequestsUrl = this.Urls.add_forge_request_list_datatables(); }); 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; cy.readFile('cypress/fixtures/add-forge-now-requests.json').then((result) => { @@ -93,7 +88,7 @@ }); cy.addForgeModeratorLogin(); - cy.visit(addForgeModerationUrl); + cy.visit(this.addForgeModerationUrl); cy.get('.swh-add-forge-now-moderation-item') .should('have.class', 'active'); diff --git a/cypress/e2e/admin.cy.js b/cypress/e2e/admin.cy.js --- a/cypress/e2e/admin.cy.js +++ b/cypress/e2e/admin.cy.js @@ -7,22 +7,18 @@ const $ = Cypress.$; -const defaultRedirect = '/'; - -let url; - function logout() { cy.contains('a', 'logout') .click(); } describe('Test Admin Login/logout', function() { - before(function() { - url = this.Urls.login(); + beforeEach(function() { + this.url = this.Urls.login(); }); it('should redirect to default page', function() { - cy.visit(url) + cy.visit(this.url) .get('input[name="username"]') .type('admin') .get('input[name="password"]') @@ -31,14 +27,14 @@ .submit(); cy.location('pathname') - .should('be.equal', defaultRedirect); + .should('be.equal', this.Urls.swh_web_homepage()); logout(); }); it('should display admin-origin-save and deposit in sidebar', function() { cy.adminLogin(); - cy.visit(url); + cy.visit(this.url); cy.get(`.sidebar a[href="${this.Urls.admin_origin_save_requests()}"]`) .should('be.visible'); @@ -51,7 +47,7 @@ it('should display username on top-right', function() { cy.adminLogin(); - cy.visit(url); + cy.visit(this.url); cy.get('.swh-position-right') .should('contain', 'admin'); @@ -64,12 +60,12 @@ expect(win.swh.webapp.isUserLoggedIn()).to.be.false; }); cy.adminLogin(); - cy.visit(url); + cy.visit(this.url); cy.window().then(win => { expect(win.swh.webapp.isUserLoggedIn()).to.be.true; }); logout(); - cy.visit(url); + cy.visit(this.url); cy.window().then(win => { expect(win.swh.webapp.isUserLoggedIn()).to.be.false; });