|
7 | 7 | 3.days.from_now |
8 | 8 | end |
9 | 9 | let(:organization) { FactoryBot.create(:organization) } |
| 10 | + let(:another_organization) { FactoryBot.create(:organization, :another) } |
10 | 11 | let(:admin) { FactoryBot.create(:user, :admin, organization:) } |
11 | 12 | let(:user) { FactoryBot.create(:user, organization:) } |
12 | 13 |
|
13 | 14 | context 'as Admin' do |
| 15 | + let!(:user_forms) do |
| 16 | + FactoryBot.create_list(:form, 3, organization:) do |form, i| |
| 17 | + FactoryBot.create(:user_role, :form_manager, user: admin, form:) |
| 18 | + if i == 0 |
| 19 | + form.update(aasm_state: :archived) |
| 20 | + end |
| 21 | + end |
| 22 | + end |
| 23 | + let!(:form_in_my_org) { FactoryBot.create(:form, organization:) } |
| 24 | + let!(:form_in_other_org) { FactoryBot.create(:form, organization: another_organization) } |
| 25 | + |
14 | 26 | before do |
15 | 27 | login_as(admin) |
16 | 28 | end |
17 | 29 |
|
18 | 30 | describe '/admin/forms' do |
19 | | - let!(:form) { FactoryBot.create(:form, organization:) } |
20 | | - let!(:form2) { FactoryBot.create(:form, organization:) } |
21 | | - let!(:form3) { FactoryBot.create(:form, organization:) } |
22 | | - let!(:form4) { FactoryBot.create(:form, organization:, aasm_state: :submitted) } |
23 | | - let!(:form5) { FactoryBot.create(:form, organization:, aasm_state: :archived) } |
24 | | - |
25 | 31 | before do |
26 | 32 | visit admin_forms_path |
27 | 33 | end |
28 | 34 |
|
29 | | - it 'displays 3 published forms' do |
| 35 | + it 'displays 2 published form owned by the admin user' do |
| 36 | + expect(find_all('.usa-table tbody tr').size).to eq(2) |
30 | 37 | expect(page).to have_content('PUBLISHED') |
31 | 38 | expect(page).to_not have_content('ARCHIVED') |
32 | | - expect(find_all('.usa-table tbody tr').size).to eq(3) |
33 | 39 | end |
34 | 40 |
|
35 | 41 | context 'use the visible buttons to filter for archived forms' do |
36 | | - it 'displays 1 archived form' do |
| 42 | + it 'displays 1 archived form owned by the admin user' do |
37 | 43 | within('.form-filter-buttons') do |
38 | 44 | click_on('Archived') |
39 | 45 | end |
| 46 | + expect(find_all('.usa-table tbody tr').size).to eq(1) |
40 | 47 | expect(page).to have_content('ARCHIVED') |
41 | 48 | expect(page).to_not have_content('PUBLISHED') |
42 | | - expect(find_all('.usa-table tbody tr').size).to eq(1) |
43 | 49 | end |
44 | 50 | end |
45 | 51 | end |
| 52 | + |
| 53 | + describe '/admin/forms/all' do |
| 54 | + before do |
| 55 | + visit all_admin_forms_path |
| 56 | + end |
| 57 | + |
| 58 | + it 'displays all 5 forms' do |
| 59 | + expect(find_all('.usa-table tbody tr').size).to eq(5) |
| 60 | + end |
| 61 | + end |
46 | 62 | end |
47 | 63 |
|
48 | 64 | context 'as Admin' do |
|
1432 | 1448 | end |
1433 | 1449 | end |
1434 | 1450 |
|
| 1451 | + context 'as non-admin user' do |
| 1452 | + before do |
| 1453 | + login_as(user) |
| 1454 | + end |
| 1455 | + |
| 1456 | + it 'cannot access All Forms page' do |
| 1457 | + visit all_admin_forms_path |
| 1458 | + expect(page.current_path).to eq(admin_root_path) |
| 1459 | + expect(page).to have_content('Authorization is Required') |
| 1460 | + end |
| 1461 | + end |
| 1462 | + |
1435 | 1463 | context 'Form owner with Form Manager permissions Delete Action' do |
1436 | 1464 | let!(:form) { FactoryBot.create(:form, :single_question, organization:) } |
1437 | 1465 | let!(:user_role) { FactoryBot.create(:user_role, :form_manager, user: admin, form:) } |
|
0 commit comments