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