Skip to content

Commit

Permalink
WIP add tests
Browse files Browse the repository at this point in the history
Need to add tests for users organisations updating, for which there
currently are none
  • Loading branch information
yndajas committed Sep 26, 2024
1 parent 5620919 commit 968c8a2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
32 changes: 31 additions & 1 deletion test/integration/account/organisations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,37 @@ class Account::OrganisationsTest < ActionDispatch::IntegrationTest

visit edit_account_organisation_path

assert page.has_select? "Organisation", selected: "Postage"
assert_equal "Postage", user.reload.organisation_name
end

context "with JavaScript enabled" do
setup do
use_javascript_driver
end

should "allow GOVUK Admin users to change their organisation" do
current_organisation = create(:organisation, name: "Judiciary")
user = FactoryBot.create(:admin_user, organisation: current_organisation)

create(:organisation, name: "Postage")

visit new_user_session_path
signin_with user

visit edit_account_organisation_path

autocomplete_helper = AutocompleteHelper.new
autocomplete_helper.clear_selection
autocomplete_helper.select_autocomplete_option("Postage")
click_button "Change organisation"

assert_current_url account_path
assert page.has_text? "Your organisation is now Postage"

visit edit_account_organisation_path

assert_equal "Postage", user.reload.organisation_name
end
end
end
end
21 changes: 21 additions & 0 deletions test/integration/batch_inviting_users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ class BatchInvitingUsersTest < ActionDispatch::IntegrationTest
end
end

context "with JavaScript enabled" do
setup do
use_javascript_driver
end

should "allow selecting an organisation and continuing to the next step" do
visit root_path
signin_with create(:superadmin_user)

visit new_batch_invitation_path
path = Rails.root.join("test/fixtures/users.csv")
attach_file("Upload a CSV file", path)
AutocompleteHelper.new.select_autocomplete_option(@cabinet_office.name)

click_button "Manage permissions for new users"
assert assert_selector "h1", text: "Manage permissions for new users"

assert_equal @cabinet_office, BatchInvitation.last.organisation
end
end

def perform_batch_invite_with_user(user, application, organisation:, fixture_file: "users.csv", user_count: 1)
perform_enqueued_jobs do
visit root_path
Expand Down
4 changes: 4 additions & 0 deletions test/support/autocomplete_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
class AutocompleteHelper
include Capybara::DSL

def clear_selection
click_button "Clear selection"
end

def select_autocomplete_option(option_string)
autocomplete_input_element = find(".autocomplete__input")
autocomplete_input_element.fill_in with: option_string
Expand Down

0 comments on commit 968c8a2

Please sign in to comment.