aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/calendars_spec.rb
blob: 8bca4965d71acb5f5c179a2a4062a78494974825 (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
# -*- coding: utf-8 -*-
require 'spec_helper'

describe 'Calendars', type: :feature do
  login_user

  let!(:calendars) { Array.new(2) { create :calendar, organisation_id: 1 } }
  let!(:shared_calendar_other_org) { create :calendar, shared: true }
  let!(:unshared_calendar_other_org) { create :calendar }

  describe 'index' do
    before(:each) { visit calendars_path }

    it 'displays calendars of the current organisation and shared calendars' do
      expect(page).to have_content(calendars.first.short_name)
      expect(page).to have_content(shared_calendar_other_org.short_name)
      expect(page).not_to have_content(unshared_calendar_other_org.short_name)
    end

    context 'filtering' do
      it 'supports filtering by short name' do
        fill_in 'q[short_name_cont]', with: calendars.first.short_name
        click_button 'search_btn'
        expect(page).to have_content(calendars.first.short_name)
        expect(page).not_to have_content(calendars.last.short_name)
      end

      it 'supports filtering by shared' do
        shared_calendar = create :calendar, organisation_id: 1, shared: true
        visit calendars_path
        # select I18n.t('true'), from: 'q[shared]'
        find(:css, '#q_shared').set(true)
        click_button 'filter_btn'
        expect(page).to have_content(shared_calendar.short_name)
        expect(page).not_to have_content(calendars.first.short_name)
      end

      # wip
      # it 'supports filtering by date' do
      #   july_calendar = create :calendar, dates: [Date.new(2017, 7, 7)], date_ranges: [Date.new(2017, 7, 15)..Date.new(2017, 7, 30)], organisation_id: 1
      #   visit calendars_path
      #   select '7', from: 'q_contains_date_3i'
      #   select 'juillet', from: 'q_contains_date_2i'
      #   select '2017', from: 'q_contains_date_1i'
      #   click_button 'filter_btn'
      #   expect(page).to have_content(july_calendar.short_name)
      #   expect(page).not_to have_content(calendars.first.short_name)
      #   select '18', from: 'q_contains_date_3i'
      #   select 'juillet', from: 'q_contains_date_2i'
      #   select '2017', from: 'q_contains_date_1i'
      #   click_button 'filter_btn'
      #   expect(page).to have_content(july_calendar.short_name)
      #   expect(page).not_to have_content(calendars.first.short_name)
      # end
    end
  end

  describe 'show' do
    it 'displays calendar' do
      visit calendar_path(calendars.first)
      expect(page).to have_content(calendars.first.name)
    end
  end
end