-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
175 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
vendor/engines/sanger_sequencing/spec/controllers/sanger_sequencing/sanger_products_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
require "controller_spec_helper" | ||
|
||
RSpec.describe SangerSequencing::SangerProductsController do | ||
let(:facility) { create(:setup_facility, sanger_sequencing_enabled: true) } | ||
let(:service) { create(:setup_service, facility:, sanger_sequencing_enabled: true) } | ||
let(:user) { create(:user, :facility_administrator, facility:) } | ||
|
||
before do | ||
sign_in user | ||
|
||
@params = { facility_id: facility.url_name, service_id: service.url_name } | ||
end | ||
|
||
shared_examples "creates a sanger product if needed" do | ||
it "creates a sanger product if needed" do | ||
expect { do_request }.to( | ||
change do | ||
service.reload.sanger_product | ||
end.from(nil).to(SangerSequencing::SangerProduct) | ||
) | ||
end | ||
end | ||
|
||
describe "show" do | ||
before do | ||
@method = :get | ||
@action = :show | ||
end | ||
|
||
include_examples "creates a sanger product if needed" | ||
end | ||
|
||
describe "edit" do | ||
before do | ||
@method = :get | ||
@action = :edit | ||
end | ||
|
||
include_examples "creates a sanger product if needed" | ||
end | ||
|
||
describe "update" do | ||
before do | ||
@method = :put | ||
@action = :update | ||
@params[:sanger_sequencing_sanger_product] = { group: "default" } | ||
end | ||
|
||
include_examples "creates a sanger product if needed" | ||
|
||
it "updates the sanger product" do | ||
sanger_product_json = { | ||
"needs_primer" => true, "group" => "fragment" | ||
} | ||
@params[:sanger_sequencing_sanger_product] = sanger_product_json | ||
|
||
service.create_sanger_product | ||
|
||
expect { do_request }.to( | ||
change do | ||
service.reload.sanger_product.as_json(only: %i[needs_primer group]) | ||
end.from( | ||
{ "needs_primer" => false, "group" => "default" } | ||
).to( | ||
sanger_product_json | ||
) | ||
) | ||
end | ||
end | ||
end |
52 changes: 0 additions & 52 deletions
52
vendor/engines/sanger_sequencing/spec/system/sanger_product_spec.rb
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
vendor/engines/sanger_sequencing/spec/system/sanger_products_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe "Sanger Products" do | ||
let(:facility) { create(:setup_facility, sanger_sequencing_enabled: true) } | ||
let(:service) { create(:setup_service, facility:, sanger_sequencing_enabled: true) } | ||
let(:admin) { create(:user, :facility_administrator, facility:) } | ||
let(:user) { create(:user) } | ||
|
||
describe "admin tab" do | ||
context "when not logged in" do | ||
it "redirects to login" do | ||
visit facility_service_sanger_sequencing_sanger_product_path(facility, service) | ||
|
||
expect(page).to have_content("Login") | ||
expect(page).to_not have_content("Sanger") | ||
expect(page).to_not have_content(service.name) | ||
end | ||
end | ||
|
||
context "when logged in as normal user" do | ||
before { login_as user } | ||
|
||
it "renders permission denied" do | ||
visit facility_service_sanger_sequencing_sanger_product_path(facility, service) | ||
|
||
expect(page).to have_content("Permission Denied") | ||
end | ||
end | ||
|
||
context "when logged in as facility admin" do | ||
before { login_as admin } | ||
|
||
it "requires the facility to be sanger enabled" do | ||
facility.update(sanger_sequencing_enabled: false) | ||
|
||
visit facility_service_sanger_sequencing_sanger_product_path(facility, service) | ||
|
||
expect(page).to have_content("Not Found") | ||
end | ||
|
||
it "does not show the tab if service is sanger disabled" do | ||
service.update(sanger_sequencing_enabled: false) | ||
|
||
visit facility_service_sanger_sequencing_sanger_product_path(facility, service) | ||
|
||
within(".nav-tabs") do | ||
expect(page).to_not have_content("Sanger") | ||
end | ||
end | ||
|
||
it "shows the tab if service is sanger enabled" do | ||
visit facility_service_sanger_sequencing_sanger_product_path(facility, service) | ||
|
||
within(".nav-tabs") do | ||
expect(page).to have_content("Sanger") | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe "sanger product show" do | ||
before { login_as admin } | ||
|
||
it "can navigate by clicking the tab" do | ||
visit manage_facility_service_path(facility, service) | ||
|
||
within(".nav-tabs") do | ||
click_link("Sanger") | ||
end | ||
|
||
expect(page).to have_content("Sanger Configuration") | ||
end | ||
|
||
it "shows sanger product information" do | ||
visit facility_service_sanger_sequencing_sanger_product_path(facility, service) | ||
|
||
expect(page).to have_content("Sanger Configuration") | ||
expect(page).to have_content("Needs a Primer") | ||
expect(page).to have_content("Plated Service Type") | ||
expect(page).to have_link("Edit") | ||
end | ||
|
||
it "allows to edit sanger product" do | ||
visit facility_service_sanger_sequencing_sanger_product_path(facility, service) | ||
|
||
click_link("Edit") | ||
|
||
check("sanger_sequencing_sanger_product[needs_primer]") | ||
select("Fragment Analysis", from: "sanger_sequencing_sanger_product[group]") | ||
|
||
click_button("Save") | ||
|
||
expect(page).to have_content("Sanger Configuration updated successfully") | ||
end | ||
end | ||
end |