|
| 1 | +require "integration_test_helper" |
| 2 | +require "support/ga4_test_helpers" |
| 3 | + |
| 4 | +class Ga4TrackingFlashMessagesTest < JavascriptIntegrationTest |
| 5 | + include Ga4TestHelpers |
| 6 | + |
| 7 | + setup do |
| 8 | + setup_users |
| 9 | + @edition = FactoryBot.create(:edition) |
| 10 | + @ready_edition = FactoryBot.create(:edition, :ready) |
| 11 | + @published_edition = FactoryBot.create(:edition, :published) |
| 12 | + end |
| 13 | + |
| 14 | + context "Danger alerts" do |
| 15 | + should "push the correct values to the dataLayer when a welsh_editor attempts to navigate to the 'Create new content' page" do |
| 16 | + login_as_welsh_editor |
| 17 | + visit new_artefact_path |
| 18 | + |
| 19 | + assert page.has_css?(".gem-c-error-alert") |
| 20 | + |
| 21 | + event_data = get_event_data |
| 22 | + |
| 23 | + assert_equal "danger_alerts", event_data[0]["action"] |
| 24 | + assert_equal "flash_danger", event_data[0]["event_name"] |
| 25 | + assert_equal "You do not have permission to see this page.", event_data[0]["text"] |
| 26 | + end |
| 27 | + |
| 28 | + should "push the correct values to the dataLayer when user does not have govuk_editor permission" do |
| 29 | + login_as(@no_editor) |
| 30 | + visit history_update_important_note_edition_path(@edition) |
| 31 | + |
| 32 | + assert page.has_css?(".gem-c-error-alert") |
| 33 | + |
| 34 | + event_data = get_event_data |
| 35 | + |
| 36 | + assert_equal "danger_alerts", event_data[0]["action"] |
| 37 | + assert_equal "flash_danger", event_data[0]["event_name"] |
| 38 | + assert_equal "You do not have correct editor permissions for this action.", event_data[0]["text"] |
| 39 | + end |
| 40 | + |
| 41 | + should "push the correct values to the dataLayer on a server error" do |
| 42 | + EditionProgressor.any_instance.expects(:progress).returns(false) |
| 43 | + |
| 44 | + visit send_to_2i_page_edition_path(@edition) |
| 45 | + fill_in "Comment (optional)", with: "Some comment" |
| 46 | + click_button "Send to 2i" |
| 47 | + |
| 48 | + assert page.has_css?(".gem-c-error-alert") |
| 49 | + |
| 50 | + event_data = get_event_data |
| 51 | + |
| 52 | + assert_equal "danger_alerts", event_data[0]["action"] |
| 53 | + assert_equal "flash_danger", event_data[0]["event_name"] |
| 54 | + assert_equal "Due to a service problem, the request could not be made", event_data[0]["text"] |
| 55 | + end |
| 56 | + |
| 57 | + should "push the correct values to the dataLayer when the edition is not in a valid state to be sent to 2i" do |
| 58 | + visit send_to_2i_page_edition_path(@ready_edition) |
| 59 | + fill_in "Comment (optional)", with: "Some comment" |
| 60 | + click_button "Send to 2i" |
| 61 | + |
| 62 | + assert page.has_css?(".gem-c-error-alert") |
| 63 | + |
| 64 | + event_data = get_event_data |
| 65 | + |
| 66 | + assert_equal "danger_alerts", event_data[0]["action"] |
| 67 | + assert_equal "flash_danger", event_data[0]["event_name"] |
| 68 | + assert_equal "Edition is not in a state where it can be sent to 2i", event_data[0]["text"] |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context "Warning alerts" do |
| 73 | + should "push the correct values to the dataLayer when another user has already created a new edition" do |
| 74 | + visit edition_path(@published_edition) |
| 75 | + click_on "Admin" |
| 76 | + |
| 77 | + FactoryBot.create(:edition, panopticon_id: @published_edition.artefact.id) |
| 78 | + |
| 79 | + click_button "Save" |
| 80 | + |
| 81 | + assert page.has_css?(".gem-c-error-alert") |
| 82 | + |
| 83 | + event_data = get_event_data |
| 84 | + |
| 85 | + assert_equal "warning_alerts", event_data[0]["action"] |
| 86 | + assert_equal "flash_warning", event_data[0]["event_name"] |
| 87 | + assert_equal "Another person has created a newer edition", event_data[0]["text"] |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + context "Success alerts" do |
| 92 | + should "push the correct flash message values to the dataLayer when edition is successfully saved" do |
| 93 | + visit edition_path(@edition) |
| 94 | + fill_in "Title", with: "The new title" |
| 95 | + click_button "Save" |
| 96 | + |
| 97 | + assert page.has_css?(".gem-c-success-alert") |
| 98 | + |
| 99 | + event_data = get_event_data |
| 100 | + |
| 101 | + assert_equal "success_alerts", event_data[0]["action"] |
| 102 | + assert_equal "flash_success", event_data[0]["event_name"] |
| 103 | + assert_equal "Edition updated successfully.", event_data[0]["text"] |
| 104 | + end |
| 105 | + |
| 106 | + should "push the correct flash message values to the dataLayer when edition is successfully sent to 2i" do |
| 107 | + visit send_to_2i_page_edition_path(@edition) |
| 108 | + fill_in "Comment (optional)", with: "Some comment" |
| 109 | + click_button "Send to 2i" |
| 110 | + |
| 111 | + assert page.has_css?(".gem-c-success-alert") |
| 112 | + |
| 113 | + event_data = get_event_data |
| 114 | + |
| 115 | + assert_equal "success_alerts", event_data[0]["action"] |
| 116 | + assert_equal "flash_success", event_data[0]["event_name"] |
| 117 | + assert_equal "Sent to 2i", event_data[0]["text"] |
| 118 | + end |
| 119 | + end |
| 120 | +end |
0 commit comments