user_manages_notifications_spec.rb 1.69 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'spec_helper'

Rémy Coutable's avatar
Rémy Coutable committed
5
describe 'Projects > Show > User manages notifications', :js do
6 7
  let(:project) { create(:project, :public, :repository) }

Rémy Coutable's avatar
Rémy Coutable committed
8 9 10 11
  before do
    sign_in(project.owner)
    visit project_path(project)
  end
12

13
  def click_notifications_button
Rémy Coutable's avatar
Rémy Coutable committed
14
    first('.notifications-btn').click
15 16 17 18
  end

  it 'changes the notification setting' do
    click_notifications_button
Rémy Coutable's avatar
Rémy Coutable committed
19
    click_link 'On mention'
20

21 22 23 24
    wait_for_requests

    click_notifications_button
    expect(find('.update-notification.is-active')).to have_content('On mention')
25 26 27 28 29 30 31 32 33 34
    expect(find('.notifications-icon use')[:'xlink:href']).to end_with('#notifications')
  end

  it 'changes the notification setting to disabled' do
    click_notifications_button
    click_link 'Disabled'

    wait_for_requests

    expect(find('.notifications-icon use')[:'xlink:href']).to end_with('#notifications-off')
35
  end
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

  context 'custom notification settings' do
    let(:email_events) do
      [
        :new_note,
        :new_issue,
        :reopen_issue,
        :close_issue,
        :reassign_issue,
        :issue_due,
        :new_merge_request,
        :push_to_merge_request,
        :reopen_merge_request,
        :close_merge_request,
        :reassign_merge_request,
        :merge_merge_request,
        :failed_pipeline,
        :success_pipeline
      ]
    end

    it 'shows notification settings checkbox' do
58
      click_notifications_button
59 60 61 62 63 64 65 66 67
      page.find('a[data-notification-level="custom"]').click

      page.within('.custom-notifications-form') do
        email_events.each do |event_name|
          expect(page).to have_selector("input[name='notification_setting[#{event_name}]']")
        end
      end
    end
  end
68
end