Skip to content

Commit 7879682

Browse files
authored
Merge pull request #1226 from Crown-Commercial-Service/feature/nrmi-168-removearchived-agreements-from-add-missing-task
Feature/nrmi 168 remove archived agreements from add missing task
2 parents a9e35d5 + 2f63590 commit 7879682

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

app/views/admin/suppliers/show.html.haml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
%ul.govuk-page-actions--actions
1111
%li.govuk-page-actions--action
1212
= link_to 'Edit supplier', edit_admin_supplier_path(@supplier)
13-
%li.govuk-page-actions--action
14-
= link_to "Add a missing task", new_admin_supplier_task_path(@supplier)
13+
- if @supplier.frameworks.where(aasm_state: %w[new published]).exists?
14+
%li.govuk-page-actions--action
15+
= link_to "Add a missing task", new_admin_supplier_task_path(@supplier)
1516
%li.govuk-page-actions--action
1617
= link_to "Add a new user", new_admin_user_path(supplier_sf_id: @supplier.salesforce_id)
1718

app/views/admin/tasks/new.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
= @supplier.name
1111
= render partial: 'shared/error_summary', locals: { entity: @task } if @task.errors.present?
1212

13-
= form.input :framework_id, collection: @supplier.frameworks.collect {|x| [x.full_name, x.id]}.sort, include_blank: false
13+
= form.input :framework_id, collection: @supplier.frameworks.where(aasm_state: %w[new published]).map {|x| [x.full_name, x.id]}.sort, include_blank: false
1414
= form.input :period_year, collection: (Date.today.year-10..Date.today.year).to_a.reverse, selected: Date.today.last_month.year
1515
= form.input :period_month, collection: (1..12).map {|m| [Date::MONTHNAMES[m], m]}, selected: Date.today.last_month.month
1616
= form.button :submit, value: 'Create task'

spec/features/admin_can_add_a_task_to_supplier_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,44 @@
5151
end
5252
end
5353
end
54+
55+
context 'when the supplier has frameworks in different states' do
56+
let!(:supplier) { FactoryBot.create(:supplier, name: 'Second Supplier') }
57+
let!(:published_framework) { FactoryBot.create(:framework, name: 'Published Framework', aasm_state: 'published') }
58+
let!(:new_framework) { FactoryBot.create(:framework, name: 'New Framework', aasm_state: 'new') }
59+
let!(:archived_framework) { FactoryBot.create(:framework, name: 'Archived Framework', aasm_state: 'archived') }
60+
61+
before do
62+
stub_govuk_bank_holidays_request
63+
64+
FactoryBot.create(:agreement, framework: published_framework, supplier: supplier)
65+
FactoryBot.create(:agreement, framework: new_framework, supplier: supplier)
66+
FactoryBot.create(:agreement, framework: archived_framework, supplier: supplier)
67+
68+
sign_in_as_admin
69+
end
70+
71+
scenario 'frameworks are filtered to only show active ones' do
72+
visit new_admin_supplier_task_path(supplier)
73+
74+
expect(page).to have_select('Framework', options: [published_framework.full_name, new_framework.full_name])
75+
expect(page).not_to have_select('Framework', options: [archived_framework.full_name])
76+
end
77+
end
78+
79+
context 'when the supplier has only archived frameworks' do
80+
before do
81+
stub_govuk_bank_holidays_request
82+
supplier = FactoryBot.create(:supplier, name: 'Archived Only Supplier')
83+
archived_framework = FactoryBot.create(:framework, name: 'Archived Framework', aasm_state: 'archived')
84+
FactoryBot.create(:agreement, framework: archived_framework, supplier: supplier)
85+
sign_in_as_admin
86+
end
87+
88+
scenario 'does not show add missing task link' do
89+
visit admin_suppliers_path
90+
click_on 'Archived Only Supplier'
91+
expect(page).not_to have_link 'Add a missing task'
92+
end
93+
end
5494
end

0 commit comments

Comments
 (0)