2019-09-30 12:06:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-03 20:46:49 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 09:08:32 +00:00
|
|
|
RSpec.describe BoardsHelper do
|
2021-02-19 18:10:51 +00:00
|
|
|
let_it_be(:user) { create(:user) }
|
2020-02-18 15:08:51 +00:00
|
|
|
let_it_be(:project) { create(:project) }
|
2021-02-19 18:10:51 +00:00
|
|
|
let_it_be(:base_group) { create(:group, path: 'base') }
|
|
|
|
let_it_be(:project_board) { create(:board, project: project) }
|
|
|
|
let_it_be(:group_board) { create(:board, group: base_group) }
|
2019-07-12 06:31:17 +00:00
|
|
|
|
2018-02-19 19:06:16 +00:00
|
|
|
describe '#build_issue_link_base' do
|
|
|
|
context 'project board' do
|
|
|
|
it 'returns correct path for project board' do
|
2021-02-19 18:10:51 +00:00
|
|
|
assign(:project, project)
|
|
|
|
assign(:board, project_board)
|
2018-02-19 19:06:16 +00:00
|
|
|
|
2021-02-19 18:10:51 +00:00
|
|
|
expect(helper.build_issue_link_base).to eq("/#{project.namespace.path}/#{project.path}/-/issues")
|
2018-02-19 19:06:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'group board' do
|
|
|
|
it 'returns correct path for base group' do
|
2021-02-19 18:10:51 +00:00
|
|
|
assign(:board, group_board)
|
2018-02-19 19:06:16 +00:00
|
|
|
|
2021-02-19 18:10:51 +00:00
|
|
|
expect(helper.build_issue_link_base).to eq('/base/:project_path/issues')
|
2018-02-19 19:06:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct path for subgroup' do
|
|
|
|
subgroup = create(:group, parent: base_group, path: 'sub')
|
2021-02-19 18:10:51 +00:00
|
|
|
assign(:board, create(:board, group: subgroup))
|
2018-02-19 19:06:16 +00:00
|
|
|
|
2021-02-19 18:10:51 +00:00
|
|
|
expect(helper.build_issue_link_base).to eq('/base/sub/:project_path/issues')
|
2018-02-19 19:06:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-19 18:10:51 +00:00
|
|
|
describe '#board_base_url' do
|
|
|
|
context 'when project board' do
|
|
|
|
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
|
2017-12-03 20:46:49 +00:00
|
|
|
|
2021-02-19 18:10:51 +00:00
|
|
|
describe '#board_data' do
|
2020-10-15 18:08:43 +00:00
|
|
|
context 'project_board' do
|
|
|
|
before do
|
|
|
|
assign(:project, project)
|
2021-02-19 18:10:51 +00:00
|
|
|
assign(:board, project_board)
|
2017-12-03 20:46:49 +00:00
|
|
|
|
2020-10-15 18:08:43 +00:00
|
|
|
allow(helper).to receive(:current_user) { user }
|
2021-02-19 18:10:51 +00:00
|
|
|
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)
|
2020-10-15 18:08:43 +00:00
|
|
|
end
|
2017-12-03 20:46:49 +00:00
|
|
|
|
2020-10-15 18:08:43 +00:00
|
|
|
it 'returns a board_lists_path as lists_endpoint' do
|
2021-02-19 18:10:51 +00:00
|
|
|
expect(helper.board_data[:lists_endpoint]).to eq(board_lists_path(project_board))
|
2020-10-15 18:08:43 +00:00
|
|
|
end
|
2020-04-30 09:09:39 +00:00
|
|
|
|
2020-10-15 18:08:43 +00:00
|
|
|
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
|
2020-04-30 09:09:39 +00:00
|
|
|
end
|
2020-09-22 03:09:49 +00:00
|
|
|
|
2020-10-15 18:08:43 +00:00
|
|
|
context 'group board' do
|
|
|
|
before do
|
2021-02-19 18:10:51 +00:00
|
|
|
assign(:group, base_group)
|
|
|
|
assign(:board, group_board)
|
2020-10-15 18:08:43 +00:00
|
|
|
|
|
|
|
allow(helper).to receive(:current_user) { user }
|
2021-02-19 18:10:51 +00:00
|
|
|
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)
|
2020-10-15 18:08:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct path for base group' do
|
2021-02-19 18:10:51 +00:00
|
|
|
expect(helper.build_issue_link_base).to eq("/#{base_group.full_path}/:project_path/issues")
|
2020-10-15 18:08:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns required label endpoints' do
|
2021-02-19 18:10:51 +00:00
|
|
|
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")
|
2020-10-15 18:08:43 +00:00
|
|
|
end
|
2020-09-22 03:09:49 +00:00
|
|
|
end
|
2017-12-03 20:46:49 +00:00
|
|
|
end
|
2019-07-12 06:31:17 +00:00
|
|
|
|
|
|
|
describe '#current_board_json' do
|
|
|
|
let(:board_json) { helper.current_board_json }
|
|
|
|
|
|
|
|
it 'can serialise with a basic set of attributes' do
|
2021-02-19 18:10:51 +00:00
|
|
|
assign(:board, project_board)
|
2019-07-12 06:31:17 +00:00
|
|
|
|
|
|
|
expect(board_json).to match_schema('current-board')
|
|
|
|
end
|
|
|
|
end
|
2017-12-03 20:46:49 +00:00
|
|
|
end
|