2023-02-08 14:21:39 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-06 21:26:58 -04:00
|
|
|
describe "Admin Customize Form Templates", type: :system do
|
2023-02-08 14:21:39 -05:00
|
|
|
let(:form_template_page) { PageObjects::Pages::FormTemplate.new }
|
|
|
|
let(:ace_editor) { PageObjects::Components::AceEditor.new }
|
2023-05-30 14:37:32 -04:00
|
|
|
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:admin)
|
|
|
|
fab!(:form_template)
|
|
|
|
fab!(:category)
|
2023-02-08 14:21:39 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.experimental_form_templates = true
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when visiting the page to customize form templates" do
|
2023-05-30 14:37:32 -04:00
|
|
|
before { category.update!(form_template_ids: [form_template.id]) }
|
2023-03-01 15:37:14 -05:00
|
|
|
|
2023-02-08 14:21:39 -05:00
|
|
|
it "should show the existing form templates in a table" do
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit
|
|
|
|
|
2023-02-08 14:21:39 -05:00
|
|
|
expect(form_template_page).to have_form_template_table
|
|
|
|
expect(form_template_page).to have_form_template(form_template.name)
|
|
|
|
end
|
|
|
|
|
2023-03-01 15:37:14 -05:00
|
|
|
it "should show the categories the form template is used in" do
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit
|
|
|
|
|
2023-03-01 15:37:14 -05:00
|
|
|
expect(form_template_page).to have_form_template_table
|
|
|
|
expect(form_template_page).to have_category_in_template_row(category.name)
|
|
|
|
end
|
|
|
|
|
2023-02-08 14:21:39 -05:00
|
|
|
it "should show the form template structure in a modal" do
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit
|
|
|
|
|
2023-02-08 14:21:39 -05:00
|
|
|
form_template_page.click_view_form_template
|
2023-03-01 14:07:13 -05:00
|
|
|
expect(form_template_page).to have_template_structure("- type: input")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should show a preview of the template in a modal when toggling the preview" do
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit
|
|
|
|
|
2023-03-01 14:07:13 -05:00
|
|
|
form_template_page.click_view_form_template
|
|
|
|
form_template_page.click_toggle_preview
|
|
|
|
expect(form_template_page).to have_input_field("input")
|
2023-02-08 14:21:39 -05:00
|
|
|
end
|
2024-02-22 01:20:56 -05:00
|
|
|
|
|
|
|
context "when using the view template modal" do
|
|
|
|
it "should navigate to the edit page when clicking the edit button" do
|
|
|
|
form_template_page.visit
|
|
|
|
form_template_page.click_view_form_template
|
|
|
|
form_template_page.find(".d-modal__footer .btn-primary").click
|
|
|
|
expect(page).to have_current_path("/admin/customize/form-templates/#{form_template.id}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should delete the form template when clicking the delete button" do
|
|
|
|
form_template_page.visit
|
|
|
|
original_template_name = form_template.name
|
|
|
|
form_template_page.click_view_form_template
|
|
|
|
form_template_page.find(".d-modal__footer .btn-danger").click
|
|
|
|
form_template_page.find(".dialog-footer .btn-primary").click
|
|
|
|
|
|
|
|
expect(form_template_page).to have_no_form_template(original_template_name)
|
|
|
|
end
|
|
|
|
end
|
2023-02-08 14:21:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "when visiting the page to edit a form template" do
|
|
|
|
it "should prefill form data" do
|
|
|
|
visit("/admin/customize/form-templates/#{form_template.id}")
|
|
|
|
expect(form_template_page).to have_name_value(form_template.name)
|
2024-12-19 21:22:33 -05:00
|
|
|
expect(ace_editor).to have_content(form_template.template)
|
2023-02-08 14:21:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def quick_insertion_test(field_type, content)
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit_new
|
2023-02-08 14:21:39 -05:00
|
|
|
form_template_page.type_in_template_name("New Template")
|
|
|
|
form_template_page.click_quick_insert(field_type)
|
|
|
|
expect(ace_editor).to have_text(content)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when visiting the page to create a new form template" do
|
|
|
|
it "should allow admin to create a new form template" do
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit_new
|
2023-02-08 14:21:39 -05:00
|
|
|
|
|
|
|
sample_name = "My First Template"
|
2023-08-29 17:41:33 -04:00
|
|
|
sample_template = "- type: input\n id: name"
|
2023-02-08 14:21:39 -05:00
|
|
|
|
|
|
|
form_template_page.type_in_template_name(sample_name)
|
|
|
|
ace_editor.type_input(sample_template)
|
|
|
|
form_template_page.click_save_button
|
|
|
|
expect(form_template_page).to have_form_template(sample_name)
|
|
|
|
end
|
|
|
|
|
2023-03-01 14:07:13 -05:00
|
|
|
it "should disable the save button until form is filled out" do
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit_new
|
|
|
|
expect(form_template_page).to have_save_button_with_state(disabled: true)
|
2023-03-01 14:07:13 -05:00
|
|
|
form_template_page.type_in_template_name("New Template")
|
2023-05-31 09:00:35 -04:00
|
|
|
expect(form_template_page).to have_save_button_with_state(disabled: true)
|
2023-03-01 14:07:13 -05:00
|
|
|
ace_editor.type_input("- type: input")
|
2023-05-31 09:00:35 -04:00
|
|
|
expect(form_template_page).to have_save_button_with_state(disabled: false)
|
2023-03-01 14:07:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should disable the preview button until form is filled out" do
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit_new
|
|
|
|
expect(form_template_page).to have_preview_button_with_state(disabled: true)
|
2023-03-01 14:07:13 -05:00
|
|
|
form_template_page.type_in_template_name("New Template")
|
2023-05-31 09:00:35 -04:00
|
|
|
expect(form_template_page).to have_preview_button_with_state(disabled: true)
|
2023-03-01 14:07:13 -05:00
|
|
|
ace_editor.type_input("- type: input")
|
2023-05-31 09:00:35 -04:00
|
|
|
expect(form_template_page).to have_preview_button_with_state(disabled: false)
|
2023-03-01 14:07:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should show validation options in a modal when clicking the validations button" do
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit_new
|
2023-03-01 14:07:13 -05:00
|
|
|
form_template_page.click_validations_button
|
|
|
|
expect(form_template_page).to have_validations_modal
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should show a preview of the template in a modal when clicking the preview button" do
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit_new
|
2023-03-01 14:07:13 -05:00
|
|
|
form_template_page.type_in_template_name("New Template")
|
2023-08-29 17:41:33 -04:00
|
|
|
ace_editor.type_input("- type: input\n id: name")
|
2023-03-01 14:07:13 -05:00
|
|
|
form_template_page.click_preview_button
|
2023-05-31 09:00:35 -04:00
|
|
|
|
2023-03-01 14:07:13 -05:00
|
|
|
expect(form_template_page).to have_preview_modal
|
|
|
|
expect(form_template_page).to have_input_field("input")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should render all the input field types in the preview" do
|
2023-05-31 09:00:35 -04:00
|
|
|
form_template_page.visit_new
|
2023-03-01 14:07:13 -05:00
|
|
|
form_template_page.type_in_template_name("New Template")
|
|
|
|
ace_editor.type_input(
|
2023-08-29 17:41:33 -04:00
|
|
|
"- type: input\n id: name
|
|
|
|
\b\b- type: textarea\n id: description
|
|
|
|
\b\b- type: checkbox\n id: checkbox
|
|
|
|
\b\b- type: dropdown\n id: dropdown
|
|
|
|
\b\b- type: upload\n id: upload
|
|
|
|
\b\b- type: multi-select\n id: multi-select",
|
2023-03-01 14:07:13 -05:00
|
|
|
)
|
|
|
|
form_template_page.click_preview_button
|
|
|
|
expect(form_template_page).to have_input_field("input")
|
|
|
|
expect(form_template_page).to have_input_field("textarea")
|
|
|
|
expect(form_template_page).to have_input_field("checkbox")
|
|
|
|
expect(form_template_page).to have_input_field("dropdown")
|
2023-06-28 15:49:05 -04:00
|
|
|
expect(form_template_page).to have_input_field("upload")
|
2023-03-01 14:07:13 -05:00
|
|
|
expect(form_template_page).to have_input_field("multi-select")
|
|
|
|
end
|
|
|
|
|
2023-02-08 14:21:39 -05:00
|
|
|
it "should allow quick insertion of checkbox field" do
|
|
|
|
quick_insertion_test(
|
|
|
|
"checkbox",
|
|
|
|
'- type: checkbox
|
2023-08-29 17:41:33 -04:00
|
|
|
id: enter-id-here
|
2023-02-08 14:21:39 -05:00
|
|
|
attributes:
|
2023-03-01 14:07:13 -05:00
|
|
|
label: "Enter label here"
|
|
|
|
validations:
|
|
|
|
# enter validations here',
|
2023-02-08 14:21:39 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow quick insertion of short answer field" do
|
|
|
|
quick_insertion_test(
|
|
|
|
"input",
|
|
|
|
'- type: input
|
2023-08-29 17:41:33 -04:00
|
|
|
id: enter-id-here
|
2023-02-08 14:21:39 -05:00
|
|
|
attributes:
|
2023-03-01 14:07:13 -05:00
|
|
|
label: "Enter label here"
|
|
|
|
placeholder: "Enter placeholder here"
|
|
|
|
validations:
|
|
|
|
# enter validations here',
|
2023-02-08 14:21:39 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow quick insertion of long answer field" do
|
|
|
|
quick_insertion_test(
|
|
|
|
"textarea",
|
|
|
|
'- type: textarea
|
2023-08-29 17:41:33 -04:00
|
|
|
id: enter-id-here
|
2023-02-08 14:21:39 -05:00
|
|
|
attributes:
|
2023-03-01 14:07:13 -05:00
|
|
|
label: "Enter label here"
|
|
|
|
placeholder: "Enter placeholder here"
|
|
|
|
validations:
|
|
|
|
# enter validations here',
|
2023-02-08 14:21:39 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow quick insertion of dropdown field" do
|
|
|
|
quick_insertion_test(
|
|
|
|
"dropdown",
|
|
|
|
'- type: dropdown
|
2023-08-29 17:41:33 -04:00
|
|
|
id: enter-id-here
|
2023-02-08 14:21:39 -05:00
|
|
|
choices:
|
|
|
|
- "Option 1"
|
|
|
|
- "Option 2"
|
|
|
|
- "Option 3"
|
|
|
|
attributes:
|
2023-03-01 14:07:13 -05:00
|
|
|
none_label: "Select an item"
|
|
|
|
label: "Enter label here"
|
|
|
|
validations:
|
|
|
|
# enter validations here',
|
2023-02-08 14:21:39 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-06-28 15:49:05 -04:00
|
|
|
it "should allow quick insertion of upload field" do
|
2023-02-08 14:21:39 -05:00
|
|
|
quick_insertion_test(
|
|
|
|
"upload",
|
|
|
|
'- type: upload
|
2023-08-29 17:41:33 -04:00
|
|
|
id: enter-id-here
|
2023-02-08 14:21:39 -05:00
|
|
|
attributes:
|
2023-06-28 15:49:05 -04:00
|
|
|
file_types: ".jpg, .png, .gif"
|
2023-03-01 14:07:13 -05:00
|
|
|
allow_multiple: false
|
|
|
|
label: "Enter label here"
|
|
|
|
validations:
|
|
|
|
# enter validations here',
|
2023-02-08 14:21:39 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow quick insertion of multiple choice field" do
|
|
|
|
quick_insertion_test(
|
|
|
|
"multiselect",
|
2023-03-01 14:07:13 -05:00
|
|
|
'- type: multi-select
|
2023-08-29 17:41:33 -04:00
|
|
|
id: enter-id-here
|
2023-02-08 14:21:39 -05:00
|
|
|
choices:
|
|
|
|
- "Option 1"
|
|
|
|
- "Option 2"
|
|
|
|
- "Option 3"
|
|
|
|
attributes:
|
2023-03-01 14:07:13 -05:00
|
|
|
none_label: "Select an item"
|
|
|
|
label: "Enter label here"
|
|
|
|
validations:
|
|
|
|
# enter validations here',
|
2023-02-08 14:21:39 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|