debian-mirror-gitlab/spec/helpers/boards_helper_spec.rb

187 lines
6.3 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe BoardsHelper do
2021-04-17 20:07:23 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:base_group) { create(:group, path: 'base') }
let_it_be(:project) { create(:project, group: base_group) }
let_it_be(:project_board) { create(:board, project: project) }
let_it_be(:group_board) { create(:board, group: base_group) }
2019-09-30 21:07:59 +05:30
2018-03-27 19:54:05 +05:30
describe '#build_issue_link_base' do
context 'project board' do
it 'returns correct path for project board' do
2021-04-17 20:07:23 +05:30
assign(:project, project)
assign(:board, project_board)
2018-03-27 19:54:05 +05:30
2021-04-17 20:07:23 +05:30
expect(helper.build_issue_link_base).to eq("/#{project.namespace.path}/#{project.path}/-/issues")
2018-03-27 19:54:05 +05:30
end
end
context 'group board' do
it 'returns correct path for base group' do
2021-04-17 20:07:23 +05:30
assign(:board, group_board)
2018-03-27 19:54:05 +05:30
2021-04-17 20:07:23 +05:30
expect(helper.build_issue_link_base).to eq('/base/:project_path/issues')
2018-03-27 19:54:05 +05:30
end
it 'returns correct path for subgroup' do
subgroup = create(:group, parent: base_group, path: 'sub')
2021-04-17 20:07:23 +05:30
assign(:board, create(:board, group: subgroup))
2018-03-27 19:54:05 +05:30
2021-04-17 20:07:23 +05:30
expect(helper.build_issue_link_base).to eq('/base/sub/:project_path/issues')
2018-03-27 19:54:05 +05:30
end
end
end
2021-04-17 20:07:23 +05:30
describe '#board_base_url' do
2021-06-08 01:23:25 +05:30
context 'when group board' do
2021-04-17 20:07:23 +05:30
it 'generates the correct url' do
assign(:board, group_board)
assign(:group, base_group)
expect(helper.board_base_url).to eq "http://test.host/groups/#{base_group.full_path}/-/boards"
end
end
context 'when project board' do
it 'generates the correct url' do
assign(:board, project_board)
assign(:project, project)
expect(helper.board_base_url).to eq "/#{project.full_path}/-/boards"
end
end
end
2018-03-17 18:26:18 +05:30
2021-06-08 01:23:25 +05:30
describe '#current_board_namespace' do
context 'when group board' do
it 'returns the correct namespace' do
assign(:board, group_board)
assign(:group, base_group)
expect(helper.current_board_namespace).to be(base_group)
end
end
context 'project under group' do
context 'when project board' do
it 'returns the correct namespace' do
assign(:project, project)
assign(:board, project_board)
expect(helper.current_board_namespace).to be(project.parent)
end
end
end
context 'project under user namespace' do
let_it_be(:project_under_user) { create(:project, namespace: user.namespace) }
context 'when project board' do
let_it_be(:project_board) { create(:board, project: project_under_user) }
it 'returns the correct namespace' do
assign(:project, project_under_user)
assign(:board, project_board)
expect(helper.current_board_namespace).to be(user.namespace)
end
end
end
end
2021-04-17 20:07:23 +05:30
describe '#board_data' do
2021-01-03 14:25:43 +05:30
context 'project_board' do
before do
assign(:project, project)
2021-04-17 20:07:23 +05:30
assign(:board, project_board)
2018-03-17 18:26:18 +05:30
2021-01-03 14:25:43 +05:30
allow(helper).to receive(:current_user) { user }
2021-04-17 20:07:23 +05:30
allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, project_board).and_return(true)
allow(helper).to receive(:can?).with(user, :admin_issue, project_board).and_return(true)
2021-04-29 21:17:54 +05:30
allow(helper).to receive(:can?).with(user, :admin_issue_board_list, project).and_return(false)
2021-01-03 14:25:43 +05:30
end
it 'returns a board_lists_path as lists_endpoint' do
2021-04-17 20:07:23 +05:30
expect(helper.board_data[:lists_endpoint]).to eq(board_lists_path(project_board))
2021-01-03 14:25:43 +05:30
end
2018-03-17 18:26:18 +05:30
2021-01-03 14:25:43 +05:30
it 'returns board type as parent' do
expect(helper.board_data[:parent]).to eq('project')
end
it 'returns can_update for user permissions on the board' do
expect(helper.board_data[:can_update]).to eq('true')
end
it 'returns required label endpoints' do
expect(helper.board_data[:labels_fetch_path]).to eq("/#{project.full_path}/-/labels.json?include_ancestor_groups=true")
expect(helper.board_data[:labels_manage_path]).to eq("/#{project.full_path}/-/labels")
end
2021-04-17 20:07:23 +05:30
it 'returns the group id of a project' do
expect(helper.board_data[:group_id]).to eq(project.group.id)
end
2021-04-29 21:17:54 +05:30
context 'can_admin_list' do
it 'returns can_admin_list as false by default' do
expect(helper.board_data[:can_admin_list]).to eq('false')
end
it 'returns can_admin_list as true when user can admin the board' do
allow(helper).to receive(:can?).with(user, :admin_issue_board_list, project).and_return(true)
expect(helper.board_data[:can_admin_list]).to eq('true')
end
end
2018-03-17 18:26:18 +05:30
end
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
context 'group board' do
before do
2021-04-17 20:07:23 +05:30
assign(:group, base_group)
assign(:board, group_board)
2021-01-03 14:25:43 +05:30
allow(helper).to receive(:current_user) { user }
2021-04-17 20:07:23 +05:30
allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, group_board).and_return(true)
allow(helper).to receive(:can?).with(user, :admin_issue, group_board).and_return(true)
2021-04-29 21:17:54 +05:30
allow(helper).to receive(:can?).with(user, :admin_issue_board_list, base_group).and_return(false)
2021-01-03 14:25:43 +05:30
end
it 'returns correct path for base group' do
2021-04-17 20:07:23 +05:30
expect(helper.build_issue_link_base).to eq("/#{base_group.full_path}/:project_path/issues")
2021-01-03 14:25:43 +05:30
end
it 'returns required label endpoints' do
2021-04-17 20:07:23 +05:30
expect(helper.board_data[:labels_fetch_path]).to eq("/groups/#{base_group.full_path}/-/labels.json?include_ancestor_groups=true&only_group_labels=true")
expect(helper.board_data[:labels_manage_path]).to eq("/groups/#{base_group.full_path}/-/labels")
end
it 'returns the group id' do
expect(helper.board_data[:group_id]).to eq(base_group.id)
2021-01-03 14:25:43 +05:30
end
2021-04-29 21:17:54 +05:30
context 'can_admin_list' do
it 'returns can_admin_list as false by default' do
expect(helper.board_data[:can_admin_list]).to eq('false')
end
it 'returns can_admin_list as true when user can admin the board' do
allow(helper).to receive(:can?).with(user, :admin_issue_board_list, base_group).and_return(true)
expect(helper.board_data[:can_admin_list]).to eq('true')
end
end
2020-05-24 23:13:21 +05:30
end
2018-03-17 18:26:18 +05:30
end
2019-09-30 21:07:59 +05:30
describe '#current_board_json' do
let(:board_json) { helper.current_board_json }
it 'can serialise with a basic set of attributes' do
2021-04-17 20:07:23 +05:30
assign(:board, project_board)
2019-09-30 21:07:59 +05:30
expect(board_json).to match_schema('current-board')
end
end
2018-03-17 18:26:18 +05:30
end