Skip to content

Commit

Permalink
Some html style changes for barcode input.
Browse files Browse the repository at this point in the history
Some new tests added for sequencescape_submission
  • Loading branch information
emrojo committed Jan 21, 2021
1 parent e7551a0 commit 3b17556
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/models/sequencescape_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ def assets

def extra_barcodes_list
return nil unless extra_barcodes

extra_barcodes.split(' ')
end

def extra_plates
return @extra_plates if @extra_plates

response = Sequencescape::Api::V2.additional_plates_for_presenter(barcode: extra_barcodes_list)
@extra_plates ||= response
raise "Barcodes not found #{extra_barcodes}" unless @extra_plates
Expand Down
4 changes: 2 additions & 2 deletions app/views/plates/_choose_workflow.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
<% end %>

<% if submission.allowed_extra_barcodes %>
<%= f.label :extra_barcodes, 'Additional labware barcodes' %>
<%= f.label :extra_barcodes, 'Add additional labware barcodes to the submission (Optional)' %>
<br/>
<%= f.text_area :extra_barcodes %>
<%= f.text_area :extra_barcodes, cols: 30, rows: 5, style: 'width: 100%; resize: none;' %>
<% end %>

<%= submit_tag name, class: 'create-submission-button' %>
Expand Down
92 changes: 92 additions & 0 deletions spec/models/sequencescape_submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,98 @@
end
end

describe '#extra_barcodes_list' do
let(:attributes) do
{
api: api, assets: assets, template_uuid: template_uuid,
request_options: request_options, user: user_uuid
}
end

it 'splits by whitespace' do
obj = described_class.new(attributes.merge(extra_barcodes: '1234 5678'))
expect(obj.extra_barcodes_list).to eq(%w[1234 5678])
end
it 'splits by new line' do
obj = described_class.new(attributes.merge(extra_barcodes: "1234\n5678"))
expect(obj.extra_barcodes_list).to eq(%w[1234 5678])
end
end

describe '#extra_plates' do
let(:attributes) do
{
api: api, assets: assets, template_uuid: template_uuid,
request_options: request_options, user: user_uuid
}
end

let(:plate) { create :v2_plate }
let(:obj) { described_class.new(attributes.merge(extra_barcodes: '1234 5678')) }
it 'raises error if barcodes not found in service' do
allow(Sequencescape::Api::V2).to receive(:additional_plates_for_presenter).and_return(nil)
expect { obj.extra_plates }.to raise_error
end
it 'returns the data obtained from service' do
allow(Sequencescape::Api::V2).to receive(:additional_plates_for_presenter).and_return([plate])
expect(obj.extra_plates).to eq([plate])
end
end

describe '#extra_assets' do
let(:attributes) do
{
api: api, assets: assets, template_uuid: template_uuid,
request_options: request_options, user: user_uuid
}
end

let(:plate) { create(:passed_plate) }
let(:plate2) { create(:passed_plate) }
it 'returns the uuids of the labwares wells' do
obj = described_class.new(attributes.merge(extra_barcodes: '1234 5678'))
allow(Sequencescape::Api::V2).to receive(:additional_plates_for_presenter)
.with(barcode: %w[1234 5678]).and_return([plate, plate2])
# There are 4 non-empty wells in each labware
expect(obj.extra_assets.count).to eq(8)
end
it 'removes duplicates uuids in the returned list' do
allow(Sequencescape::Api::V2).to receive(:additional_plates_for_presenter)
.with(barcode: %w[1234 1234 5678]).and_return([plate, plate, plate2])
obj = described_class.new(attributes.merge(extra_barcodes: '1234 1234 5678'))
expect(obj.extra_assets.count).to eq(8)
expect(obj.extra_assets.uniq.count).to eq(8)
end
end

describe '#asset_groups_for_orders_creation' do
let(:attributes) do
{
api: api, assets: assets, template_uuid: template_uuid,
request_options: request_options, user: user_uuid
}
end

it 'returns normal asset groups when no extra barcodes provided' do
obj = described_class.new(attributes)
expect(obj.asset_groups_for_orders_creation).to eq(obj.asset_groups)
end
context 'when extra barcodes provided' do
let(:plate) { create(:passed_plate) }
let(:plate2) { create(:passed_plate) }

before do
allow(Sequencescape::Api::V2).to receive(:additional_plates_for_presenter)
.with(barcode: %w[1234 5678]).and_return([plate, plate2])
end

it 'returns the current assets plus the extra assets' do
obj = described_class.new(attributes.merge(extra_barcodes: '1234 5678'))
expect(obj.asset_groups_for_orders_creation.first[:assets].count).to eq(obj.assets.count + 8)
end
end
end

describe '#save' do
context 'with a single asset group' do
let!(:order_request) do
Expand Down

0 comments on commit 3b17556

Please sign in to comment.