Skip to content

Commit

Permalink
update admin/editor specs
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeFraties committed Apr 25, 2024
1 parent 49eb1fb commit f4a966b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
4 changes: 2 additions & 2 deletions spec/features/admin/admin_page_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
describe 'Creating a PageGroup' do
let!(:admin) { create(:user, :admin) }
let!(:valid_editor) { create(:user) }
let!(:nonexistent_email) { "[email protected]" }

before do
login_as(admin, scope: :user, run_callbacks: false)
Expand Down Expand Up @@ -35,6 +34,7 @@
end

it 'fails to create a PageGroup with invalid editor emails and shows an error message' do
nonexistent_email = "[email protected]"
visit new_admin_page_group_path

fill_in 'Name', with: 'Failed Page Group'
Expand All @@ -54,7 +54,6 @@
let!(:page_group) { create(:page_group) }
let!(:editor) { create(:user, email: "[email protected]") }
let!(:existing_editor) { create(:user) }
let!(:nonexistent_email) { "[email protected]" }

before do
login_as(admin, scope: :user, run_callbacks: false)
Expand Down Expand Up @@ -139,6 +138,7 @@
end

it 'attempts to update a PageGroup with a nonexistent editor email' do
nonexistent_email = "[email protected]"
visit edit_admin_page_group_path(page_group)

fill_in 'Name', with: 'Updated Page Group Name'
Expand Down
69 changes: 69 additions & 0 deletions spec/features/editor/editor_page_group_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require 'rails_helper'

RSpec.describe 'PageGroup Management', type: :feature, js: true do
describe 'Editing a PageGroup' do
let!(:page_group) { create(:page_group) }
let!(:editor) { create(:user, email: "[email protected]") }
let!(:new_editor) { create(:user, email: "[email protected]") }

before do
editor.add_role(:page_group_editor, page_group)
login_as(editor, scope: :user, run_callbacks: false)
end

context 'Updating editors' do
it 'successfully adds an editor to a PageGroup when there were none' do
visit edit_editor_page_group_path(page_group)
fill_in 'Add Community Editor(s)', with: new_editor.email
click_button 'Update Page group'

expect(page).to have_content('Page group was successfully updated.')
expect(page).to have_content("[email protected]")
expect(page).to have_content("[email protected]")
expect(page_group.reload.editors).to include(new_editor)
end

it "successfully adds an editor to a PageGroup's existing editors" do
visit edit_editor_page_group_path(page_group)
fill_in 'Add Community Editor(s)', with: new_editor.email
click_button 'Update Page group'

expect(page).to have_content('Page group was successfully updated.')
expect(page).to have_content("[email protected]")
expect(page).to have_content("[email protected]")
expect(page_group.editors).to include(editor, new_editor)
end

it "successfully removes an editor from a PageGroup's existing editors" do
editor.add_role(:page_group_editor, page_group)
new_editor.add_role(:page_group_editor, page_group)
visit edit_editor_page_group_path(page_group)

within("ul#current_editors") do
find("li", text: new_editor.email).find("input[type='checkbox']").set(true)
end

click_button 'Update Page group'

expect(page).to have_content('Page group was successfully updated.')
expect(page).to have_content(editor.email)
expect(page).not_to have_content(new_editor.email)
visit edit_editor_page_group_path(page_group)
expect(page).to have_content(editor.email)
expect(page).not_to have_content(new_editor.email)
expect(page_group.reload.editors).to include(editor)
expect(page_group.reload.editors).not_to include(new_editor)
end

it 'attempts to update a PageGroup with a nonexistent editor email' do
nonexistent_email = "[email protected]"
visit edit_editor_page_group_path(page_group)
fill_in 'Add Community Editor(s)', with: nonexistent_email
click_button 'Update Page group'

expect(page).to have_content('User not found with email(s): [email protected]')
expect(page_group.reload.editors).not_to include(nonexistent_email)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/features/editor/editor_page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

describe 'Page Builder', type: :feature, js: true do
describe 'Page Management', type: :feature, js: true do
let!(:admin) { create(:user, :admin) }
let!(:editor) { create(:user) }
let!(:page_group) { create(:page_group, name: 'programming') }
Expand Down

0 comments on commit f4a966b

Please sign in to comment.