aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/compliance_check_sets_spec.rb
blob: 5cace04d4c9de9c8ec8377aa8184b53be5b97228 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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 rapports de contrôles"

      # Headline
      expect( page ).to have_content(I18n.t("compliance_check_sets.executed.title", name: 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