From 96c18ec8a3ebdb16927ef32b58133fdc76e38c31 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati Date: Thu, 22 Feb 2024 21:12:33 -0800 Subject: [PATCH] added cucumber tests and added untracked migration file --- ...015_change_to_field_for_form_submission.rb | 5 ++++ features/email_template.feature | 30 +++++++++++++++++++ features/step_definitions/web_steps.rb | 12 ++++++++ 3 files changed, 47 insertions(+) create mode 100644 db/migrate/20240220192015_change_to_field_for_form_submission.rb diff --git a/db/migrate/20240220192015_change_to_field_for_form_submission.rb b/db/migrate/20240220192015_change_to_field_for_form_submission.rb new file mode 100644 index 00000000..0674e52e --- /dev/null +++ b/db/migrate/20240220192015_change_to_field_for_form_submission.rb @@ -0,0 +1,5 @@ +class ChangeToFieldForFormSubmission < ActiveRecord::Migration[6.1] + def change + EmailTemplate.find_by(path: "teacher_mailer/form_submission").update(to: "lmock@berkeley.edu, contact@bjc.berkeley.edu") + end +end diff --git a/features/email_template.feature b/features/email_template.feature index 9b67dc3a..36e96d97 100644 --- a/features/email_template.feature +++ b/features/email_template.feature @@ -33,3 +33,33 @@ Scenario: Logging in as an admin should be able to edit email subject And I press "Submit" And I follow "Welcome Email" Then the "email_template_subject" field should contain "Test Subject" + +Scenario: Creating new email template with blank fields displays flash error + Given I am on the email templates index + And I press "New Email Templates" + When I press "Submit" + Then I should see "Failed to submit information: Body cannot be blank, To cannot be blank" + +Scenario: Creating and deleting new email template with valid fields succeeds + Given I am on the email templates index + And I press "New Email Templates" + When I fill in "email_template_title" with "Test Email" + And I fill in "email_template_subject" with "Test Subject" + And I fill in "email_template_to" with "{{teacher_email}}" + And I fill in TinyMCE email form with "This is the body of my test email" + And I press "Submit" + Then I should see "Created Test Email successfully" + When I follow the first "❌" link + And I accept the popup alert + Then I should be on the email templates index + And I should not see "Test Email" + +Scenario: Editing email template to have blank body or to field displays flash error + Given I am on the email templates index + And I follow "Welcome Email" + And I fill in "email_template_to" with "" + And I press "Submit" + Then I should see "Failed to save Welcome Email template: To cannot be blank" + When I fill in TinyMCE email form with "" + And I press "Submit" + Then I should see "Failed to save Welcome Email template: Body cannot be blank" diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index b35e61d9..6f216b75 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -60,6 +60,18 @@ def with_scope(locator, &block) page.execute_script('$(tinymce.editors[0].setContent("' + value + '"))') end +When(/^(?:|I )follow the first "([^"]*)" link$/) do |link_text| + first("a", text: link_text).click +end + +When(/^(?:|I )press the first "([^"]*)" button$/) do |button_text| + first("button", text: button_text).click +end + +Then(/^(?:|I )accept the popup alert$/) do + page.driver.browser.switch_to.alert.accept +end + When(/^(?:|I )fill in "([^"]*)" for "([^"]*)"$/) do |value, field| fill_in(field, with: value) end