Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Refactor date alert settings tests

Dombi Attilaea6a2e9dad63
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html
index 945496af1ca..fe1242a46ab 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html
+++ b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html
@@ -64,7 +64,7 @@
type="checkbox"
formControlName="active"
class="op-reminder-settings-date-alerts--active"
- attr.data-qa-selector="op-settings-start-date"
+ data-qa-global-notification-type="op-settings-start-date-active"
id="op-settings-start-date"
/>
<label
@@ -75,8 +75,7 @@
<select
formControlName="time"
class="op-reminder-settings-date-alerts--time form--select -narrow"
- attr.id="op-reminder-settings-date-alerts"
- id="op-reminder-settings-start-date-alerts"
+ data-qa-global-notification-type= "op-reminder-settings-start-date-alerts"
required="true"
*ngIf="dateAlertsStatuses.startDate"
>
@@ -97,7 +96,7 @@
type="checkbox"
formControlName="active"
class="op-reminder-settings-date-alerts--active"
- attr.data-qa-selector="op-settings-due-date"
+ data-qa-global-notification-type= "op-settings-due-date-active"
id="op-settings-due-date"
/>
<label
@@ -108,8 +107,7 @@
<select
formControlName="time"
class="op-reminder-settings-date-alerts--time form--select -narrow"
- attr.id="op-reminder-settings-date-alerts"
- id="op-reminder-settings-due-date-alerts"
+ data-qa-global-notification-type= "op-reminder-settings-due-date-alerts"
required="true"
*ngIf="dateAlertsStatuses.dueDate"
>
@@ -129,7 +127,7 @@
formControlName="active"
type="checkbox"
class="op-reminder-settings-date-alerts--active"
- attr.data-qa-selector="op-settings-overdue-date"
+ data-qa-global-notification-type="op-settings-overdue-date-active"
id="op-settings-overdue-date">
<label
class="op-reminder-settings-date-alerts--label"
@@ -139,8 +137,7 @@
<select
formControlName="time"
class="op-reminder-settings-date-alerts--time form--select -narrow"
- attr.id="op-reminder-settings-date-alerts"
- id="op-reminder-settings-overdue-date-alerts"
+ data-qa-global-notification-type="op-reminder-settings-overdue-alerts"
required="true"
*ngIf="dateAlertsStatuses.overdue"
>
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html
index 797b61f5515..49392a9bbe8 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html
+++ b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html
@@ -98,7 +98,8 @@
<select
formControlName="startDate"
class="op-reminder-settings-table-date-alerts--time form--select"
- id="op-reminder-settings-start-date-alerts-global"
+ data-qa-project-notification-type="op-reminder-settings-start-date-alerts"
+ [attr.data-qa-project]="item.controls.project.value.title"
required="true"
>
<option
@@ -121,7 +122,8 @@
<select
formControlName="dueDate"
class="op-reminder-settings-table-date-alerts--time form--select"
- id="op-reminder-settings-due-date-alerts-global"
+ data-qa-project-notification-type="op-reminder-settings-due-date-alerts"
+ [attr.data-qa-project]="item.controls.project.value.title"
required="true"
>
<option
@@ -144,7 +146,8 @@
<select
formControlName="overdue"
class="op-reminder-settings-table-date-alerts--time form--select"
- id="op-reminder-settings-overdue-date-alerts-global"
+ data-qa-project-notification-type="op-reminder-settings-overdue-alerts"
+ [attr.data-qa-project]="item.controls.project.value.title"
required="true"
>
<option
diff --git a/spec/features/notifications/settings/date_alert_settings_spec.rb b/spec/features/notifications/settings/date_alert_settings_spec.rb
deleted file mode 100644
index 57636cfc292..00000000000
--- a/spec/features/notifications/settings/date_alert_settings_spec.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-require 'rails_helper'
-
-describe "Date alert settings", js: true do
- current_user { create(:user) }
-
- let(:settings_page) { Pages::My::Notifications.new(current_user) }
- let(:user) { current_user }
- let!(:project) { create(:project) }
- let!(:project_alt) { create(:project) }
- let!(:role) { create(:role, permissions: %i[view_project]) }
- let!(:member) { create(:member, user:, project:, roles: [role]) }
- let!(:member_two) { create(:member, user:, project: project_alt, roles: [role]) }
-
- it 'allows to configure the date alert settings' do
- # Set date alert settings
- settings_page.visit!
- settings_page.set_time('op-reminder-settings-start-date-alerts', '3 days before')
- settings_page.date_alert_option('overdue', true)
- settings_page.set_time('op-reminder-settings-overdue-date-alerts', 'every week')
-
- settings_page.save
- settings_page.expect_and_dismiss_toaster(message: 'Successful update')
-
- user.reload
- notification_settings = user.notification_settings
-
- expect(notification_settings.count).to eq(1)
- expect(notification_settings.first.start_date).to eq(3)
- expect(notification_settings.first.due_date).to eq(1)
- expect(notification_settings.first.overdue).to eq(7)
-
- # Unset date alert settings
- settings_page.date_alert_option('start', false)
- settings_page.date_alert_option('overdue', false)
- settings_page.date_alert_option('due', false)
-
- settings_page.save
-
- user.reload
- notification_settings = user.notification_settings
-
- expect(notification_settings.count).to eq(1)
- expect(notification_settings.first.start_date).to be_nil
- expect(notification_settings.first.due_date).to be_nil
- expect(notification_settings.first.overdue).to be_nil
- end
-
- it 'allows to configure date alerts settings per project' do
- # Set date alert settings
- settings_page.visit!
- settings_page.add_project project
-
- settings_page.set_time('op-reminder-settings-start-date-alerts-global', '3 days before')
- settings_page.set_time('op-reminder-settings-due-date-alerts-global', '3 days before')
- settings_page.set_time('op-reminder-settings-overdue-date-alerts-global', 'every week')
- settings_page.save
- settings_page.expect_and_dismiss_toaster(message: 'Successful update')
-
- user.reload
- notification_settings = user.notification_settings
-
- expect(notification_settings.count).to eq 2
- expect(notification_settings.where(project:).count).to eq 1
- expect(notification_settings.where(project:).first.start_date).to eq(3)
- expect(notification_settings.where(project:).first.due_date).to eq(3)
- expect(notification_settings.where(project:).first.overdue).to eq(7)
-
- # Unset date alert settings
- settings_page.set_time('op-reminder-settings-start-date-alerts-global', 'No notification')
- settings_page.set_time('op-reminder-settings-due-date-alerts-global', 'No notification')
- settings_page.set_time('op-reminder-settings-overdue-date-alerts-global', 'No notification')
- settings_page.save
- settings_page.expect_and_dismiss_toaster(message: 'Successful update')
-
- user.reload
- notification_settings = user.notification_settings
-
- expect(notification_settings.count).to eq 2
- expect(notification_settings.where(project:).count).to eq 1
- expect(notification_settings.where(project:).first.start_date).to be_nil
- expect(notification_settings.where(project:).first.due_date).to be_nil
- expect(notification_settings.where(project:).first.overdue).to be_nil
- end
-end
diff --git a/spec/features/users/notifications/shared_examples.rb b/spec/features/users/notifications/shared_examples.rb
index 7eeb576b23d..722ca716860 100644
--- a/spec/features/users/notifications/shared_examples.rb
+++ b/spec/features/users/notifications/shared_examples.rb
@@ -1,5 +1,5 @@
shared_examples 'notification settings workflow' do
- describe 'with another project the user can see' do
+ describe 'with another project the user can see', with_ee: %i[date_alerts] do
let!(:project) { create :project }
let!(:project_alt) { create :project }
let!(:role) { create :role, permissions: %i[view_project] }
@@ -14,7 +14,7 @@ shared_examples 'notification settings workflow' do
settings_page.add_project project
settings_page.add_project project_alt
- # Set settings for project email
+ # Set settings for global email
settings_page.configure_global assignee: true,
responsible: true,
work_package_commented: true,
@@ -23,6 +23,11 @@ shared_examples 'notification settings workflow' do
work_package_prioritized: true,
work_package_scheduled: true
+ # Set settings for global date alerts
+ settings_page.set_reminder('start-date', '3 days before')
+ settings_page.enable_date_alert('overdue', true)
+ settings_page.set_reminder('overdue', 'every week')
+
# Set settings for project email
settings_page.configure_project project: project,
assignee: true,
@@ -33,13 +38,33 @@ shared_examples 'notification settings workflow' do
work_package_prioritized: false,
work_package_scheduled: false
+ # Set settings for project date alerts
+ settings_page.set_project_reminder('start-date', '3 days before', project)
+ settings_page.set_project_reminder('due-date', '3 days before', project)
+ settings_page.set_project_reminder('overdue', 'every week', project)
+
settings_page.save
+ settings_page.expect_and_dismiss_toaster(message: 'Successful update')
- user.reload
- notification_settings = user.notification_settings
+ notification_settings = user.reload.notification_settings
expect(notification_settings.count).to eq 3
+ expect(notification_settings.where(project: nil).count).to eq(1)
expect(notification_settings.where(project:).count).to eq 1
+ global_settings = notification_settings.find_by(project: nil)
+ expect(global_settings.assignee).to be_truthy
+ expect(global_settings.responsible).to be_truthy
+ expect(global_settings.mentioned).to be_truthy
+ expect(global_settings.watched).to be_truthy
+ expect(global_settings.work_package_commented).to be_truthy
+ expect(global_settings.work_package_created).to be_truthy
+ expect(global_settings.work_package_processed).to be_truthy
+ expect(global_settings.work_package_prioritized).to be_truthy
+ expect(global_settings.work_package_scheduled).to be_truthy
+ expect(global_settings.start_date).to eq(3)
+ expect(global_settings.due_date).to eq(1)
+ expect(global_settings.overdue).to eq(7)
+
project_settings = notification_settings.find_by(project:)
expect(project_settings.assignee).to be_truthy
expect(project_settings.responsible).to be_truthy
@@ -50,6 +75,37 @@ shared_examples 'notification settings workflow' do
expect(project_settings.work_package_processed).to be_falsey
expect(project_settings.work_package_prioritized).to be_falsey
expect(project_settings.work_package_scheduled).to be_falsey
+ expect(project_settings.start_date).to eq(3)
+ expect(project_settings.due_date).to eq(3)
+ expect(project_settings.overdue).to eq(7)
+
+ # Unset global date alert settings
+ settings_page.enable_date_alert('start', false)
+ settings_page.enable_date_alert('overdue', false)
+ settings_page.enable_date_alert('due', false)
+
+ # Unset project date alert settings
+ settings_page.set_project_reminder('start-date', 'No notification', project)
+ settings_page.set_project_reminder('due-date', 'No notification', project)
+ settings_page.set_project_reminder('overdue', 'No notification', project)
+
+ settings_page.save
+ settings_page.expect_and_dismiss_toaster(message: 'Successful update')
+
+ notification_settings = user.reload.notification_settings
+ expect(notification_settings.count).to eq 3
+ expect(notification_settings.where(project: nil).count).to eq(1)
+ expect(notification_settings.where(project:).count).to eq 1
+
+ global_settings = notification_settings.find_by(project: nil)
+ expect(global_settings.start_date).to be_nil
+ expect(global_settings.due_date).to be_nil
+ expect(global_settings.overdue).to be_nil
+
+ project_settings = notification_settings.find_by(project:)
+ expect(project_settings.start_date).to be_nil
+ expect(project_settings.due_date).to be_nil
+ expect(project_settings.overdue).to be_nil
# Trying to add the same project again will not be possible (Regression #38072)
click_button 'Add setting for project'
@@ -58,5 +114,24 @@ shared_examples 'notification settings workflow' do
expect(page).to have_text 'This project is already selected'
expect(page).to have_selector('.ng-option-disabled', text: project.name)
end
+
+ context 'without enterprise', with_ee: false do
+ it 'does not renders the date alerts' do
+ # Expect default settings
+ settings_page.expect_represented
+
+ # Add projects columns
+ settings_page.add_project project
+
+ # Expect no date alert fields
+ settings_page.expect_no_date_alert_setting('start-date')
+ settings_page.expect_no_date_alert_setting('due-date')
+ settings_page.expect_no_date_alert_setting('overdue')
+
+ settings_page.expect_no_project_date_alert_setting('start-date', project)
+ settings_page.expect_no_project_date_alert_setting('due-date', project)
+ settings_page.expect_no_project_date_alert_setting('overdue', project)
+ end
+ end
end
end
diff --git a/spec/support/pages/notifications/settings.rb b/spec/support/pages/notifications/settings.rb
index bdd7dd604a3..eae0db6350f 100644
--- a/spec/support/pages/notifications/settings.rb
+++ b/spec/support/pages/notifications/settings.rb
@@ -87,13 +87,20 @@ module Pages
checked ? checkbox.check : checkbox.uncheck
end
- def date_alert_option(type, checked)
- checkbox = page.find "input[type='checkbox']#op-settings-#{type}-date"
+ def enable_date_alert(type, checked)
+ checkbox = page.find "input[type='checkbox'][data-qa-global-notification-type='op-settings-#{type}-date-active']"
checked ? checkbox.check : checkbox.uncheck
end
- def set_time(label, time)
- select time, from: label
+ def set_reminder(label, time)
+ select_box = page.find "select[data-qa-global-notification-type='op-reminder-settings-#{label}-alerts']"
+ select_box.select time
+ end
+
+ def expect_no_date_alert_setting(label)
+ expect(page).not_to have_selector(
+ "select[data-qa-global-notification-type='op-reminder-settings-#{label}-alerts']"
+ )
end
def configure_project(project: nil, **types)
@@ -105,6 +112,19 @@ module Pages
checked ? checkbox.check : checkbox.uncheck
end
+ def set_project_reminder(label, time, project)
+ select_box =
+ page.find "select[data-qa-project='#{project}']" \
+ "[data-qa-project-notification-type='op-reminder-settings-#{label}-alerts']"
+ select_box.select time
+ end
+
+ def expect_no_project_date_alert_setting(label, project)
+ expect(page).not_to have_selector(
+ "select[data-qa-project='#{project}'][data-qa-project-notification-type='op-reminder-settings-#{label}-alerts']"
+ )
+ end
+
def save
click_button 'Save'
expect_toast message: 'Successful update.'