Skip to content

Commit

Permalink
Update frontend for new Builder terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
audiodude committed May 3, 2024
1 parent c1aa031 commit 7c92ea9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 39 deletions.
19 changes: 11 additions & 8 deletions wp1-frontend/cypress/e2e/createWikiProjectList.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,27 @@ describe('the create WikiProject builder page', () => {
it('validates textbox on clicking save', () => {
cy.get('#saveListButton').click();
cy.get('#listName > .invalid-feedback').should('be.visible');
cy.get('#add-items ~ .invalid-feedback').should('be.visible');
cy.get('#include-items ~ .invalid-feedback').should('be.visible');
});

it('validates list name on losing focus', () => {
cy.get('#listName > .form-control').click();
cy.get('#add-items').click();
cy.get('#include-items').click();
cy.get('#listName > .invalid-feedback').should('be.visible');
});

it('displays a textbox with invalid wikiProjects', () => {
cy.get('#listName > .form-control').click().type('List name');
cy.get('#add-items').click().type('Fake Project 1\nAnother Fake');
cy.get('#include-items').click().type('Fake Project 1\nAnother Fake');
cy.intercept('v1/builders/', {
fixture: 'save_wikiproject_failure.json',
});
cy.get('#saveListButton').click();

cy.get('#add-items').should('have.value', 'Fake Project 1\nAnother Fake');
cy.get('#include-items').should(
'have.value',
'Fake Project 1\nAnother Fake',
);
cy.get('#invalid_articles > .form-control').should(
'have.value',
'Fake Project 1\nAnother Fake',
Expand All @@ -66,7 +69,7 @@ describe('the create WikiProject builder page', () => {
});

cy.get('#listName > .form-control').click().type('List Name');
cy.get('#add-items').click().type('Fake Project 1\nAnother Fake');
cy.get('#include-items').click().type('Fake Project 1\nAnother Fake');
cy.get('#saveListButton').click();
cy.get('#saveListButton').click();
cy.url().should('eq', 'http://localhost:5173/#/selections/user');
Expand All @@ -85,22 +88,22 @@ describe('the create WikiProject builder page', () => {

it('shows spinner', () => {
cy.get('#listName > .form-control').click().type('List Name');
cy.get('#add-items').click().type('Fake Project');
cy.get('#include-items').click().type('Fake Project');
cy.get('#saveListButton').click();
cy.get('#saveLoader').should('be.visible');
});

it('disables save button', () => {
cy.get('#listName > .form-control').click().type('List Name');
cy.get('#add-items').click().type('Fake Project');
cy.get('#include-items').click().type('Fake Project');
cy.get('#saveListButton').click();
cy.get('#saveListButton').should('have.attr', 'disabled');
});
});

it('redirects on saving valid project names', () => {
cy.get('#listName > .form-control').click().type('List Name');
cy.get('#add-items').click().type('Fake Project\nAnother Fake');
cy.get('#include-items').click().type('Fake Project\nAnother Fake');
cy.intercept('v1/builders/', { fixture: 'save_list_success.json' });
cy.get('#saveListButton').click();
cy.url().should('eq', 'http://localhost:5173/#/selections/user');
Expand Down
4 changes: 2 additions & 2 deletions wp1-frontend/cypress/e2e/updateWikiProjectList.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ describe('the update wikiproject list page', () => {

it('displays builder information', () => {
cy.get('#listName > .form-control').should('have.value', 'Builder 1');
cy.get('#add-items').should(
cy.get('#include-items').should(
'have.value',
'British Columbia road transport\nNew Brunswick road transport',
);
cy.get('#project > select').should('have.value', 'en.wikipedia.org');
});

it('does not show invalid list items', () => {
cy.get('#add-items ~ .invalid-feedback').should('not.be.visible');
cy.get('#include-items ~ .invalid-feedback').should('not.be.visible');
});

it('does not show invalid list name', () => {
Expand Down
7 changes: 5 additions & 2 deletions wp1-frontend/cypress/fixtures/wikiproject_builder.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"params": {
"add": ["British Columbia road transport", "New Brunswick road transport"],
"subtract": ["Countries"]
"include": [
"British Columbia road transport",
"New Brunswick road transport"
],
"exclude": ["Countries"]
},
"name": "Builder 1",
"model": "wp1.selection.models.wikiproject",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"params": {
"add": ["British Columbia road transport", "New Brunswick road transport"],
"subtract": ["Countries"]
"include": [
"British Columbia road transport",
"New Brunswick road transport"
],
"exclude": ["Countries"]
},
"name": "Builder 1",
"model": "wp1.selection.models.wikiproject",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"params": {
"add": ["British Columbia road transport", "New Brunswick road transport"],
"subtract": ["Countries"]
"include": [
"British Columbia road transport",
"New Brunswick road transport"
],
"exclude": ["Countries"]
},
"name": "Builder 1",
"model": "wp1.selection.models.wikiproject",
Expand Down
46 changes: 23 additions & 23 deletions wp1-frontend/src/components/WikiProjectBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
</template>
<template #extra-params>
<div id="lists" class="form-group m-4">
<label for="add-items">WikiProjects to include</label>
<label for="include-items">WikiProjects to include</label>
<textarea
id="add-items"
ref="addItems"
id="include-items"
ref="includeItems"
class="form-control my-2"
v-model="addText"
v-model="includeText"
rows="5"
required
></textarea>
Expand All @@ -37,12 +37,12 @@
Please provide WikiProjects to include
</div>

<label for="subtract-items">WikiProjects to exclude</label>
<label for="exclude-items">WikiProjects to exclude</label>
<textarea
id="subtract-items"
ref="subtractItems"
id="exclude-items"
ref="excludeItems"
class="form-control my-2"
v-model="subtractText"
v-model="excludeText"
rows="5"
></textarea>
</div>
Expand All @@ -58,19 +58,19 @@ export default {
name: 'WikiProjectBuilder',
data: function () {
return {
addText: '',
subtractText: '',
includeText: '',
excludeText: '',
invalidItems: '',
params: {},
};
},
methods: {
onBuilderLoaded: function (builder) {
this.addText = builder.params.add.join('\n');
this.subtractText = builder.params.subtract.join('\n');
this.includeText = builder.params.include.join('\n');
this.excludeText = builder.params.exclude.join('\n');
},
onBeforeSubmit: function () {
this.$refs.addItems.setCustomValidity('');
this.$refs.includeItems.setCustomValidity('');
},
onValidationError: function (data) {
this.invalidItems = data.items.invalid.join('\n');
Expand All @@ -80,21 +80,21 @@ export default {
},
},
watch: {
addText: function () {
const add = this.subtractText.split('\n');
if (add.length === 1 && add[0] === '') {
this.params.add = [];
includeText: function () {
const include = this.excludeText.split('\n');
if (include.length === 1 && include[0] === '') {
this.params.include = [];
return;
}
this.params.add = this.addText.split('\n') || [];
this.params.include = this.includeText.split('\n') || [];
},
subtractText: function () {
const subtract = this.subtractText.split('\n');
if (subtract.length === 1 && subtract[0] === '') {
this.params.subtract = [];
excludeText: function () {
const exclude = this.excludeText.split('\n');
if (exclude.length === 1 && exclude[0] === '') {
this.params.exclude = [];
return;
}
this.params.subtract = this.subtractText.split('\n');
this.params.exclude = this.excludeText.split('\n');
},
},
};
Expand Down

0 comments on commit 7c92ea9

Please sign in to comment.