aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/purchase_windows_spec.rb
blob: f797594b7a3c2639f8c55b9b30f6ee8bd15eb64d (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
describe "PurchaseWindows", type: :feature do
  login_user

  before do
    @user.organisation.update features: %w{purchase_windows}
  end

  describe "#index" do
    with_permissions('purchase_windows.create') do
      it "allows users to create new purchase windows" do
        name = 'Test purchase window create'

        visit(referential_purchase_windows_path(first_referential.id))

        click_link(I18n.t('purchase_windows.actions.new'))

        fill_in('purchase_window[name]', with: name)
        # select('#DD2DAA', from: 'purchase_window[color]')

        click_link(I18n.t('simple_form.labels.purchase_window.add_a_date_range'))
        click_button(I18n.t('actions.submit'))

        expect(page).to have_content(name)
      end
    end

    with_permissions('purchase_windows.update') do
      it "allows users to update purchase windows" do
        actual_name = 'Existing purchase window'
        expected_name = 'Updated purchase window'
        create(
          :purchase_window,
          referential: first_referential,
          name: actual_name
        )

        visit(referential_purchase_windows_path(first_referential.id))

        click_link(actual_name)

        click_link(I18n.t('purchase_windows.actions.edit'))
        fill_in('purchase_window[name]', with: expected_name)

        click_button(I18n.t('actions.submit'))

        expect(page).to have_content(expected_name)
      end
    end

    with_permissions('purchase_windows.destroy') do
      it "allows users to destroy purchase windows" do
        name = 'Existing purchase window'
        create(
          :purchase_window,
          referential: first_referential,
          name: name
        )

        visit(referential_purchase_windows_path(first_referential.id))

        click_link(name)

        click_link(I18n.t('purchase_windows.actions.destroy'))

        expect(page).to_not have_content(name)
      end
    end
  end
end