From d8c0303c4f00998c546e9d3d06c0b13ed89b0391 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 16 Nov 2017 07:55:12 +0100 Subject: Refs: #4823@0.2h; Code Review Part II --- config/locales/compliance_check_sets.en.yml | 2 +- spec/features/compliance_check_sets_spec.rb | 110 ++++++++++++++++++++++++++++ spec/features/compliance_ckeck_sets_spec.rb | 110 ---------------------------- 3 files changed, 111 insertions(+), 111 deletions(-) create mode 100644 spec/features/compliance_check_sets_spec.rb delete mode 100644 spec/features/compliance_ckeck_sets_spec.rb diff --git a/config/locales/compliance_check_sets.en.yml b/config/locales/compliance_check_sets.en.yml index 4488a79ba..5aa6f9740 100644 --- a/config/locales/compliance_check_sets.en.yml +++ b/config/locales/compliance_check_sets.en.yml @@ -20,7 +20,7 @@ en: activerecord: attributes: compliance_check_set: - ref: réf + ref: ref creation_date: Created at associated_object: Associated object assigned_to: Assigned to diff --git a/spec/features/compliance_check_sets_spec.rb b/spec/features/compliance_check_sets_spec.rb new file mode 100644 index 000000000..7ba64b6b8 --- /dev/null +++ b/spec/features/compliance_check_sets_spec.rb @@ -0,0 +1,110 @@ +require 'rails_helper' + +RSpec.describe "ComplianceCheckSets", type: :feature do + + include ComplianceCheckSetsHelper + include TransportModeHelper + + login_user + + # We setup a control_set with two blocks and one direct control (meaning that it is not attached to a block) + # Then we add one control to the first block and two controls to the second block + let( :compliance_check_set ){ create :compliance_check_set, name: random_string } + let(:blox){[ + create( :compliance_check_block, + compliance_check_set: compliance_check_set, transport_mode: 'bus', transport_submode: 'demandAndResponseBus'), + create( :compliance_check_block, + compliance_check_set: compliance_check_set, transport_mode: 'rail', transport_submode: 'suburbanRailway') + ]} + let!(:direct_checks){ make_check(nil, times: 2) + make_check(nil, severity: :error) } + let!(:indirect_checks){ blox.flat_map{ |block| make_check(block) } } + let( :all_checks ){ direct_checks + indirect_checks } + + + context 'executed' do + + before do + visit(executed_compliance_check_set_path(compliance_check_set)) + end + + it 'we can see the expected content' do + # Breadcrumbs + expect_breadcrumb_links "Accueil", "Gestion de l'offre", "Liste des jeux de contrôles" + + # Headline + expect( page ).to have_content("Jeu de contrôles exécutés #{compliance_check_set.name}") + + # Information Definition List + expect( page.first('.dl-term') ).to have_content("Nom") + expect( page.first('.dl-def') ).to have_content(compliance_check_set.name) + + # Filters + within( 'form.form-filter' ) do + expect( page ).to have_content("Groupe de contrôle") + expect( page ).to have_content("Objet") + expect( page ).to have_content("Criticité") + end + + # Checks + # Direct Children + within(:xpath, xpath_for_div_of_block) do + direct_checks.each do | direct_check | + expect( page ).to have_content( direct_check.code ) + expect( page ).to have_content( direct_check.name ) + expect( page ).to have_content( direct_check.criticity ) + expect( page ).to have_content( direct_check.comment ) + end + + end + # Indirect Children + compliance_check_set.compliance_check_blocks.each do | block | + within(:xpath, xpath_for_div_of_block(block)) do + block.compliance_checks.each do | check | + expect( page ).to have_content( check.code ) + expect( page ).to have_content( check.name ) + expect( page ).to have_content( check.criticity ) + expect( page ).to have_content( check.comment ) + end + end + end + end + + it 'can filter the results and remove the filter' do + # Filter + check('error') + click_on('Filtrer') + all_checks.each do | check | + if check.criticity == 'error' + expect( page ).to have_content(check.code) + else + expect( page ).not_to have_content(check.code) + end + end + + # Remove filter + click_on('Effacer') + all_checks.each do | check | + expect( page ).to have_content(check.code) + end + + end + end + + def make_check ccblock=nil, times: 1, severity: :warning + times.times.map do + make_one_check ccblock, severity + end + end + + def make_one_check ccblock, severity + create( :compliance_check, + code: random_string, + compliance_check_block: ccblock, + compliance_check_set: compliance_check_set, + criticity: severity) + end + + def xpath_for_div_of_block(block = nil) + %{.//div[@class="col-lg-12"]/h2[contains(text(),"#{transport_mode_text(block)}")]/../../..} + end +end diff --git a/spec/features/compliance_ckeck_sets_spec.rb b/spec/features/compliance_ckeck_sets_spec.rb deleted file mode 100644 index 7ba64b6b8..000000000 --- a/spec/features/compliance_ckeck_sets_spec.rb +++ /dev/null @@ -1,110 +0,0 @@ -require 'rails_helper' - -RSpec.describe "ComplianceCheckSets", type: :feature do - - include ComplianceCheckSetsHelper - include TransportModeHelper - - login_user - - # We setup a control_set with two blocks and one direct control (meaning that it is not attached to a block) - # Then we add one control to the first block and two controls to the second block - let( :compliance_check_set ){ create :compliance_check_set, name: random_string } - let(:blox){[ - create( :compliance_check_block, - compliance_check_set: compliance_check_set, transport_mode: 'bus', transport_submode: 'demandAndResponseBus'), - create( :compliance_check_block, - compliance_check_set: compliance_check_set, transport_mode: 'rail', transport_submode: 'suburbanRailway') - ]} - let!(:direct_checks){ make_check(nil, times: 2) + make_check(nil, severity: :error) } - let!(:indirect_checks){ blox.flat_map{ |block| make_check(block) } } - let( :all_checks ){ direct_checks + indirect_checks } - - - context 'executed' do - - before do - visit(executed_compliance_check_set_path(compliance_check_set)) - end - - it 'we can see the expected content' do - # Breadcrumbs - expect_breadcrumb_links "Accueil", "Gestion de l'offre", "Liste des jeux de contrôles" - - # Headline - expect( page ).to have_content("Jeu de contrôles exécutés #{compliance_check_set.name}") - - # Information Definition List - expect( page.first('.dl-term') ).to have_content("Nom") - expect( page.first('.dl-def') ).to have_content(compliance_check_set.name) - - # Filters - within( 'form.form-filter' ) do - expect( page ).to have_content("Groupe de contrôle") - expect( page ).to have_content("Objet") - expect( page ).to have_content("Criticité") - end - - # Checks - # Direct Children - within(:xpath, xpath_for_div_of_block) do - direct_checks.each do | direct_check | - expect( page ).to have_content( direct_check.code ) - expect( page ).to have_content( direct_check.name ) - expect( page ).to have_content( direct_check.criticity ) - expect( page ).to have_content( direct_check.comment ) - end - - end - # Indirect Children - compliance_check_set.compliance_check_blocks.each do | block | - within(:xpath, xpath_for_div_of_block(block)) do - block.compliance_checks.each do | check | - expect( page ).to have_content( check.code ) - expect( page ).to have_content( check.name ) - expect( page ).to have_content( check.criticity ) - expect( page ).to have_content( check.comment ) - end - end - end - end - - it 'can filter the results and remove the filter' do - # Filter - check('error') - click_on('Filtrer') - all_checks.each do | check | - if check.criticity == 'error' - expect( page ).to have_content(check.code) - else - expect( page ).not_to have_content(check.code) - end - end - - # Remove filter - click_on('Effacer') - all_checks.each do | check | - expect( page ).to have_content(check.code) - end - - end - end - - def make_check ccblock=nil, times: 1, severity: :warning - times.times.map do - make_one_check ccblock, severity - end - end - - def make_one_check ccblock, severity - create( :compliance_check, - code: random_string, - compliance_check_block: ccblock, - compliance_check_set: compliance_check_set, - criticity: severity) - end - - def xpath_for_div_of_block(block = nil) - %{.//div[@class="col-lg-12"]/h2[contains(text(),"#{transport_mode_text(block)}")]/../../..} - end -end -- cgit v1.2.3