Commit 713facd9 authored by Florie Guibert's avatar Florie Guibert

Consolidate due date sidebar rspec tests

Unify tests for issue board and issue page
parent bb224023
......@@ -154,7 +154,7 @@ export default {
};
},
dataTestId() {
return this.dateType === dateTypes.start ? 'start-date' : 'due-date';
return this.dateType === dateTypes.start ? 'sidebar-start-date' : 'sidebar-due-date';
},
},
methods: {
......
......@@ -114,7 +114,7 @@ RSpec.describe 'Epic boards sidebar', :js do
wait_for_requests
page.within('[data-testid="start-date"]') do
page.within('[data-testid="sidebar-start-date"]') do
edit_fixed_date
end
end
......@@ -124,7 +124,7 @@ RSpec.describe 'Epic boards sidebar', :js do
wait_for_requests
page.within('[data-testid="start-date"]') do
page.within('[data-testid="sidebar-start-date"]') do
remove_fixed_date
end
end
......@@ -136,7 +136,7 @@ RSpec.describe 'Epic boards sidebar', :js do
wait_for_requests
page.within('[data-testid="due-date"]') do
page.within('[data-testid="sidebar-due-date"]') do
edit_fixed_date
end
end
......@@ -146,7 +146,7 @@ RSpec.describe 'Epic boards sidebar', :js do
wait_for_requests
page.within('[data-testid="due-date"]') do
page.within('[data-testid="sidebar-due-date"]') do
remove_fixed_date
end
end
......
......@@ -11,7 +11,6 @@ RSpec.describe 'Issue Sidebar' do
let_it_be(:label) { create(:label, project: project, title: 'bug') }
let_it_be(:issue) { create(:labeled_issue, project: project, labels: [label]) }
let_it_be(:mock_date) { Date.today.at_beginning_of_month + 2.days }
let_it_be(:issue_with_due_date) { create(:issue, project: project, due_date: mock_date) }
let_it_be(:xss_label) { create(:label, project: project, title: '<script>alert("xss");</script>') }
before do
......@@ -201,30 +200,6 @@ RSpec.describe 'Issue Sidebar' do
end
end
context 'due date widget', :js do
let(:due_date_value) { find('[data-testid="due-date"] [data-testid="sidebar-date-value"]') }
context 'when no due date exists' do
before do
visit_issue(project, issue)
end
it "displays 'None'" do
expect(due_date_value.text).to have_content 'None'
end
end
context 'when due date exists' do
before do
visit_issue(project, issue_with_due_date)
end
it "displays the due date" do
expect(due_date_value.text).to have_content mock_date.strftime('%b %-d, %Y')
end
end
end
context 'as an allowed user' do
before do
project.add_developer(user)
......@@ -262,6 +237,10 @@ RSpec.describe 'Issue Sidebar' do
it_behaves_like 'milestone sidebar widget'
end
context 'editing issue due date', :js do
it_behaves_like 'date sidebar widget'
end
context 'editing issue labels', :js do
before do
issue.update!(labels: [label])
......
......@@ -417,7 +417,7 @@ RSpec.describe "Issues > User edits issue", :js do
it 'adds due date to issue' do
date = Date.today.at_beginning_of_month + 2.days
page.within '[data-testid="due-date"]' do
page.within '[data-testid="sidebar-due-date"]' do
click_button 'Edit'
page.within '.pika-single' do
click_button date.day
......@@ -432,7 +432,7 @@ RSpec.describe "Issues > User edits issue", :js do
it 'removes due date from issue' do
date = Date.today.at_beginning_of_month + 2.days
page.within '[data-testid="due-date"]' do
page.within '[data-testid="sidebar-due-date"]' do
click_button 'Edit'
page.within '.pika-single' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Project issue boards sidebar due date', :js do
include BoardHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
let_it_be(:issue) { create(:issue, project: project, relative_position: 1) }
let_it_be(:board) { create(:board, project: project) }
let_it_be(:list) { create(:list, board: board, position: 0) }
let(:card) { find('.board:nth-child(1)').first('.board-card') }
RSpec.shared_examples 'date sidebar widget' do
context 'editing due date' do
let(:due_date_value) { find('[data-testid="sidebar-due-date"] [data-testid="sidebar-date-value"]') }
around do |example|
freeze_time { example.run }
end
before do
project.add_maintainer(user)
sign_in(user)
visit project_board_path(project, board)
wait_for_requests
it 'displays "None" when there is no due date' do
expect(due_date_value.text).to have_content 'None'
end
context 'due date' do
it 'updates due date' do
click_card(card)
page.within('[data-testid="sidebar-due-date"]') do
today = Date.today.day
......@@ -40,6 +23,7 @@ RSpec.describe 'Project issue boards sidebar due date', :js do
wait_for_requests
expect(page).to have_content(today.to_s(:medium))
expect(due_date_value.text).to have_content Time.current.strftime('%b %-d, %Y')
end
end
end
......
......@@ -46,6 +46,10 @@ RSpec.shared_examples 'issue boards sidebar' do
it_behaves_like 'milestone sidebar widget'
end
context 'editing issue due date', :js do
it_behaves_like 'date sidebar widget'
end
context 'in notifications subscription' do
it 'displays notifications toggle', :aggregate_failures do
page.within('[data-testid="sidebar-notifications"]') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment