From db7120ffaea5f7149a536932fc55ad9ea19c8999 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 5 Feb 2021 11:30:54 -0500 Subject: [PATCH] Added E2E tests for #12585. (#12597) * Added E2E tests for #12585. * Added a check to ensure no error message when preview works. --- app/javascript/article-form/articleForm.jsx | 1 + .../fixtures/users/articleEditorV1User.json | 5 ++ .../fixtures/users/articleEditorV2User.json | 5 ++ .../publishingFlows/previewArticle.js | 75 +++++++++++++++++++ spec/support/seeds/seeds_e2e.rb | 61 ++++++++++----- 5 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 cypress/fixtures/users/articleEditorV1User.json create mode 100644 cypress/fixtures/users/articleEditorV2User.json create mode 100644 cypress/integration/publishingFlows/previewArticle.js diff --git a/app/javascript/article-form/articleForm.jsx b/app/javascript/article-form/articleForm.jsx index a3498ac76..b26cec998 100644 --- a/app/javascript/article-form/articleForm.jsx +++ b/app/javascript/article-form/articleForm.jsx @@ -310,6 +310,7 @@ export class ArticleForm extends Component { className="crayons-article-form" onSubmit={this.onSubmit} onInput={this.toggleEdit} + data-testid="article-form" >
{ + describe('v1 Editor', () => { + beforeEach(() => { + cy.testSetup(); + cy.fixture('users/articleEditorV1User.json').as('user'); + + cy.get('@user').then((user) => { + cy.loginUser(user).then(() => { + cy.visit('/new'); + }); + }); + }); + + it('should preview blank content of an article', () => { + cy.findByTestId('article-form').as('articleForm'); + + cy.get('@articleForm') + .findByText(/^Preview$/i) + .click(); + cy.findByTestId('error-message').should('not.exist'); + }); + + it(`should show error if the article content can't be previewed`, () => { + cy.findByTestId('article-form').as('articleForm'); + + // Cause an error by having a non tag liquid tag without a tag name in the article body. + cy.get('@articleForm') + .findByLabelText('Post Content') + .type('{%tag %}', { parseSpecialCharSequences: false }); + + cy.get('@articleForm') + .findByText(/^Preview$/i) + .click(); + + cy.findByTestId('error-message').should('be.visible'); + }); + }); + + describe('v2 Editor', () => { + beforeEach(() => { + cy.testSetup(); + cy.fixture('users/articleEditorV2User.json').as('user'); + + cy.get('@user').then((user) => { + cy.loginUser(user).then(() => { + cy.visit('/new'); + }); + }); + }); + + it('should preview blank content of an article', () => { + cy.findByTestId('article-form').as('articleForm'); + + cy.get('@articleForm') + .findByText(/^Preview$/i) + .click(); + cy.findByTestId('error-message').should('not.exist'); + }); + + it(`should show error if the article content can't be previewed`, () => { + cy.findByTestId('article-form').as('articleForm'); + + // Cause an error by having a non tag liquid tag without a tag name in the article body. + cy.get('@articleForm') + .findByLabelText('Post Content') + .type('{%tag %}', { parseSpecialCharSequences: false }); + + cy.get('@articleForm') + .findByText(/^Preview$/i) + .click(); + + cy.findByTestId('error-message').should('be.visible'); + }); + }); +}); diff --git a/spec/support/seeds/seeds_e2e.rb b/spec/support/seeds/seeds_e2e.rb index d6357329d..e7704fe9c 100644 --- a/spec/support/seeds/seeds_e2e.rb +++ b/spec/support/seeds/seeds_e2e.rb @@ -12,23 +12,6 @@ seeder = Seeder.new SiteConfig.public = true SiteConfig.waiting_on_first_user = false -seeder.create_if_none(Organization) do - 3.times do - Organization.create!( - name: Faker::TvShows::SiliconValley.company, - summary: Faker::Company.bs, - remote_profile_image_url: logo = Faker::Company.logo, - nav_image: logo, - url: Faker::Internet.url, - slug: "org#{rand(10_000)}", - github_username: "org#{rand(10_000)}", - twitter_username: "org#{rand(10_000)}", - bg_color_hex: Faker::Color.hex_color, - text_color_hex: Faker::Color.hex_color, - ) - end -end - ############################################################################## # NOTE: @citizen428 For the time being we want all current DEV profile fields. @@ -84,3 +67,47 @@ seeder.create_if_doesnt_exist(User, "email", "change-password-user@forem.com") d end ############################################################################## + +seeder.create_if_doesnt_exist(User, "email", "article-editor-v1-user@forem.com") do + User.create!( + name: "Article Editor v1 User", + email: "article-editor-v1-user@forem.local", + username: "article_editor_v1_user", + summary: Faker::Lorem.paragraph_by_chars(number: 199, supplemental: false), + profile_image: File.open(Rails.root.join("app/assets/images/#{rand(1..40)}.png")), + website_url: Faker::Internet.url, + email_comment_notifications: false, + email_follower_notifications: false, + confirmed_at: Time.current, + password: "password", + password_confirmation: "password", + saw_onboarding: true, + checked_code_of_conduct: true, + checked_terms_and_conditions: true, + editor_version: "v1", + ) +end + +############################################################################## + +seeder.create_if_doesnt_exist(User, "email", "article-editor-v2-user@forem.com") do + User.create!( + name: "Article Editor v2 User", + email: "article-editor-v2-user@forem.local", + username: "article_editor_v2_user", + summary: Faker::Lorem.paragraph_by_chars(number: 199, supplemental: false), + profile_image: File.open(Rails.root.join("app/assets/images/#{rand(1..40)}.png")), + website_url: Faker::Internet.url, + email_comment_notifications: false, + email_follower_notifications: false, + confirmed_at: Time.current, + password: "password", + password_confirmation: "password", + saw_onboarding: true, + checked_code_of_conduct: true, + checked_terms_and_conditions: true, + editor_version: "v2", + ) +end + +##############################################################################