Skip to content

Commit

Permalink
Fix bug in WikiProject builder frontend, add test, tweak tests
Browse files Browse the repository at this point in the history
  • Loading branch information
audiodude committed May 4, 2024
1 parent 0c6b468 commit 5689513
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
29 changes: 28 additions & 1 deletion wp1-frontend/cypress/e2e/createWikiProjectList.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
42 changes: 29 additions & 13 deletions wp1-frontend/cypress/e2e/updateWikiProjectList.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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',
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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');
});
Expand Down
2 changes: 1 addition & 1 deletion wp1-frontend/cypress/fixtures/wikiproject_builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
],
"exclude": ["Countries"]
},
"name": "Builder 1",
"name": "Builder 3",
"model": "wp1.selection.models.wikiproject",
"project": "en.wikipedia.org",
"selection_errors": []
Expand Down
2 changes: 1 addition & 1 deletion wp1-frontend/src/components/WikiProjectBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5689513

Please sign in to comment.