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>2021-11-02 15:12:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-02 15:12:25 +0300
commitd67ccb290ab5e54ff42f9cd464a132fc1d3067e1 (patch)
tree002a8f1b98a94a655638ce6ecbd079f4a758c8a0 /spec
parent157c4d9279f8ba1ad14debad9bdd017725bad316 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/boards/components/new_board_button_spec.js71
-rw-r--r--spec/helpers/groups_helper_spec.rb2
-rw-r--r--spec/helpers/user_callouts_helper_spec.rb14
-rw-r--r--spec/helpers/wiki_helper_spec.rb6
-rw-r--r--spec/lib/bulk_imports/groups/loaders/group_loader_spec.rb58
-rw-r--r--spec/models/namespace_spec.rb19
6 files changed, 146 insertions, 24 deletions
diff --git a/spec/frontend/boards/components/new_board_button_spec.js b/spec/frontend/boards/components/new_board_button_spec.js
new file mode 100644
index 00000000000..e66c31953f6
--- /dev/null
+++ b/spec/frontend/boards/components/new_board_button_spec.js
@@ -0,0 +1,71 @@
+import { mount } from '@vue/test-utils';
+import { GlButton } from '@gitlab/ui';
+import NewBoardButton from '~/boards/components/new_board_button.vue';
+import { extendedWrapper } from 'helpers/vue_test_utils_helper';
+import { assignGitlabExperiment } from 'helpers/experimentation_helper';
+import eventHub from '~/boards/eventhub';
+
+const FEATURE = 'prominent_create_board_btn';
+
+describe('NewBoardButton', () => {
+ let wrapper;
+
+ const createComponent = (args = {}) =>
+ extendedWrapper(
+ mount(NewBoardButton, {
+ provide: {
+ canAdminBoard: true,
+ multipleIssueBoardsAvailable: true,
+ ...args,
+ },
+ }),
+ );
+
+ afterEach(() => {
+ if (wrapper) {
+ wrapper.destroy();
+ }
+ });
+
+ describe('control variant', () => {
+ assignGitlabExperiment(FEATURE, 'control');
+
+ it('renders nothing', () => {
+ wrapper = createComponent();
+
+ expect(wrapper.text()).toBe('');
+ });
+ });
+
+ describe('candidate variant', () => {
+ assignGitlabExperiment(FEATURE, 'candidate');
+
+ it('renders New board button when `candidate` variant', () => {
+ wrapper = createComponent();
+
+ expect(wrapper.text()).toBe('New board');
+ });
+
+ it('renders nothing when `canAdminBoard` is `false`', () => {
+ wrapper = createComponent({ canAdminBoard: false });
+
+ expect(wrapper.find(GlButton).exists()).toBe(false);
+ });
+
+ it('renders nothing when `multipleIssueBoardsAvailable` is `false`', () => {
+ wrapper = createComponent({ multipleIssueBoardsAvailable: false });
+
+ expect(wrapper.find(GlButton).exists()).toBe(false);
+ });
+
+ it('emits `showBoardModal` when button is clicked', () => {
+ jest.spyOn(eventHub, '$emit').mockImplementation();
+
+ wrapper = createComponent();
+
+ wrapper.find(GlButton).vm.$emit('click', { preventDefault: () => {} });
+
+ expect(eventHub.$emit).toHaveBeenCalledWith('showBoardModal', 'new');
+ });
+ });
+});
diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb
index 4d647696130..8859ed27022 100644
--- a/spec/helpers/groups_helper_spec.rb
+++ b/spec/helpers/groups_helper_spec.rb
@@ -92,7 +92,7 @@ RSpec.describe GroupsHelper do
shared_examples 'correct ancestor order' do
it 'outputs the groups in the correct order' do
expect(subject)
- .to match(%r{<li style="text-indent: 16px;"><a.*>#{deep_nested_group.name}.*</li>.*<a.*>#{very_deep_nested_group.name}</a>}m)
+ .to match(%r{<li><a.*>#{deep_nested_group.name}.*</li>.*<a.*>#{very_deep_nested_group.name}</a>}m)
end
end
diff --git a/spec/helpers/user_callouts_helper_spec.rb b/spec/helpers/user_callouts_helper_spec.rb
index f738ba855b8..7abc67e29a4 100644
--- a/spec/helpers/user_callouts_helper_spec.rb
+++ b/spec/helpers/user_callouts_helper_spec.rb
@@ -216,20 +216,6 @@ RSpec.describe UserCalloutsHelper do
context 'when the invite_members_banner has not been dismissed' do
it { is_expected.to eq(true) }
- context 'when a user has dismissed this banner via cookies already' do
- before do
- helper.request.cookies["invite_#{group.id}_#{user.id}"] = 'true'
- end
-
- it { is_expected.to eq(false) }
-
- it 'creates the callout from cookie', :aggregate_failures do
- expect { subject }.to change { Users::GroupCallout.count }.by(1)
- expect(Users::GroupCallout.last).to have_attributes(group_id: group.id,
- feature_name: described_class::INVITE_MEMBERS_BANNER)
- end
- end
-
context 'when the group was just created' do
before do
flash[:notice] = "Group #{group.name} was successfully created"
diff --git a/spec/helpers/wiki_helper_spec.rb b/spec/helpers/wiki_helper_spec.rb
index dc76f92db1b..0d04ca2b876 100644
--- a/spec/helpers/wiki_helper_spec.rb
+++ b/spec/helpers/wiki_helper_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe WikiHelper do
it 'sets the title for the show action' do
expect(helper).to receive(:breadcrumb_title).with(page.human_title)
- expect(helper).to receive(:wiki_breadcrumb_dropdown_links).with(page.slug)
+ expect(helper).to receive(:wiki_breadcrumb_collapsed_links).with(page.slug)
expect(helper).to receive(:page_title).with(page.human_title, 'Wiki')
expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki))
@@ -17,7 +17,7 @@ RSpec.describe WikiHelper do
it 'sets the title for a custom action' do
expect(helper).to receive(:breadcrumb_title).with(page.human_title)
- expect(helper).to receive(:wiki_breadcrumb_dropdown_links).with(page.slug)
+ expect(helper).to receive(:wiki_breadcrumb_collapsed_links).with(page.slug)
expect(helper).to receive(:page_title).with('Edit', page.human_title, 'Wiki')
expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki))
@@ -27,7 +27,7 @@ RSpec.describe WikiHelper do
it 'sets the title for an unsaved page' do
expect(page).to receive(:persisted?).and_return(false)
expect(helper).not_to receive(:breadcrumb_title)
- expect(helper).not_to receive(:wiki_breadcrumb_dropdown_links)
+ expect(helper).not_to receive(:wiki_breadcrumb_collapsed_links)
expect(helper).to receive(:page_title).with('Wiki')
expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki))
diff --git a/spec/lib/bulk_imports/groups/loaders/group_loader_spec.rb b/spec/lib/bulk_imports/groups/loaders/group_loader_spec.rb
index de0b56045b3..69363bf0866 100644
--- a/spec/lib/bulk_imports/groups/loaders/group_loader_spec.rb
+++ b/spec/lib/bulk_imports/groups/loaders/group_loader_spec.rb
@@ -11,20 +11,66 @@ RSpec.describe BulkImports::Groups::Loaders::GroupLoader do
let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) }
let(:service_double) { instance_double(::Groups::CreateService) }
- let(:data) { { foo: :bar } }
+ let(:data) { { 'path' => 'test' } }
subject { described_class.new }
+ context 'when path is missing' do
+ it 'raises an error' do
+ expect { subject.load(context, {}) }.to raise_error(described_class::GroupCreationError, 'Path is missing')
+ end
+ end
+
+ context 'when destination namespace is not a group' do
+ it 'raises an error' do
+ entity.update!(destination_namespace: user.namespace.path)
+
+ expect { subject.load(context, data) }.to raise_error(described_class::GroupCreationError, 'Destination is not a group')
+ end
+ end
+
+ context 'when group exists' do
+ it 'raises an error' do
+ group1 = create(:group)
+ group2 = create(:group, parent: group1)
+ entity.update!(destination_namespace: group1.full_path)
+ data = { 'path' => group2.path }
+
+ expect { subject.load(context, data) }.to raise_error(described_class::GroupCreationError, 'Group exists')
+ end
+ end
+
+ context 'when there are other group errors' do
+ it 'raises an error with those errors' do
+ group = ::Group.new
+ group.validate
+ expected_errors = group.errors.full_messages.to_sentence
+
+ expect(::Groups::CreateService)
+ .to receive(:new)
+ .with(context.current_user, data)
+ .and_return(service_double)
+
+ expect(service_double).to receive(:execute).and_return(group)
+ expect(entity).not_to receive(:update!)
+
+ expect { subject.load(context, data) }.to raise_error(described_class::GroupCreationError, expected_errors)
+ end
+ end
+
context 'when user can create group' do
shared_examples 'calls Group Create Service to create a new group' do
it 'calls Group Create Service to create a new group' do
+ group_double = instance_double(::Group)
+
expect(::Groups::CreateService)
.to receive(:new)
.with(context.current_user, data)
.and_return(service_double)
- expect(service_double).to receive(:execute)
- expect(entity).to receive(:update!)
+ expect(service_double).to receive(:execute).and_return(group_double)
+ expect(group_double).to receive(:errors).and_return([])
+ expect(entity).to receive(:update!).with(group: group_double)
subject.load(context, data)
end
@@ -40,7 +86,7 @@ RSpec.describe BulkImports::Groups::Loaders::GroupLoader do
context 'when there is parent group' do
let(:parent) { create(:group) }
- let(:data) { { 'parent_id' => parent.id } }
+ let(:data) { { 'parent_id' => parent.id, 'path' => 'test' } }
before do
allow(Ability).to receive(:allowed?).with(user, :create_subgroup, parent).and_return(true)
@@ -55,7 +101,7 @@ RSpec.describe BulkImports::Groups::Loaders::GroupLoader do
it 'does not create new group' do
expect(::Groups::CreateService).not_to receive(:new)
- subject.load(context, data)
+ expect { subject.load(context, data) }.to raise_error(described_class::GroupCreationError, 'User not allowed to create group')
end
end
@@ -69,7 +115,7 @@ RSpec.describe BulkImports::Groups::Loaders::GroupLoader do
context 'when there is parent group' do
let(:parent) { create(:group) }
- let(:data) { { 'parent_id' => parent.id } }
+ let(:data) { { 'parent_id' => parent.id, 'path' => 'test' } }
before do
allow(Ability).to receive(:allowed?).with(user, :create_subgroup, parent).and_return(false)
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 808343ffae9..4dae5b5201e 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -559,6 +559,25 @@ RSpec.describe Namespace do
it 'returns namespaces with a matching route path regardless of the casing' do
expect(described_class.search('PARENT-PATH/NEW-PATH', include_parents: true)).to eq([second_group])
end
+
+ context 'with project namespaces' do
+ let_it_be(:project) { create(:project, namespace: parent_group, path: 'some-new-path') }
+ let_it_be(:project_namespace) { create(:project_namespace, project: project) }
+
+ it 'does not return project namespace' do
+ search_result = described_class.search('path')
+
+ expect(search_result).not_to include(project_namespace)
+ expect(search_result).to match_array([first_group, parent_group, second_group])
+ end
+
+ it 'does not return project namespace when including parents' do
+ search_result = described_class.search('path', include_parents: true)
+
+ expect(search_result).not_to include(project_namespace)
+ expect(search_result).to match_array([first_group, parent_group, second_group])
+ end
+ end
end
describe '.with_statistics' do