From 0a2110b9af52005798251dc9d245a66dd5dd20fa Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 20 May 2024 11:00:09 -0400 Subject: [PATCH] Add coverage for custom filters (#30347) --- spec/system/filters_spec.rb | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 spec/system/filters_spec.rb diff --git a/spec/system/filters_spec.rb b/spec/system/filters_spec.rb new file mode 100644 index 0000000000..9d18e90460 --- /dev/null +++ b/spec/system/filters_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Filters' do + let(:user) { Fabricate(:user) } + let(:filter_title) { 'Filter of fun and games' } + + before { sign_in(user) } + + describe 'Creating a filter' do + it 'Populates a new filter from form' do + navigate_to_filters + + click_on I18n.t('filters.new.title') + fill_in_filter_form + expect(page).to have_content(filter_title) + end + end + + describe 'Editing an existing filter' do + let(:new_title) { 'Change title value' } + + before { Fabricate :custom_filter, account: user.account, title: filter_title } + + it 'Updates the saved filter' do + navigate_to_filters + + click_on filter_title + + fill_in filter_title_field, with: new_title + click_on I18n.t('generic.save_changes') + + expect(page).to have_content(new_title) + end + end + + describe 'Destroying an existing filter' do + before { Fabricate :custom_filter, account: user.account, title: filter_title } + + it 'Deletes the filter' do + navigate_to_filters + + expect(page).to have_content filter_title + expect do + click_on I18n.t('filters.index.delete') + end.to change(CustomFilter, :count).by(-1) + + expect(page).to_not have_content(filter_title) + end + end + + def navigate_to_filters + visit settings_path + + click_on I18n.t('filters.index.title') + expect(page).to have_content I18n.t('filters.index.title') + end + + def fill_in_filter_form + fill_in filter_title_field, with: filter_title + check I18n.t('filters.contexts.home') + within('.custom_filter_keywords_keyword') do + fill_in with: 'Keyword' + end + click_on I18n.t('filters.new.save') + end + + def filter_title_field + I18n.t('simple_form.labels.defaults.title') + end +end