mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
e323628d8a
What is the problem? We are relying on RSpec custom matchers in system tests by defining predicates in page objects. The problem is that this can result in a system test unnecessarily waiting up till the full duration of Capybara's default wait time when the RSpec custom matcher is used with `not_to`. Considering this topic page object where we have a `has_post?` predicate defined. ``` class Topic < PageObject def has_post? has_css?('something') end end ``` The assertion `expect(Topic.new).not_to have_post` will end up waiting the full Capybara's default wait time since the RSpec custom matcher is calling Capybara's `has_css?` method which will wait until the selector appear. If the selector has already disappeared by the time the assertion is called, we end up waiting for something that will never exists. This commit fixes such cases by introducing new predicates that uses the `has_no_*` versions of Capybara's node matchers. For future reference, `to have_css` and `not_to have_css` is safe to sue because the RSpec matcher defined by Capbyara is smart enough to call `has_css?` or `has_no_css?` based on the expectation of the assertion.
66 lines
2.5 KiB
Ruby
66 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Edit Category", type: :system, js: true do
|
|
fab!(:color_scheme) { Fabricate(:color_scheme) }
|
|
fab!(:theme) { Fabricate(:theme) }
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
fab!(:form_template) { Fabricate(:form_template) }
|
|
fab!(:form_template_2) { Fabricate(:form_template) }
|
|
fab!(:category) do
|
|
Fabricate(:category, name: "Cool Category", slug: "cool-cat", topic_count: 3234)
|
|
end
|
|
let(:category_page) { PageObjects::Pages::Category.new }
|
|
|
|
before do
|
|
SiteSetting.experimental_form_templates = true
|
|
sign_in(admin)
|
|
end
|
|
|
|
describe "when editing a category with no form templates set" do
|
|
before { category.update(form_template_ids: []) }
|
|
|
|
it "should have form templates disabled and topic template enabled" do
|
|
category_page.visit_edit_template(category)
|
|
expect(category_page).not_to have_form_template_enabled
|
|
expect(category_page).to have_d_editor
|
|
end
|
|
|
|
it "should allow you to select and save a form template" do
|
|
category_page.visit_edit_template(category)
|
|
category_page.toggle_form_templates
|
|
expect(category_page).to have_no_d_editor
|
|
category_page.select_form_template(form_template.name)
|
|
expect(category_page).to have_selected_template(form_template.name)
|
|
category_page.save_settings
|
|
try_until_success do
|
|
expect(Category.find_by_id(category.id).form_template_ids).to eq([form_template.id])
|
|
end
|
|
end
|
|
|
|
it "should allow you to select and save multiple form templates" do
|
|
category_page.visit_edit_template(category)
|
|
category_page.toggle_form_templates
|
|
category_page.select_form_template(form_template.name)
|
|
category_page.select_form_template(form_template_2.name)
|
|
category_page.save_settings
|
|
try_until_success do
|
|
expect(Category.find_by_id(category.id).form_template_ids).to eq(
|
|
[form_template.id, form_template_2.id],
|
|
)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "when editing a category with form templates set" do
|
|
before { category.update(form_template_ids: [form_template.id, form_template_2.id]) }
|
|
|
|
it "should have form templates enabled and showing the selected templates" do
|
|
category_page.visit_edit_template(category)
|
|
expect(category_page).to have_form_template_enabled
|
|
expect(category_page).to have_no_d_editor
|
|
selected_templates = "#{form_template.name},#{form_template_2.name}"
|
|
expect(category_page).to have_selected_template(selected_templates)
|
|
end
|
|
end
|
|
end
|