From 568951335c93469af707b7dd7c04efd9043f986d Mon Sep 17 00:00:00 2001 From: Travis Briggs Date: Sat, 4 May 2024 10:34:12 +0200 Subject: [PATCH] Fix bug in WikiProject builder frontend, add test, tweak tests --- .../cypress/e2e/createWikiProjectList.cy.js | 29 ++++++++++++- .../cypress/e2e/updateWikiProjectList.cy.js | 42 +++++++++++++------ .../cypress/fixtures/wikiproject_builder.json | 2 +- .../src/components/WikiProjectBuilder.vue | 2 +- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/wp1-frontend/cypress/e2e/createWikiProjectList.cy.js b/wp1-frontend/cypress/e2e/createWikiProjectList.cy.js index a4f50f39..1e1bc90f 100644 --- a/wp1-frontend/cypress/e2e/createWikiProjectList.cy.js +++ b/wp1-frontend/cypress/e2e/createWikiProjectList.cy.js @@ -114,10 +114,37 @@ describe('the create WikiProject builder page', () => { cy.get('#listName > .form-control').type('List Name'); cy.get('#include-items').click(); cy.get('#include-items').type('Fake Project\nAnother Fake'); - cy.intercept('v1/builders/', { fixture: 'save_list_success.json' }); + cy.intercept('v1/builders/', { fixture: 'save_list_success.json' }).as( + 'createBuilderSuccess', + ); cy.get('#saveListButton').click(); + cy.wait('@createBuilderSuccess'); cy.url().should('eq', 'http://localhost:5173/#/selections/user'); }); + + it('sends correct data to API', () => { + cy.get('#listName > .form-control').click(); + cy.get('#listName > .form-control').type('List Name'); + cy.get('#include-items').click(); + cy.get('#include-items').type('Fake Project\nAnother Fake Project'); + cy.get('#exclude-items').click(); + cy.get('#exclude-items').type('Even Faker Project\nMost Fake Project'); + + cy.intercept('v1/builders/', { fixture: 'save_list_success.json' }).as( + 'createBuilderSuccess', + ); + cy.get('#saveListButton').click(); + cy.wait('@createBuilderSuccess').then((interception) => { + expect(interception.request.body.params.include).to.deep.equal([ + 'Fake Project', + 'Another Fake Project', + ]); + expect(interception.request.body.params.exclude).to.deep.equal([ + 'Even Faker Project', + 'Most Fake Project', + ]); + }); + }); }); describe('when the user is not logged in', () => { diff --git a/wp1-frontend/cypress/e2e/updateWikiProjectList.cy.js b/wp1-frontend/cypress/e2e/updateWikiProjectList.cy.js index 262589e8..10269b4d 100644 --- a/wp1-frontend/cypress/e2e/updateWikiProjectList.cy.js +++ b/wp1-frontend/cypress/e2e/updateWikiProjectList.cy.js @@ -11,10 +11,10 @@ describe('the update wikiproject list page', () => { describe('and the builder is found', () => { beforeEach(() => { - cy.intercept('GET', 'v1/builders/1', { + cy.intercept('GET', 'v1/builders/3', { fixture: 'wikiproject_builder.json', }).as('builder'); - cy.visit('/#/selections/wikiproject/1'); + cy.visit('/#/selections/wikiproject/3'); cy.wait('@sites'); cy.wait('@identity'); cy.wait('@builder'); @@ -28,7 +28,7 @@ describe('the update wikiproject list page', () => { }); it('displays builder information', () => { - cy.get('#listName > .form-control').should('have.value', 'Builder 1'); + cy.get('#listName > .form-control').should('have.value', 'Builder 3'); cy.get('#include-items').should( 'have.value', 'British Columbia road transport\nNew Brunswick road transport', @@ -45,7 +45,7 @@ describe('the update wikiproject list page', () => { }); it('displays a textbox with invalid project names', () => { - cy.intercept('v1/builders/1', { + cy.intercept('v1/builders/3', { fixture: 'save_wikiproject_failure.json', }); cy.get('#updateListButton').click(); @@ -56,8 +56,24 @@ describe('the update wikiproject list page', () => { ); }); + it('sends correct data to API', () => { + cy.intercept('v1/builders/3', { fixture: 'save_list_success.json' }).as( + 'updateBuilderSuccess', + ); + cy.get('#updateListButton').click(); + cy.wait('@updateBuilderSuccess').then((interception) => { + expect(interception.request.body.params.include).to.deep.equal([ + 'British Columbia road transport', + 'New Brunswick road transport', + ]); + expect(interception.request.body.params.exclude).to.deep.equal([ + 'Countries', + ]); + }); + }); + it('redirects on saving valid project names', () => { - cy.intercept('POST', 'v1/builders/1', { + cy.intercept('POST', 'v1/builders/3', { fixture: 'save_list_success.json', }); cy.get('#updateListButton').click(); @@ -66,7 +82,7 @@ describe('the update wikiproject list page', () => { describe('when update button clicked', () => { beforeEach(() => { - cy.intercept('POST', 'v1/builders/1', (req) => { + cy.intercept('POST', 'v1/builders/3', (req) => { req.continue(() => { return new Promise((resolve) => { setTimeout(resolve, 4000); @@ -89,10 +105,10 @@ describe('the update wikiproject list page', () => { describe('and the builder has fatal errors', () => { beforeEach(() => { - cy.intercept('GET', 'v1/builders/1', { + cy.intercept('GET', 'v1/builders/3', { fixture: 'wikiproject_builder_fatal_error.json', }); - cy.visit('/#/selections/wikiproject/1'); + cy.visit('/#/selections/wikiproject/3'); }); it('displays the error div', () => { @@ -106,10 +122,10 @@ describe('the update wikiproject list page', () => { describe('and the builder has retryable errors', () => { beforeEach(() => { - cy.intercept('GET', 'v1/builders/1', { + cy.intercept('GET', 'v1/builders/3', { fixture: 'wikiproject_builder_retryable_error.json', }); - cy.visit('/#/selections/wikiproject/1'); + cy.visit('/#/selections/wikiproject/3'); }); it('displays the error div', () => { @@ -123,11 +139,11 @@ describe('the update wikiproject list page', () => { describe('and the builder is not found', () => { beforeEach(() => { - cy.intercept('GET', 'v1/builders/1', { + cy.intercept('GET', 'v1/builders/3', { statusCode: 404, body: '404 NOT FOUND', }); - cy.visit('/#/selections/wikiproject/1'); + cy.visit('/#/selections/wikiproject/3'); }); it('displays the 404 text', () => { @@ -142,7 +158,7 @@ describe('the update wikiproject list page', () => { }); it('opens login page', () => { - cy.visit('/#/selections/wikiproject/1'); + cy.visit('/#/selections/wikiproject/3'); cy.contains('Please Log In To Continue'); cy.get('.pt-2 > .btn'); }); diff --git a/wp1-frontend/cypress/fixtures/wikiproject_builder.json b/wp1-frontend/cypress/fixtures/wikiproject_builder.json index c6019dea..da85933a 100644 --- a/wp1-frontend/cypress/fixtures/wikiproject_builder.json +++ b/wp1-frontend/cypress/fixtures/wikiproject_builder.json @@ -6,7 +6,7 @@ ], "exclude": ["Countries"] }, - "name": "Builder 1", + "name": "Builder 3", "model": "wp1.selection.models.wikiproject", "project": "en.wikipedia.org", "selection_errors": [] diff --git a/wp1-frontend/src/components/WikiProjectBuilder.vue b/wp1-frontend/src/components/WikiProjectBuilder.vue index b098a8f1..f8afc668 100644 --- a/wp1-frontend/src/components/WikiProjectBuilder.vue +++ b/wp1-frontend/src/components/WikiProjectBuilder.vue @@ -81,7 +81,7 @@ export default { }, watch: { includeText: function () { - const include = this.excludeText.split('\n'); + const include = this.includeText.split('\n'); if (include.length === 1 && include[0] === '') { this.params.include = []; return;