From 253032468f8a1913adb0896c86304e78dd1f5f2c Mon Sep 17 00:00:00 2001 From: roschaefer Date: Thu, 7 Nov 2019 14:17:22 +0100 Subject: [PATCH 1/8] Refactor: Re-use validation via error slot --- .../ContributionForm/ContributionForm.vue | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/webapp/components/ContributionForm/ContributionForm.vue b/webapp/components/ContributionForm/ContributionForm.vue index f6ebf6bcc..4c55a89b3 100644 --- a/webapp/components/ContributionForm/ContributionForm.vue +++ b/webapp/components/ContributionForm/ContributionForm.vue @@ -22,22 +22,12 @@ autofocus /> - + {{ form.title.length }}/{{ formSchema.title.max }} - + {{ form.title.length }}/{{ formSchema.title.max }} - - - - {{ form.title.length }}/{{ formSchema.title.max }} - From c83a808825a7676edde2a5f34714297626035f2a Mon Sep 17 00:00:00 2001 From: roschaefer Date: Thu, 7 Nov 2019 14:22:05 +0100 Subject: [PATCH 2/8] Refactor content length validation with transform --- .../ContributionForm/ContributionForm.vue | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/webapp/components/ContributionForm/ContributionForm.vue b/webapp/components/ContributionForm/ContributionForm.vue index 4c55a89b3..224390d7e 100644 --- a/webapp/components/ContributionForm/ContributionForm.vue +++ b/webapp/components/ContributionForm/ContributionForm.vue @@ -39,16 +39,15 @@ /> - {{ form.contentLength }} + {{ contentLength }} - - {{ form.contentLength }} - + + {{ contentLength }} @@ -135,7 +134,6 @@ export default { form: { title: '', content: '', - contentLength: 0, teaserImage: null, image: null, language: null, @@ -144,7 +142,13 @@ export default { }, formSchema: { title: { required: true, min: 3, max: 100 }, - content: { required: true, min: 3 }, + content: { + required: true, + min: 3, + transform: (content) => { + return this.$filters.removeHtml(content) + } + }, }, id: null, loading: false, @@ -168,11 +172,13 @@ export default { this.form.content = contribution.content this.form.image = contribution.image this.form.categoryIds = this.categoryIds(contribution.categories) - this.manageContent(this.form.content) }, }, }, computed: { + contentLength() { + return this.$filters.removeHtml(this.form.content).length + }, locale() { const locale = this.contribution && this.contribution.language @@ -230,14 +236,7 @@ export default { }) }, updateEditorContent(value) { - // TODO: Do smth????? what is happening this.$refs.contributionForm.update('content', value) - this.manageContent(value) - }, - manageContent(content) { - let str = content.replace(/<\/?[^>]+(>|$)/gm, '') - this.form.contentLength = str.length - this.validatePost() }, availableLocales() { orderBy(locales, 'name').map(locale => { @@ -259,10 +258,9 @@ export default { return categoryIds }, validatePost() { - const passesContentValidations = this.form.contentLength >= this.contentMin const passesCategoryValidations = this.form.categoryIds.length > 0 && this.form.categoryIds.length <= 3 - this.failsValidations = !(passesContentValidations && passesCategoryValidations) + this.failsValidations = !(passesCategoryValidations) }, }, apollo: { From 62b393b0f00e07d2a4a16cff342546c69d4cb58b Mon Sep 17 00:00:00 2001 From: roschaefer Date: Thu, 7 Nov 2019 23:23:47 +0100 Subject: [PATCH 3/8] Refactoring of Categories Select component --- .../CategoriesSelect/CategoriesSelect.vue | 37 ++++------ .../ContributionForm/ContributionForm.vue | 67 ++++++------------- 2 files changed, 33 insertions(+), 71 deletions(-) diff --git a/webapp/components/CategoriesSelect/CategoriesSelect.vue b/webapp/components/CategoriesSelect/CategoriesSelect.vue index cbe46b890..9b54b3283 100644 --- a/webapp/components/CategoriesSelect/CategoriesSelect.vue +++ b/webapp/components/CategoriesSelect/CategoriesSelect.vue @@ -28,16 +28,23 @@ From edbb0c3d1f78afad94db2d12e88fc4e99edc630a Mon Sep 17 00:00:00 2001 From: roschaefer Date: Tue, 12 Nov 2019 17:37:16 +0100 Subject: [PATCH 7/8] Fix cypress tests --- cypress/integration/common/steps.js | 7 ++++++- cypress/integration/notifications/Mentions.feature | 1 + cypress/integration/post/WritePost.feature | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index 493c54e38..ec63a81c8 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -245,6 +245,11 @@ Then("I select a category", () => { .click(); }); +When("I choose a language for the post", () => { + cy.get('.ds-flex-item > .ds-form-item .ds-select ') + .click().get('.ds-select-option').first().click() +}) + Then("the post shows up on the landing page at position {int}", index => { cy.openPage("landing"); const selector = `.post-card:nth-child(${index}) > .ds-card-content`; @@ -536,4 +541,4 @@ Then("I see only one post with the title {string}", title => { .find(".post-link") .should("have.length", 1); cy.get(".main-container").contains(".post-link", title); -}); \ No newline at end of file +}); diff --git a/cypress/integration/notifications/Mentions.feature b/cypress/integration/notifications/Mentions.feature index 7523e3d05..810b77433 100644 --- a/cypress/integration/notifications/Mentions.feature +++ b/cypress/integration/notifications/Mentions.feature @@ -20,6 +20,7 @@ Feature: Notification for a mention """ And mention "@matt-rider" in the text And I select a category + And I choose a language for the post And I click on "Save" When I log out And I log in with the following credentials: diff --git a/cypress/integration/post/WritePost.feature b/cypress/integration/post/WritePost.feature index 461766532..c5762536e 100644 --- a/cypress/integration/post/WritePost.feature +++ b/cypress/integration/post/WritePost.feature @@ -17,7 +17,8 @@ Feature: Create a post Human Connection is a free and open-source social network for active citizenship. """ - Then I select a category + And I select a category + And I choose a language for the post And I click on "Save" Then I get redirected to ".../my-first-post" And the post was saved successfully From c20a656405eef0b6896bc85a1a76937b27608f52 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Fri, 15 Nov 2019 11:51:53 +0100 Subject: [PATCH 8/8] Follow @mattwr18 suggestions --- cypress/integration/common/steps.js | 8 ++++++-- cypress/integration/notifications/Mentions.feature | 2 +- cypress/integration/post/WritePost.feature | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index ec63a81c8..c51c863d1 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -5,9 +5,12 @@ import { } from "cypress-cucumber-preprocessor/steps"; import helpers from "../../support/helpers"; import { VERSION } from '../../constants/terms-and-conditions-version.js' +import locales from '../../../webapp/locales' +import orderBy from 'lodash/orderBy' /* global cy */ +const languages = orderBy(locales, 'name') let lastPost = {}; let loginCredentials = { @@ -245,9 +248,10 @@ Then("I select a category", () => { .click(); }); -When("I choose a language for the post", () => { +When("I choose {string} as the language for the post", (languageCode) => { cy.get('.ds-flex-item > .ds-form-item .ds-select ') - .click().get('.ds-select-option').first().click() + .click().get('.ds-select-option') + .eq(languages.findIndex(l => l.code === languageCode)).click() }) Then("the post shows up on the landing page at position {int}", index => { diff --git a/cypress/integration/notifications/Mentions.feature b/cypress/integration/notifications/Mentions.feature index 810b77433..ef2694abc 100644 --- a/cypress/integration/notifications/Mentions.feature +++ b/cypress/integration/notifications/Mentions.feature @@ -20,7 +20,7 @@ Feature: Notification for a mention """ And mention "@matt-rider" in the text And I select a category - And I choose a language for the post + And I choose "en" as the language for the post And I click on "Save" When I log out And I log in with the following credentials: diff --git a/cypress/integration/post/WritePost.feature b/cypress/integration/post/WritePost.feature index c5762536e..0d74606ad 100644 --- a/cypress/integration/post/WritePost.feature +++ b/cypress/integration/post/WritePost.feature @@ -18,7 +18,7 @@ Feature: Create a post for active citizenship. """ And I select a category - And I choose a language for the post + And I choose "en" as the language for the post And I click on "Save" Then I get redirected to ".../my-first-post" And the post was saved successfully