Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-24 15:09:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-24 15:09:24 +0300
commit17c1c66eefd05243dd8ed2c8fd49d17ab1a52522 (patch)
treea6f7c103902284c8245bc1991769916139f60aa9 /spec
parent3a4363e0098b1ff7689247e55da416848ac51050 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/incidents/incident_timeline_events_spec.rb168
-rw-r--r--spec/frontend/blob/components/table_contents_spec.js48
-rw-r--r--spec/helpers/projects_helper_spec.rb56
-rw-r--r--spec/support/helpers/test_env.rb2
-rw-r--r--spec/support/shared_examples/features/incident_details_routing_shared_examples.rb28
5 files changed, 135 insertions, 167 deletions
diff --git a/spec/features/incidents/incident_timeline_events_spec.rb b/spec/features/incidents/incident_timeline_events_spec.rb
index 45518671c57..ffab23c58bc 100644
--- a/spec/features/incidents/incident_timeline_events_spec.rb
+++ b/spec/features/incidents/incident_timeline_events_spec.rb
@@ -4,171 +4,101 @@ require 'spec_helper'
RSpec.describe 'Incident timeline events', :js, feature_category: :incident_management do
let_it_be(:project) { create(:project) }
- let_it_be(:developer) { create(:user) }
+ let_it_be(:user) { create(:user, developer_projects: [project]) }
let_it_be(:incident) { create(:incident, project: project) }
- before_all do
- project.add_developer(developer)
- end
-
- before do
- sign_in(developer)
-
- visit incident_project_issues_path(project, incident)
- wait_for_requests
- click_link s_('Incident|Timeline')
- end
-
- context 'when add event is clicked' do
- it 'submits event data when save is clicked' do
- click_button s_('Incident|Add new timeline event')
-
- expect(page).to have_selector('.common-note-form')
-
- fill_in _('Description'), with: 'Event note goes here'
- fill_in 'timeline-input-hours', with: '07'
- fill_in 'timeline-input-minutes', with: '25'
-
- click_button _('Save')
+ shared_examples 'add, edit, and delete timeline events' do
+ it 'submits event data on save' do
+ # Add event
+ click_button(s_('Incident|Add new timeline event'))
+ complete_form('Event note goes here', '07', '25')
expect(page).to have_selector('.incident-timeline-events')
-
page.within '.timeline-event-note' do
expect(page).to have_content('Event note goes here')
expect(page).to have_content('07:25')
end
- end
- end
-
- context 'when add event is clicked and feature flag enabled' do
- before do
- stub_feature_flags(incident_event_tags: true)
- end
-
- it 'submits event data with tags when save is clicked' do
- click_button s_('Incident|Add new timeline event')
-
- expect(page).to have_selector('.common-note-form')
- fill_in _('Description'), with: 'Event note goes here'
- fill_in 'timeline-input-hours', with: '07'
- fill_in 'timeline-input-minutes', with: '25'
-
- click_button _('Select tags')
-
- page.within '.gl-dropdown-inner' do
- expect(page).to have_content(_('Start time'))
- page.find('.gl-dropdown-item-text-wrapper', text: _('Start time')).click
- end
-
- click_button _('Save')
-
- expect(page).to have_selector('.incident-timeline-events')
+ # Edit event
+ trigger_dropdown_action(_('Edit'))
+ complete_form('Edited event note goes here', '08', '30')
page.within '.timeline-event-note' do
- expect(page).to have_content('Event note goes here')
- expect(page).to have_content('07:25')
- expect(page).to have_content('Start time')
+ expect(page).to have_content('Edited event note goes here')
+ expect(page).to have_content('08:30')
end
- end
- end
- context 'when edit is clicked' do
- before do
- click_button 'Add new timeline event'
- fill_in 'Description', with: 'Event note to edit'
- click_button _('Save')
- end
+ # Delete event
+ trigger_dropdown_action(_('Delete'))
- it 'shows the confirmation modal and edits the event' do
- click_button _('More actions')
-
- page.within '.gl-dropdown-contents' do
- expect(page).to have_content(_('Edit'))
- page.find('.gl-dropdown-item-text-primary', text: _('Edit')).click
+ page.within '.modal' do
+ expect(page).to have_content(s_('Incident|Delete event'))
end
- expect(page).to have_selector('.common-note-form')
-
- fill_in _('Description'), with: 'Event note goes here'
- fill_in 'timeline-input-hours', with: '07'
- fill_in 'timeline-input-minutes', with: '25'
-
- click_button _('Save')
-
+ click_button s_('Incident|Delete event')
wait_for_requests
- page.within '.timeline-event-note' do
- expect(page).to have_content('Event note goes here')
- expect(page).to have_content('07:25')
- end
+ expect(page).to have_content(s_('Incident|No timeline items have been added yet.'))
end
- end
- context 'when edit is clicked and feature flag enabled' do
- before do
+ it 'submits event data on save with feature flag on' do
stub_feature_flags(incident_event_tags: true)
- click_button 'Add new timeline event'
- fill_in 'Description', with: 'Event note to edit'
- click_button _('Select tags')
+ # Add event
+ click_button(s_('Incident|Add new timeline event'))
+
+ click_button _('Select tags')
page.within '.gl-dropdown-inner' do
+ expect(page).to have_content(_('Start time'))
page.find('.gl-dropdown-item-text-wrapper', text: _('Start time')).click
end
- click_button _('Save')
- end
- it 'shows the confirmation modal and edits the event tags' do
- click_button _('More actions')
+ complete_form('Event note goes here', '07', '25')
- page.within '.gl-dropdown-contents' do
- expect(page).to have_content(_('Edit'))
- page.find('.gl-dropdown-item-text-primary', text: _('Edit')).click
+ expect(page).to have_selector('.incident-timeline-events')
+ page.within '.timeline-event-note' do
+ expect(page).to have_content('Event note goes here')
+ expect(page).to have_content('07:25')
+ expect(page).to have_content('Start time')
end
- expect(page).to have_selector('.common-note-form')
-
- click_button s_('Start time')
+ # Edit event
+ trigger_dropdown_action(_('Edit'))
+ click_button _('Start time')
page.within '.gl-dropdown-inner' do
- expect(page).to have_content(_('Start time'))
page.find('.gl-dropdown-item-text-wrapper', text: _('Start time')).click
end
-
- click_button _('Save')
-
- wait_for_requests
+ complete_form('Edited event note goes here', '08', '30')
page.within '.timeline-event-note' do
+ expect(page).to have_content('Edited event note goes here')
+ expect(page).to have_content('08:30')
expect(page).not_to have_content('Start time')
end
end
- end
- context 'when delete is clicked' do
- before do
- click_button s_('Incident|Add new timeline event')
- fill_in _('Description'), with: 'Event note to delete'
+ private
+
+ def complete_form(title, hours, minutes)
+ fill_in _('Description'), with: title
+ fill_in 'timeline-input-hours', with: hours
+ fill_in 'timeline-input-minutes', with: minutes
+
click_button _('Save')
+ wait_for_requests
end
- it 'shows the confirmation modal and deletes the event' do
+ def trigger_dropdown_action(text)
click_button _('More actions')
page.within '.gl-dropdown-contents' do
- expect(page).to have_content(_('Delete'))
- page.find('.gl-dropdown-item-text-primary', text: 'Delete').click
+ page.find('.gl-dropdown-item', text: text).click
end
-
- page.within '.modal' do
- expect(page).to have_content(s_('Incident|Delete event'))
- end
-
- click_button s_('Incident|Delete event')
-
- wait_for_requests
-
- expect(page).to have_content(s_('Incident|No timeline items have been added yet.'))
end
end
+
+ it_behaves_like 'for each incident details route',
+ 'add, edit, and delete timeline events',
+ tab_text: s_('Incident|Timeline')
end
diff --git a/spec/frontend/blob/components/table_contents_spec.js b/spec/frontend/blob/components/table_contents_spec.js
index 5fe328b65ff..6af9cdcae7d 100644
--- a/spec/frontend/blob/components/table_contents_spec.js
+++ b/spec/frontend/blob/components/table_contents_spec.js
@@ -1,4 +1,4 @@
-import { GlDropdownItem } from '@gitlab/ui';
+import { GlDisclosureDropdown } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
@@ -10,6 +10,8 @@ function createComponent() {
wrapper = shallowMount(TableContents);
}
+const findDropdown = () => wrapper.findComponent(GlDisclosureDropdown);
+
async function setLoaded(loaded) {
document.querySelector('.blob-viewer').dataset.loaded = loaded;
@@ -20,10 +22,10 @@ describe('Markdown table of contents component', () => {
beforeEach(() => {
setHTMLFixture(`
<div class="blob-viewer" data-type="rich" data-loaded="false">
- <h1><a href="#1"></a>Hello</h1>
- <h2><a href="#2"></a>World</h2>
- <h3><a href="#3"></a>Testing</h3>
- <h2><a href="#4"></a>GitLab</h2>
+ <h1><a id="hello">$</a> Hello</h1>
+ <h2><a id="world">$</a> World</h2>
+ <h3><a id="hakuna">$</a> Hakuna</h3>
+ <h2><a id="matata">$</a> Matata</h2>
</div>
`);
});
@@ -34,12 +36,10 @@ describe('Markdown table of contents component', () => {
});
describe('not loaded', () => {
- const findDropdownItem = () => wrapper.findComponent(GlDropdownItem);
-
it('does not populate dropdown', () => {
createComponent();
- expect(findDropdownItem().exists()).toBe(false);
+ expect(findDropdown().exists()).toBe(false);
});
it('does not show dropdown when loading blob content', async () => {
@@ -47,7 +47,7 @@ describe('Markdown table of contents component', () => {
await setLoaded(false);
- expect(findDropdownItem().exists()).toBe(false);
+ expect(findDropdown().exists()).toBe(false);
});
it('does not show dropdown when viewing non-rich content', async () => {
@@ -57,7 +57,7 @@ describe('Markdown table of contents component', () => {
await setLoaded(true);
- expect(findDropdownItem().exists()).toBe(false);
+ expect(findDropdown().exists()).toBe(false);
});
});
@@ -67,15 +67,25 @@ describe('Markdown table of contents component', () => {
await setLoaded(true);
- const dropdownItems = wrapper.findAllComponents(GlDropdownItem);
+ const dropdown = findDropdown();
- expect(dropdownItems.exists()).toBe(true);
- expect(dropdownItems.length).toBe(4);
+ expect(dropdown.exists()).toBe(true);
+ expect(dropdown.props('items').length).toBe(4);
// make sure that this only happens once
await setLoaded(true);
- expect(wrapper.findAllComponents(GlDropdownItem).length).toBe(4);
+ expect(dropdown.props('items').length).toBe(4);
+ });
+
+ it('generates proper anchor links', async () => {
+ createComponent();
+ await setLoaded(true);
+
+ const dropdown = findDropdown();
+ const items = dropdown.props('items');
+ const hrefs = items.map((item) => item.href);
+ expect(hrefs).toEqual(['#hello', '#world', '#hakuna', '#matata']);
});
it('sets padding for dropdown items', async () => {
@@ -83,12 +93,12 @@ describe('Markdown table of contents component', () => {
await setLoaded(true);
- const dropdownLinks = wrapper.findAll('[data-testid="tableContentsLink"]');
+ const items = findDropdown().props('items');
- expect(dropdownLinks.at(0).element.style.paddingLeft).toBe('0px');
- expect(dropdownLinks.at(1).element.style.paddingLeft).toBe('8px');
- expect(dropdownLinks.at(2).element.style.paddingLeft).toBe('16px');
- expect(dropdownLinks.at(3).element.style.paddingLeft).toBe('8px');
+ expect(items[0].extraAttrs.style.paddingLeft).toBe('16px');
+ expect(items[1].extraAttrs.style.paddingLeft).toBe('24px');
+ expect(items[2].extraAttrs.style.paddingLeft).toBe('32px');
+ expect(items[3].extraAttrs.style.paddingLeft).toBe('24px');
});
});
});
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index 2da9f7b1ebc..477b5cd7753 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe ProjectsHelper do
+RSpec.describe ProjectsHelper, feature_category: :source_code_management do
include ProjectForksHelper
include AfterNextHelpers
@@ -582,46 +582,24 @@ RSpec.describe ProjectsHelper do
end
end
- describe '#show_merge_request_count' do
+ describe '#show_count?' do
context 'enabled flag' do
it 'returns true if compact mode is disabled' do
- expect(helper.show_merge_request_count?).to be_truthy
+ expect(helper.show_count?).to be_truthy
end
it 'returns false if compact mode is enabled' do
- expect(helper.show_merge_request_count?(compact_mode: true)).to be_falsey
+ expect(helper.show_count?(compact_mode: true)).to be_falsey
end
end
context 'disabled flag' do
it 'returns false if disabled flag is true' do
- expect(helper.show_merge_request_count?(disabled: true)).to be_falsey
+ expect(helper.show_count?(disabled: true)).to be_falsey
end
it 'returns true if disabled flag is false' do
- expect(helper.show_merge_request_count?).to be_truthy
- end
- end
- end
-
- describe '#show_issue_count?' do
- context 'enabled flag' do
- it 'returns true if compact mode is disabled' do
- expect(helper.show_issue_count?).to be_truthy
- end
-
- it 'returns false if compact mode is enabled' do
- expect(helper.show_issue_count?(compact_mode: true)).to be_falsey
- end
- end
-
- context 'disabled flag' do
- it 'returns false if disabled flag is true' do
- expect(helper.show_issue_count?(disabled: true)).to be_falsey
- end
-
- it 'returns true if disabled flag is false' do
- expect(helper.show_issue_count?).to be_truthy
+ expect(helper).to be_show_count
end
end
end
@@ -1050,6 +1028,28 @@ RSpec.describe ProjectsHelper do
end
end
end
+
+ describe '#able_to_see_forks_count?' do
+ subject { helper.able_to_see_forks_count?(project, user) }
+
+ where(:can_read_code, :forking_enabled, :expected) do
+ false | false | false
+ true | false | false
+ false | true | false
+ true | true | true
+ end
+
+ with_them do
+ before do
+ allow(project).to receive(:forking_enabled?).and_return(forking_enabled)
+ allow(helper).to receive(:can?).with(user, :read_code, project).and_return(can_read_code)
+ end
+
+ it 'returns the correct response' do
+ expect(subject).to eq(expected)
+ end
+ end
+ end
end
describe '#fork_button_disabled_tooltip' do
diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb
index 3530d1b1a39..3403064bf0b 100644
--- a/spec/support/helpers/test_env.rb
+++ b/spec/support/helpers/test_env.rb
@@ -423,7 +423,7 @@ module TestEnv
return if File.exist?(install_dir) && ci?
if component_needs_update?(install_dir, version)
- puts "==> Starting #{component} set up...\n"
+ puts "==> Starting #{component} (#{version}) set up...\n"
# Cleanup the component entirely to ensure we start fresh
FileUtils.rm_rf(install_dir) if fresh_install
diff --git a/spec/support/shared_examples/features/incident_details_routing_shared_examples.rb b/spec/support/shared_examples/features/incident_details_routing_shared_examples.rb
new file mode 100644
index 00000000000..dab125caa60
--- /dev/null
+++ b/spec/support/shared_examples/features/incident_details_routing_shared_examples.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'for each incident details route' do |example, tab_text:|
+ before do
+ sign_in(user)
+ visit incident_path
+ end
+
+ context 'for /-/issues/:id route' do
+ let(:incident_path) { project_issue_path(project, incident) }
+
+ before do
+ page.within('[data-testid="incident-tabs"]') { click_link tab_text }
+ end
+
+ it_behaves_like example
+ end
+
+ context 'for /-/issues/incident/:id route' do
+ let(:incident_path) { incident_project_issues_path(project, incident) }
+
+ before do
+ page.within('[data-testid="incident-tabs"]') { click_link tab_text }
+ end
+
+ it_behaves_like example
+ end
+end