summaryrefslogtreecommitdiff
path: root/spec/features/admin/broadcast_messages_spec.rb
blob: fca4cdb0ff40a7bb1b32a06b006e7ce50f644a3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Admin Broadcast Messages', :js, feature_category: :onboarding do
  context 'when creating and editing' do
    it 'previews, creates and edits a broadcast message' do
      admin = create(:admin)
      sign_in(admin)
      gitlab_enable_admin_mode_sign_in(admin)

      # create
      visit admin_broadcast_messages_path

      fill_in 'Message', with: 'test message'

      wait_for_requests

      page.within(preview_container) do
        expect(page).to have_content('test message')
      end

      click_button 'Add broadcast message'

      wait_for_requests

      page.within(preview_container) do
        expect(page).to have_content('Your message here')
      end

      page.within(first_message_container) do
        expect(page).to have_content('test message')
      end

      # edit
      page.within(first_message_container) do
        find('[data-testid="edit-message"]').click
      end

      wait_for_requests

      expect(find('[data-testid="message-input"]').value).to eq('test message')

      fill_in 'Message', with: 'changed test message'

      wait_for_requests

      page.within(preview_container) do
        expect(page).to have_content('changed test message')
      end

      click_button 'Update broadcast message'

      wait_for_requests

      page.within(preview_container) do
        expect(page).to have_content('Your message here')
      end

      page.within(first_message_container) do
        expect(page).to have_content('changed test message')
      end
    end

    def preview_container
      find('[data-testid="preview-broadcast-message"]')
    end

    def first_message_container
      find('[data-testid="message-row"]', match: :first)
    end
  end
end