aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/compliance_control_sets_spec.rb
blob: 306f363a5737e852ff82515f1ce1e1e0b996d744 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
RSpec.describe "ComplianceControlSets", type: :feature do
  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( :control_set ){ create :compliance_control_set, organisation: organisation }
  let( :controls ){ control_set.compliance_controls }

  let(:other_orga) { create :organisation }
  let(:other_control_cset) { create :compliance_control_set, organisation: other_orga }

  let(:blox){
    2.times.map{ |n| create :compliance_control_block, compliance_control_set: control_set, transport_mode: StifTransportModeEnumerations.transport_modes[n], transport_submode: StifTransportSubmodeEnumerations.transport_submodes[n] }
  }

  before do
    blox.first.update transport_mode: 'bus', transport_submode: 'nightBus'
    blox.second.update transport_mode: 'train', transport_submode: 'train'

    make_control
    make_control blox.first, severity: :error
    make_control blox.second, times: 2
  end

  describe 'show' do
    let( :control_button_href ){ select_type_compliance_control_set_compliance_controls_path(control_set) }
    let( :new_group_button_href ) { new_compliance_control_set_compliance_control_block_path(control_set) }

    before do
      visit compliance_control_set_path( control_set )
    end

    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

      # Floating Buttons
      within '.select_toolbox#floating-links' do
        expect( page ).to have_link("Contrôle", href: control_button_href)
        expect( page ).to have_link("Groupe de contrôles", href: new_group_button_href)
      end
      
    end

    it 'we can apply a severity filter' do
      controls.take(2).each do | control |
        control.update criticity: 'error'
      end
      check('error')
      click_on('Filtrer')
      controls.each do | control |
        if control.criticity == 'error'
          expect( page ).to have_content(control.code)
        else
          expect( page ).not_to have_content(control.code)
        end
      end
    end

    it 'we can apply a subclass filter' do
      controls.first.update(origin_code: 'x-Route-y')
      controls.second.update(origin_code: 'x-Line-y')

      within('#subclass-filter') do
        check('Itinéraire')
        check('Ligne')
      end
      click_on('Filtrer')
      controls.each do | control |
        if control.origin_code[/-Generic-/]
          expect( page ).not_to have_content(control.code)
        else
          expect( page ).to have_content(control.code)
        end
      end
    end

    context "wthout filter on compliance control block applied" do
      it "we can see empty blocks" do
        blox.first.compliance_controls.destroy_all
        expect(page).to have_content (transport_mode_text(blox.first) )
      end
    end

  end

  describe 'index' do

    before do
      visit compliance_control_sets_path
    end
    
    it "only showw compliance control sets from user organisation" do
      expect(page).not_to have_content (other_orga.name)
      expect(page).to have_content (organisation.name)
    end
  end

  def make_control ccblock=nil, times: 1, severity: :warning
    times.times do
      make_one_control ccblock, severity
    end
  end

  def make_one_control ccblock, severity
      create( :generic_attribute_control_min_max,
        code: random_string,
        compliance_control_block: ccblock,
        compliance_control_set: control_set,
        criticity: severity)
  end

end