diff options
| author | teddywing | 2017-11-17 16:15:25 +0100 |
|---|---|---|
| committer | GitHub | 2017-11-17 16:15:25 +0100 |
| commit | 0d80f302bbf90334671b954b6788d581d5c852cb (patch) | |
| tree | 078d579ccb120d0f7d495b248175fc6cbc6b42f9 /spec | |
| parent | 3e4b615c6d40598f06a20957e3b48c0c516a8ce5 (diff) | |
| parent | b5536b6f8d7e5fbfe52d24e0b71bcc4984b87262 (diff) | |
| download | chouette-core-0d80f302bbf90334671b954b6788d581d5c852cb.tar.bz2 | |
Merge pull request #113 from af83/4823-compliance_check_show
4823 compliance check show
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/compliance_check_sets_controller_spec.rb | 4 | ||||
| -rw-r--r-- | spec/factories/compliance_control_blocks.rb | 3 | ||||
| -rw-r--r-- | spec/features/compliance_check_sets_spec.rb | 110 | ||||
| -rw-r--r-- | spec/features/compliance_control_sets_spec.rb | 16 | ||||
| -rw-r--r-- | spec/models/compliance_check_block_spec.rb | 17 | ||||
| -rw-r--r-- | spec/models/compliance_control_block_spec.rb | 17 | ||||
| -rw-r--r-- | spec/models/line_referential_spec.rb | 9 | ||||
| -rw-r--r-- | spec/support/breadcrumb_features.rb | 15 |
8 files changed, 168 insertions, 23 deletions
diff --git a/spec/controllers/compliance_check_sets_controller_spec.rb b/spec/controllers/compliance_check_sets_controller_spec.rb index 804b0a658..3ddb1dad1 100644 --- a/spec/controllers/compliance_check_sets_controller_spec.rb +++ b/spec/controllers/compliance_check_sets_controller_spec.rb @@ -5,9 +5,9 @@ RSpec.describe ComplianceCheckSetsController, type: :controller do let(:compliance_check_set) { create :compliance_check_set } - describe "GET show" do + describe "GET executed" do it 'should be successful' do - get :show, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id + get :executed, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id expect(response).to be_success end end diff --git a/spec/factories/compliance_control_blocks.rb b/spec/factories/compliance_control_blocks.rb index 4785d8419..94773d4b3 100644 --- a/spec/factories/compliance_control_blocks.rb +++ b/spec/factories/compliance_control_blocks.rb @@ -1,7 +1,8 @@ FactoryGirl.define do factory :compliance_control_block do sequence(:name) { |n| "Compliance control block #{n}" } - transport_mode "air" + transport_mode StifTransportModeEnumerations.transport_modes.first + transport_submode StifTransportSubmodeEnumerations.transport_submodes.first association :compliance_control_set end end 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_control_sets_spec.rb b/spec/features/compliance_control_sets_spec.rb index 500d4ce6f..bcb989cdc 100644 --- a/spec/features/compliance_control_sets_spec.rb +++ b/spec/features/compliance_control_sets_spec.rb @@ -25,7 +25,18 @@ RSpec.describe "ComplianceControlSets", type: :feature do visit compliance_control_set_path( control_set ) end - it 'we can see the controls inside their blocks' do + it 'we can see the expected content' do + # Breadcrumb + expect_breadcrumb_links "Accueil", "Liste des jeux de contrôles" + + # Headline + expect( page ).to have_content("Consulter le jeu de contrôles #{control_set.name}") + + # Information Definition List + expect( page.first('.dl-term') ).to have_content("Nom") + expect( page.first('.dl-def') ).to have_content(control_set.name) + + # Children controls.each do | control | expect( page ).to have_content(control.code) end @@ -76,7 +87,8 @@ RSpec.describe "ComplianceControlSets", type: :feature do create( :generic_attribute_control_min_max, code: random_string, compliance_control_block: ccblock, - compliance_control_set: control_set) + compliance_control_set: control_set, + criticity: severity) end end diff --git a/spec/models/compliance_check_block_spec.rb b/spec/models/compliance_check_block_spec.rb index a3d98d459..0629a645d 100644 --- a/spec/models/compliance_check_block_spec.rb +++ b/spec/models/compliance_check_block_spec.rb @@ -1,10 +1,17 @@ -require 'rails_helper' - RSpec.describe ComplianceCheckBlock, type: :model do - it 'should have a valid factory' do - expect(FactoryGirl.build(:compliance_check_block)).to be_valid - end it { should belong_to :compliance_check_set } it { should have_many :compliance_checks } + + it { should allow_values(*%w{bus metro rail tram funicular}).for(:transport_mode) } + it { should_not allow_values(*%w{bs mtro ril tramm Funicular}).for(:transport_mode) } + + + it { should allow_values( *%w{ demandAndResponseBus nightBus airportLinkBus highFrequencyBus expressBus + railShuttle suburbanRailway regionalRail interregionalRail }) + .for(:transport_submode) } + + it { should_not allow_values( *%w{ demandResponseBus nightus irportLinkBus highrequencyBus expressBUs + Shuttle suburban regioalRail interregion4lRail }) + .for(:transport_submode) } end diff --git a/spec/models/compliance_control_block_spec.rb b/spec/models/compliance_control_block_spec.rb index c7440a5eb..4abe0ed9c 100644 --- a/spec/models/compliance_control_block_spec.rb +++ b/spec/models/compliance_control_block_spec.rb @@ -1,13 +1,20 @@ require 'rails_helper' RSpec.describe ComplianceControlBlock, type: :model do - subject { create(:compliance_control_block) } - - it 'should have a valid factory' do - expect(FactoryGirl.build(:compliance_control_block)).to be_valid - end it { should belong_to :compliance_control_set } it { should have_many(:compliance_controls).dependent(:destroy) } it { should validate_presence_of(:transport_mode) } + + it { should allow_values(*%w{bus metro rail tram funicular}).for(:transport_mode) } + it { should_not allow_values(*%w{bs mtro ril tramm Funicular}).for(:transport_mode) } + + + it { should allow_values( *%w{ demandAndResponseBus nightBus airportLinkBus highFrequencyBus expressBus + railShuttle suburbanRailway regionalRail interregionalRail }) + .for(:transport_submode) } + + it { should_not allow_values( *%w{ demandResponseBus nightus irportLinkBus highrequencyBus expressBUs + Shuttle suburban regioalRail interregion4lRail }) + .for(:transport_submode) } end diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb index 8c6cb018b..8f8714f8f 100644 --- a/spec/models/line_referential_spec.rb +++ b/spec/models/line_referential_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -RSpec.describe LineReferential, :type => :model do +RSpec.describe LineReferential, type: :model do it 'should have a valid factory' do expect(FactoryGirl.build(:line_referential)).to be_valid end @@ -10,9 +8,4 @@ RSpec.describe LineReferential, :type => :model do it { is_expected.to have_many(:workbenches) } it { should validate_presence_of(:sync_interval) } - describe "#transport_modes" do - it 'returns a list of all transport modes' do - expect(FactoryGirl.create(:line_referential).class.transport_modes).to match_array(StifTransportModeEnumerations.transport_modes ) - end - end end diff --git a/spec/support/breadcrumb_features.rb b/spec/support/breadcrumb_features.rb new file mode 100644 index 000000000..36bfce19c --- /dev/null +++ b/spec/support/breadcrumb_features.rb @@ -0,0 +1,15 @@ +module BreadcrumbFeatures + def expect_breadcrumb_links *link_names + within('.breadcrumbs') do + all('a').zip( link_names ).each do | link_element, link_content | + within(link_element) do | | + expect(page).to have_content(link_content) + end + end + end + end +end + +RSpec.configure do | conf | + conf.include BreadcrumbFeatures, type: :feature +end |
