Added E2E tests for #12585. (#12597)

* Added E2E tests for #12585.

* Added a check to ensure no error message when preview works.
This commit is contained in:
Nick Taylor 2021-02-05 11:30:54 -05:00 committed by GitHub
parent 530bd4fcb7
commit db7120ffae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 130 additions and 17 deletions

View file

@ -310,6 +310,7 @@ export class ArticleForm extends Component {
className="crayons-article-form"
onSubmit={this.onSubmit}
onInput={this.toggleEdit}
data-testid="article-form"
>
<Header
onPreview={this.fetchPreview}

View file

@ -0,0 +1,5 @@
{
"username": "article_editor_v1_user",
"email": "article-editor-v1-user@forem.local",
"password": "password"
}

View file

@ -0,0 +1,5 @@
{
"username": "article_editor_v2_user",
"email": "article-editor-v2-user@forem.local",
"password": "password"
}

View file

@ -0,0 +1,75 @@
describe('Article Editor', () => {
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');
});
});
});

View file

@ -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
##############################################################################