Commit b18556f0 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'rs-new-menu-spec' into 'master'

Convert "New menu" feature spec to a view spec

Closes #54157

See merge request gitlab-org/gitlab-ce!23355
parents efe4067e 6d754eb1
......@@ -7,15 +7,14 @@
- if @group&.persisted?
- create_group_project = can?(current_user, :create_projects, @group)
- create_group_subgroup = can?(current_user, :create_subgroup, @group)
- if create_group_project || create_group_subgroup
%li.dropdown-bold-header
= _('This group')
- if create_group_project
%li.header-new-group-project
= link_to _('New project'), new_project_path(namespace_id: @group.id)
%li= link_to _('New project'), new_project_path(namespace_id: @group.id)
- if create_group_subgroup
%li
= link_to _('New subgroup'), new_group_path(parent_id: @group.id)
%li= link_to _('New subgroup'), new_group_path(parent_id: @group.id)
%li.divider
%li.dropdown-bold-header GitLab
......@@ -23,25 +22,20 @@
- create_project_issue = show_new_issue_link?(@project)
- merge_project = merge_request_source_project_for_project(@project)
- create_project_snippet = can?(current_user, :create_project_snippet, @project)
- if create_project_issue || merge_project || create_project_snippet
%li.dropdown-bold-header
= _('This project')
- if create_project_issue
%li
= link_to _('New issue'), new_project_issue_path(@project)
%li= link_to _('New issue'), new_project_issue_path(@project)
- if merge_project
%li
= link_to _('New merge request'), project_new_merge_request_path(merge_project)
%li= link_to _('New merge request'), project_new_merge_request_path(merge_project)
- if create_project_snippet
%li.header-new-project-snippet
= link_to _('New snippet'), new_project_snippet_path(@project)
%li= link_to _('New snippet'), new_project_snippet_path(@project)
%li.divider
%li.dropdown-bold-header GitLab
- if current_user.can_create_project?
%li
= link_to _('New project'), new_project_path, class: 'qa-global-new-project-link'
%li= link_to _('New project'), new_project_path, class: 'qa-global-new-project-link'
- if current_user.can_create_group?
%li
= link_to _('New group'), new_group_path
%li
= link_to _('New snippet'), new_snippet_path
%li= link_to _('New group'), new_group_path
%li= link_to _('New snippet'), new_snippet_path
require 'spec_helper'
describe 'Top Plus Menu', :js do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
let(:public_project) { create(:project, :public) }
before do
group.add_owner(user)
end
context 'used by full user' do
before do
sign_in(user)
end
it 'click on New project shows new project page' do
visit root_dashboard_path
click_topmenuitem("New project")
expect(page).to have_content('Project URL')
expect(page).to have_content('Project name')
end
it 'click on New group shows new group page' do
visit root_dashboard_path
click_topmenuitem("New group")
expect(page).to have_content('Group URL')
expect(page).to have_content('Group name')
end
it 'click on New snippet shows new snippet page' do
visit root_dashboard_path
click_topmenuitem("New snippet")
expect(page).to have_content('New Snippet')
expect(page).to have_content('Title')
end
it 'click on New issue shows new issue page' do
visit project_path(project)
click_topmenuitem("New issue")
expect(page).to have_content('New Issue')
expect(page).to have_content('Title')
end
it 'click on New merge request shows new merge request page' do
visit project_path(project)
click_topmenuitem("New merge request")
expect(page).to have_content('New Merge Request')
expect(page).to have_content('Source branch')
expect(page).to have_content('Target branch')
end
it 'click on New project snippet shows new snippet page' do
visit project_path(project)
page.within '.header-content' do
find('.header-new-dropdown-toggle').click
expect(page).to have_selector('.header-new.dropdown.show', count: 1)
find('.header-new-project-snippet a').click
end
expect(page).to have_content('New Snippet')
expect(page).to have_content('Title')
end
it 'Click on New subgroup shows new group page', :nested_groups do
visit group_path(group)
click_topmenuitem("New subgroup")
expect(page).to have_content('Group URL')
expect(page).to have_content('Group name')
end
it 'Click on New project in group shows new project page' do
visit group_path(group)
page.within '.header-content' do
find('.header-new-dropdown-toggle').click
expect(page).to have_selector('.header-new.dropdown.show', count: 1)
find('.header-new-group-project a').click
end
expect(page).to have_content('Project URL')
expect(page).to have_content('Project name')
end
end
context 'used by guest user' do
let(:guest_user) { create(:user) }
before do
group.add_guest(guest_user)
project.add_guest(guest_user)
sign_in(guest_user)
end
it 'click on New issue shows new issue page' do
visit project_path(project)
click_topmenuitem("New issue")
expect(page).to have_content('New Issue')
expect(page).to have_content('Title')
end
it 'has no New merge request menu item' do
visit project_path(project)
hasnot_topmenuitem("New merge request")
end
it 'has no New project snippet menu item' do
visit project_path(project)
expect(find('.header-new.dropdown')).not_to have_selector('.header-new-project-snippet')
end
it 'public project has no New merge request menu item' do
visit project_path(public_project)
hasnot_topmenuitem("New merge request")
end
it 'public project has no New project snippet menu item' do
visit project_path(public_project)
expect(find('.header-new.dropdown')).not_to have_selector('.header-new-project-snippet')
end
it 'has no New subgroup menu item' do
visit group_path(group)
hasnot_topmenuitem("New subgroup")
end
it 'has no New project for group menu item' do
visit group_path(group)
expect(find('.header-new.dropdown')).not_to have_selector('.header-new-group-project')
end
end
def click_topmenuitem(item_name)
page.within '.header-content' do
find('.header-new-dropdown-toggle').click
expect(page).to have_selector('.header-new.dropdown.show', count: 1)
click_link item_name
end
end
def hasnot_topmenuitem(item_name)
expect(find('.header-new.dropdown')).not_to have_content(item_name)
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'layouts/header/_new_dropdown' do
let(:user) { create(:user) }
context 'group-specific links' do
let(:group) { create(:group) }
before do
stub_current_user(user)
assign(:group, group)
end
context 'as a Group owner' do
before do
group.add_owner(user)
end
it 'has a "New project" link' do
render
expect(rendered).to have_link(
'New project',
href: new_project_path(namespace_id: group.id)
)
end
it 'has a "New subgroup" link', :nested_groups do
render
expect(rendered).to have_link(
'New subgroup',
href: new_group_path(parent_id: group.id)
)
end
end
end
context 'project-specific links' do
let(:project) { create(:project, creator: user, namespace: user.namespace) }
before do
assign(:project, project)
end
context 'as a Project owner' do
before do
stub_current_user(user)
end
it 'has a "New issue" link' do
render
expect(rendered).to have_link(
'New issue',
href: new_project_issue_path(project)
)
end
it 'has a "New merge request" link' do
render
expect(rendered).to have_link(
'New merge request',
href: project_new_merge_request_path(project)
)
end
it 'has a "New snippet" link' do
render
expect(rendered).to have_link(
'New snippet',
href: new_project_snippet_path(project)
)
end
end
context 'as a Project guest' do
let(:guest) { create(:user) }
before do
stub_current_user(guest)
project.add_guest(guest)
end
it 'has no "New merge request" link' do
render
expect(rendered).not_to have_link('New merge request')
end
it 'has no "New snippet" link' do
render
expect(rendered).not_to have_link(
'New snippet',
href: new_project_snippet_path(project)
)
end
end
end
context 'global links' do
before do
stub_current_user(user)
end
it 'has a "New project" link' do
render
expect(rendered).to have_link('New project', href: new_project_path)
end
it 'has a "New group" link' do
render
expect(rendered).to have_link('New group', href: new_group_path)
end
it 'has a "New snippet" link' do
render
expect(rendered).to have_link('New snippet', href: new_snippet_path)
end
end
def stub_current_user(current_user)
allow(view).to receive(:current_user).and_return(current_user)
end
end
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