debian-mirror-gitlab/spec/features/nav/pinned_nav_items_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

196 lines
5.5 KiB
Ruby
Raw Permalink Normal View History

2023-06-20 00:43:36 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Navigation menu item pinning', :js, feature_category: :navigation do
let_it_be(:user) { create(:user, use_new_navigation: true) }
before do
sign_in(user)
end
describe 'non-pinnable navigation menu' do
before do
visit explore_projects_path
end
it 'does not show the Pinned section' do
within '#super-sidebar' do
expect(page).not_to have_content 'Pinned'
end
end
it 'does not show the buttons to pin items' do
within '#super-sidebar' do
expect(page).not_to have_css 'button svg[data-testid="thumbtack-icon"]'
end
end
end
describe 'pinnable navigation menu' do
let_it_be(:project) { create(:project) }
before do
project.add_member(user, :owner)
visit project_path(project)
end
2023-07-09 08:55:56 +05:30
it 'adds sensible defaults' do
within '[data-testid="pinned-nav-items"]' do
expect(page).to have_link 'Issues'
end
end
2023-06-20 00:43:36 +05:30
it 'shows the Pinned section' do
within '#super-sidebar' do
expect(page).to have_content 'Pinned'
end
end
it 'allows to pin items' do
within '#super-sidebar' do
click_on 'Manage'
add_pin('Activity')
add_pin('Members')
end
within '[data-testid="pinned-nav-items"]' do
2023-07-09 08:55:56 +05:30
expect(page).to have_link 'Issues'
2023-06-20 00:43:36 +05:30
expect(page).to have_link 'Activity'
expect(page).to have_link 'Members'
end
end
2023-07-09 08:55:56 +05:30
describe 'when all pins are removed' do
before do
remove_pin('Issues')
end
2023-06-20 00:43:36 +05:30
it 'shows the Pinned section as expanded by default' do
within '#super-sidebar' do
expect(page).to have_content 'Your pinned items appear here.'
end
end
it 'maintains the collapsed/expanded state between page loads' do
within '#super-sidebar' do
click_on 'Pinned'
visit project_path(project)
expect(page).not_to have_content 'Your pinned items appear here.'
click_on 'Pinned'
visit project_path(project)
expect(page).to have_content 'Your pinned items appear here.'
end
end
end
describe 'pinned items' do
before do
within '#super-sidebar' do
click_on 'Operate'
add_pin('Package Registry')
add_pin('Terraform modules')
wait_for_requests
end
end
it 'can be unpinned from within the pinned section' do
within '[data-testid="pinned-nav-items"]' do
remove_pin('Package Registry')
expect(page).not_to have_content 'Package Registry'
end
end
it 'can be unpinned from within its section' do
2023-07-09 08:55:56 +05:30
section = find("button", text: 'Operate')
2023-06-20 00:43:36 +05:30
within(section.sibling('ul')) do
remove_pin('Terraform modules')
end
within '[data-testid="pinned-nav-items"]' do
expect(page).not_to have_content 'Terraform modules'
end
end
it 'can be reordered' do
within '[data-testid="pinned-nav-items"]' do
pinned_items = page.find_all('a').map(&:text)
2023-07-09 08:55:56 +05:30
item2 = page.find('a', text: 'Package Registry')
item3 = page.find('a', text: 'Terraform modules')
expect(pinned_items[1..2]).to eq [item2.text, item3.text]
drag_item(item3, to: item2)
2023-06-20 00:43:36 +05:30
pinned_items = page.find_all('a').map(&:text)
2023-07-09 08:55:56 +05:30
expect(pinned_items[1..2]).to eq [item3.text, item2.text]
2023-06-20 00:43:36 +05:30
end
end
end
end
describe 'reordering pins with hidden pins from non-available features' do
let_it_be(:project_with_repo) { create(:project, :repository) }
let_it_be(:project_without_repo) { create(:project, :repository_disabled) }
before do
project_with_repo.add_member(user, :owner)
project_without_repo.add_member(user, :owner)
visit project_path(project_with_repo)
within '#super-sidebar' do
click_on 'Code'
add_pin('Commits')
click_on 'Manage'
add_pin('Activity')
add_pin('Members')
end
visit project_path(project_without_repo)
within '[data-testid="pinned-nav-items"]' do
activity_item = page.find('a', text: 'Activity')
members_item = page.find('a', text: 'Members')
drag_item(members_item, to: activity_item)
end
visit project_path(project_with_repo)
end
it 'keeps pins of non-available features' do
within '[data-testid="pinned-nav-items"]' do
2023-07-09 08:55:56 +05:30
pinned_items = page.find_all('a')
.map(&:text)
.map { |text| text.split("\n").first } # to drop the counter badge text from "Issues\n0"
expect(pinned_items).to eq ["Issues", "Merge requests", "Commits", "Members", "Activity"]
2023-06-20 00:43:36 +05:30
end
end
end
private
def add_pin(menu_item_title)
menu_item = find("[data-testid=\"nav-item-link\"]", text: menu_item_title)
menu_item.hover
menu_item.find("[data-testid=\"thumbtack-icon\"]").click
wait_for_requests
end
def remove_pin(menu_item_title)
menu_item = find("[data-testid=\"nav-item-link\"]", text: menu_item_title)
menu_item.hover
menu_item.find("[data-testid=\"thumbtack-solid-icon\"]").click
wait_for_requests
end
def drag_item(item, to:)
item.hover
drag_handle = item.find('[data-testid="grip-icon"]')
2023-07-09 08:55:56 +05:30
# Reduce delay to make it less likely for draggables to
# change position during drag operation, which reduces
# flakiness.
drag_handle.drag_to(to, delay: 0.01)
2023-06-20 00:43:36 +05:30
wait_for_requests
end
end