aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/routes_spec.rb
blob: dbab2c0d275808db0726b09258317eda4c131ef4 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
describe "Routes", :type => :feature do
  login_user

  let(:line) { create :line }
  let!(:route) { create(:route, :line => line) }
  let!(:route2) { create(:route, :line => line) }
  #let!(:stop_areas) { Array.new(4) { create(:stop_area) } }
  let!(:stop_points) { Array.new(4) { create(:stop_point, :route => route) } }
  let(:stop_area_referential) {stop_points.first.stop_area.stop_area_referential}
  let!(:journey_pattern) { create(:journey_pattern, route: route) }

  before { @user.update(organisation: referential.organisation) }

  with_permissions "boiv:read" do
    it "line page displays line's routes" do
      visit referential_line_path(referential, line)
      expect(page).to have_content(route.name)
      expect(page).to have_content(route2.name)
    end

    describe "from line's page to route's page" do
      it "display route properties" do
        visit referential_line_path(referential, line)
        click_link "#{route.name}"
        expect(page).to have_content(route.name)
        expect(page).to have_content(route.number)
      end
    end

    describe "from line's page, create a new route" do
      it "return to line's page that display new route" do
        visit referential_line_path(referential, line)
        click_link "Ajouter un itinéraire"
        fill_in "route_name", :with => "A to B"
        fill_in "route_published_name", :with => "Published A to B"
        # select 'Aller', :from => "route_direction"
        check('route[wayback]')
        click_button("Valider")
        expect(page).to have_content("A to B")
        expect(page).to have_content("Published A to B")

      end
    end

    describe "Modifies boarding/alighting properties on route stops" do
      xit "Puts (http) an update request" do
        #visit edit_boarding_alighting_referential_line_route_path(referential, line, route)
        visit referential_line_route_path(referential, line, route)

        click_link I18n.t('routes.actions.edit_boarding_alighting')
        #select('', :from => '')
        # Changes the boarding of the first stop
        # Changes the alighting of the last stop
        # save
        #click_button(I18n.t('helpers.submit.update', model: I18n.t('activerecord.models.route.one')))
        click_button(I18n.t('helpers.submit.update', model: I18n.t('activerecord.models.route.one')))
      end
    end

    describe 'show' do
      before(:each) { visit referential_line_route_path(referential, line, route) }

      context 'user has permission to edit journey patterns' do
        skip "not sure the spec is correct or the code" do
          it 'shows edit links for journey patterns' do
            expect(page).to have_link(I18n.t('actions.edit'), href: edit_referential_line_route_journey_pattern_path(referential, line, route, journey_pattern))
          end
        end
      end

      context 'user does not have permission to edit journey patterns' do
        it 'does not show edit links for journey patterns' do
          @user.update_attribute(:permissions, [])
          visit referential_line_route_path(referential, line, route)
          expect(page).not_to have_link(I18n.t('actions.edit'), href: edit_referential_line_route_journey_pattern_path(referential, line, route, journey_pattern))
        end
      end

      context 'user has permission to destroy journey patterns' do
        it 'shows destroy links for journey patterns' do
          expect(page).to have_content(I18n.t('actions.destroy'))
        end
      end

      context 'user does not have permission to destroy journey patterns' do
        it 'does not show destroy links for journey patterns' do
          @user.update_attribute(:permissions, [])
          visit referential_line_route_path(referential, line, route)
          expect(page).not_to have_link(I18n.t('actions.destroy'), href: referential_line_route_journey_pattern_path(referential, line, route, journey_pattern))
        end
      end

      def click_on_stop_point_dropdown_btn(num)
        find(:xpath, "(//div[contains(@class, 'btn') and contains(@class, 'dropdown-toggle')])[#{num}]").click
      end

      context 'user does not have permission to edit stop areas' do
        it 'does not show edit links for stop areas' do
          @user.update_attribute(:permissions, [])
          
          expect(page).not_to have_content(I18n.t('stop_points.actions.edit'), visible: false)
          stop_points.each_with_index do |sp, i|
            click_on_stop_point_dropdown_btn(i + 1)
            expect(page).not_to have_link(I18n.t('stop_points.actions.edit'), href: edit_stop_area_referential_stop_area_path(stop_area_referential, sp))
          end
        end
      end

      context 'user has permission to edit stop areas' do
        xit 'shows edit links for stop areas' do
          @user.update_attribute(:permissions, ["stop_areas.update"])
          visit referential_line_route_path(referential, line, route)
          
          stop_points.each_with_index do |sp, i|
            click_on_stop_point_dropdown_btn(i + 1)
            expect(page).to have_link(I18n.t('stop_points.actions.edit'), href: edit_stop_area_referential_stop_area_path(stop_area_referential, sp))
          end
        end
      end

      context 'user does not have permission to destroy stop areas' do
        it 'does not show destroy links for stop areas' do
          @user.update_attribute(:permissions, [])
          stop_points.each_with_index do |sp, i|
            click_on_stop_point_dropdown_btn(i + 1)
            expect(page).not_to have_link(I18n.t('stop_points.actions.destroy'), href: stop_area_referential_stop_area_path(sp.referential, sp))
          end
        end
      end

      context 'user has permission to destroy journey patterns' do
        xit 'shows destroy links for journey patterns' do
          @user.update_attribute(:permissions, ["stop_areas.destroy"])
          stop_points.each_with_index do |sp, i|
            stop_point_action_links_btn(i + 1).click
            expect(page).to have_link(I18n.t('stop_points.actions.destroy'), href: stop_area_referential_stop_area_path(sp.referential, sp))
          end
        end
      end
    end

    describe 'referential line show' do
      before(:each) { visit referential_line_path(referential, line) }

      context 'user has permission to edit routes' do
        it 'shows edit buttons for routes' do
          expect(page).to have_content(I18n.t('actions.edit'))
        end
      end

      context 'user does not have permission to edit routes' do
        it 'does not show edit buttons for routes' do
          @user.update_attribute(:permissions, [])
          visit referential_line_path(referential, line)
          expect(page).not_to have_link(I18n.t('actions.edit'), href: edit_referential_line_route_path(referential, line, route))
        end
      end

      context 'user has permission to create routes' do
        it 'shows link to a create route page' do
          expect(page).to have_content(I18n.t('routes.actions.new'))
        end
      end

      context 'user belongs to another organisation' do
        xit 'does not show link to a create route page' do
          expect(page).not_to have_content(I18n.t('routes.actions.new'))
        end
      end

      context 'user does not have permission to create routes' do
        it 'does not show link to a create route page' do
          @user.update_attribute(:permissions, [])
          visit referential_line_path(referential, line)
          expect(page).not_to have_content(I18n.t('routes.actions.new'))
        end
      end

      context 'user does not have permission to destroy routes' do
        it 'does not show destroy buttons for routes' do
          @user.update_attribute(:permissions, [])
          visit referential_line_path(referential, line)
          expect(page).not_to have_link(I18n.t('actions.destroy'), href: referential_line_route_path(referential, line, route))
        end
      end
    end
  end
end