Skip to content

Commit

Permalink
Adapt Repositories Flags tests
Browse files Browse the repository at this point in the history
Co-authored-by: Ana María Martínez Gómez <ammartinez@suse.de>
  • Loading branch information
DavidKang and Ana06 committed Dec 10, 2018
1 parent 7c9d251 commit 2f35e55
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/api/app/views/webui2/shared/_repositories.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@
Build Flag
%span.flagerror
= render partial: 'shared/repositories_flag_table',
locals: { flags: build, project: project, package: package, architectures: architectures, user_can_set_flags: user_can_set_flags }
locals: { flags: build, project: project, package: package,
architectures: architectures, user_can_set_flags: user_can_set_flags,
table_id: 'flag_table_build' }
.col
%h5
Publish Flag
%span.flagerror
= render partial: 'shared/repositories_flag_table',
locals: { flags: publish, project: project, package: package, architectures: architectures, user_can_set_flags: user_can_set_flags }
locals: { flags: publish, project: project, package: package,
architectures: architectures, user_can_set_flags: user_can_set_flags,
table_id: 'flag_table_publish' }
.row
.col
%h5
Debuginfo Flag
%span.flagerror
= render partial: 'shared/repositories_flag_table',
locals: { flags: debuginfo, project: project, package: package, architectures: architectures, user_can_set_flags: user_can_set_flags }
locals: { flags: debuginfo, project: project, package: package,
architectures: architectures, user_can_set_flags: user_can_set_flags,
table_id: 'flag_table_debuginfo' }
.col
%h5
Use for Build Flag
%span.flagerror
= render partial: 'shared/repositories_flag_table',
locals: { flags: useforbuild, project: project, package: package, architectures: architectures, user_can_set_flags: user_can_set_flags }
locals: { flags: useforbuild, project: project, package: package,
architectures: architectures, user_can_set_flags: user_can_set_flags,
table_id: 'flag_table_useforbuild' }

= content_for :ready_function do
:plain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.table-responsive
%table.table.table-hover.table-sm
%table.table.table-hover.table-sm{ id: table_id }
%thead.thead-light
%tr
%th.w-auto Repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

%div{ id: flag.fullname }
= link_to('javascript:void(0)', title: title,
data: { html: 'true', toggle: user_can_set_flags ? 'popover' : '', placement: 'left', content: "#{content}" } ) do
data: { html: 'true', toggle: user_can_set_flags ? 'popover' : '', placement: 'left', content: "#{content}" }) do
%span.text-nowrap.current_flag_state
%i.fas{ class: icon_class }
- if is_flag_set_by_user
Expand Down
6 changes: 6 additions & 0 deletions src/api/spec/bootstrap/features/webui/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

RSpec.feature 'Bootstrap_Repositories', type: :feature, js: true, vcr: true do
let(:admin_user) { create(:admin_user) }
let!(:user) { create(:confirmed_user, login: 'Jane') }
let(:project) { user.home_project }

describe 'Repositories Flags' do
include_examples 'bootstrap tests for sections with flag tables'
end

describe 'DoD Repositories' do
let(:project_with_dod_repo) { create(:project) }
Expand Down
131 changes: 131 additions & 0 deletions src/api/spec/support/shared_examples/features/boostrap_flag_tables.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
RSpec.shared_examples 'bootstrap a flag table' do
def enable_flag_field_for(flag_attributes)
change_flag_field_to(flag_attributes, 'Enable', '.fa-check')
end

def disable_flag_field_for(flag_attributes)
change_flag_field_to(flag_attributes, 'Disable', '.fa-ban')
end

def change_flag_field_to(flag_attributes, state, icon)
locator = css_locator_for(flag_attributes[:repository], flag_attributes[:architecture])

subject.find(locator).find('.current_flag_state').click
within '.popover' do
click_link(state)
end
subject.find(locator).find(icon)
end

def css_locator_for(repository, architecture)
row = repo_cols.index(repository)
col = arch_rows.index(architecture) + 1

"tr:nth-child(#{row}) td:nth-child(#{col})"
end

let(:query_attributes) { { repo: nil, architecture_id: nil, flag: flag_type } }

scenario 'has correct table headers (arch labels)' do
expect(subject.find('tr:first-child th:nth-child(1)').text).to eq('Repository')
expect(subject.find('tr:first-child th:nth-child(2)').text).to eq('All')
architectures.each do |arch|
pos = architectures.index(arch) + 3
subject.find("tr:first-child th:nth-child(#{pos})", text: arch)
end
end

scenario 'has correct column descriptions (repository labels)' do
expect(subject.find('thead th:first-child').text).to eq('Repository')
expect(subject.find('tr:nth-child(1) td:first-child').text).to eq('All')
expect(subject.find('tr:nth-child(2) td:first-child').text).to eq(repository.name)
end

scenario 'toggle flags per repository' do
query_attributes[:repo] = repository.name

disable_flag_field_for(repository: repository.name, architecture: 'All')
expect(project.flags.reload.where(query_attributes.merge(status: :disable))).to exist

enable_flag_field_for(repository: repository.name, architecture: 'All')
expect(project.flags.reload.where(query_attributes.merge(status: :enable))).to exist
end

scenario 'toggle flags per arch' do
query_attributes[:architecture_id] = Architecture.find_by_name('i586')

disable_flag_field_for(repository: 'All', architecture: 'i586')
expect(project.flags.reload.where(query_attributes.merge(status: :disable))).to exist

enable_flag_field_for(repository: 'All', architecture: 'i586')
expect(project.flags.reload.where(query_attributes.merge(status: :enable))).to exist
end

scenario 'toggle all flags at once' do
query_attributes[:flag] = flag_type

disable_flag_field_for(repository: 'All', architecture: 'All')
expect(project.flags.reload.where(query_attributes.merge(status: :disable))).to exist

enable_flag_field_for(repository: 'All', architecture: 'All')
expect(project.flags.reload.where(query_attributes.merge(status: :enable))).to exist
end

scenario 'toggle a single flag' do
query_attributes.merge!(repo: repository.name, architecture_id: Architecture.find_by_name('x86_64'))

disable_flag_field_for(repository: repository.name, architecture: 'x86_64')
expect(project.flags.reload.where(status: 'disable')).to exist

enable_flag_field_for(repository: repository.name, architecture: 'x86_64')
expect(project.flags.reload.where(status: 'enable')).to exist
end
end

RSpec.shared_examples 'bootstrap tests for sections with flag tables' do
describe 'flags tables' do
let(:architectures) { ['i586', 'x86_64'] }
let!(:repository) { create(:repository, project: project, architectures: architectures) }
let(:arch_rows) { ['Repository', 'All'] + architectures }
let(:repo_cols) { ['Repository', 'All'] + project.repositories.pluck(:name) }

before do
login(user)
visit project_repositories_path(project: project)
end

describe '#flag_table_build' do
let(:flag_type) { 'build' }
subject { find('#flag_table_build') }

it_behaves_like 'bootstrap a flag table'
end

describe '#flag_table_publish' do
let(:flag_type) { 'publish' }
subject { find('#flag_table_publish') }

it_behaves_like 'bootstrap a flag table'
end

describe '#flag_table_debuginfo' do
let(:flag_type) { 'debuginfo' }
before do
# Default status would be 'disabled'
create(:debuginfo_flag, project: project)
visit project_repositories_path(project: project)
end

subject { find('#flag_table_debuginfo') }

it_behaves_like 'bootstrap a flag table'
end

describe '#flag_table_useforbuild' do
let(:flag_type) { 'useforbuild' }
subject { find('#flag_table_useforbuild') }

it_behaves_like 'bootstrap a flag table'
end
end
end

0 comments on commit 2f35e55

Please sign in to comment.