Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/views/admin/suppliers/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
%ul.govuk-page-actions--actions
%li.govuk-page-actions--action
= link_to 'Edit supplier', edit_admin_supplier_path(@supplier)
%li.govuk-page-actions--action
= link_to "Add a missing task", new_admin_supplier_task_path(@supplier)
- if @supplier.frameworks.where(aasm_state: %w[new published]).exists?
%li.govuk-page-actions--action
= link_to "Add a missing task", new_admin_supplier_task_path(@supplier)
%li.govuk-page-actions--action
= link_to "Add a new user", new_admin_user_path(supplier_sf_id: @supplier.salesforce_id)

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/tasks/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
= @supplier.name
= render partial: 'shared/error_summary', locals: { entity: @task } if @task.errors.present?

= form.input :framework_id, collection: @supplier.frameworks.collect {|x| [x.full_name, x.id]}.sort, include_blank: false
= form.input :framework_id, collection: @supplier.frameworks.where(aasm_state: %w[new published]).map {|x| [x.full_name, x.id]}.sort, include_blank: false
= form.input :period_year, collection: (Date.today.year-10..Date.today.year).to_a.reverse, selected: Date.today.last_month.year
= form.input :period_month, collection: (1..12).map {|m| [Date::MONTHNAMES[m], m]}, selected: Date.today.last_month.month
= form.button :submit, value: 'Create task'
40 changes: 40 additions & 0 deletions spec/features/admin_can_add_a_task_to_supplier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,44 @@
end
end
end

context 'when the supplier has frameworks in different states' do
let!(:supplier) { FactoryBot.create(:supplier, name: 'Second Supplier') }
let!(:published_framework) { FactoryBot.create(:framework, name: 'Published Framework', aasm_state: 'published') }
let!(:new_framework) { FactoryBot.create(:framework, name: 'New Framework', aasm_state: 'new') }
let!(:archived_framework) { FactoryBot.create(:framework, name: 'Archived Framework', aasm_state: 'archived') }

before do
stub_govuk_bank_holidays_request

FactoryBot.create(:agreement, framework: published_framework, supplier: supplier)
FactoryBot.create(:agreement, framework: new_framework, supplier: supplier)
FactoryBot.create(:agreement, framework: archived_framework, supplier: supplier)

sign_in_as_admin
end

scenario 'frameworks are filtered to only show active ones' do
visit new_admin_supplier_task_path(supplier)

expect(page).to have_select('Framework', options: [published_framework.full_name, new_framework.full_name])
expect(page).not_to have_select('Framework', options: [archived_framework.full_name])
end
end

context 'when the supplier has only archived frameworks' do
before do
stub_govuk_bank_holidays_request
supplier = FactoryBot.create(:supplier, name: 'Archived Only Supplier')
archived_framework = FactoryBot.create(:framework, name: 'Archived Framework', aasm_state: 'archived')
FactoryBot.create(:agreement, framework: archived_framework, supplier: supplier)
sign_in_as_admin
end

scenario 'does not show add missing task link' do
visit admin_suppliers_path
click_on 'Archived Only Supplier'
expect(page).not_to have_link 'Add a missing task'
end
end
end