Add coverage for custom filters (#30347)

pull/30341/head
Matt Jankowski 2024-05-20 11:00:09 -04:00 committed by GitHub
parent 00cf8d3748
commit 0a2110b9af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 72 additions and 0 deletions

View File

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