Skip to content

Commit

Permalink
Merge pull request #61 from emrojo/bugfix_printer_selection_not_working
Browse files Browse the repository at this point in the history
Bugfix printer selection not working
  • Loading branch information
emrojo authored Oct 18, 2019
2 parents 3660163 + 21f1da5 commit f2c4a29
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/controllers/steps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
@activity.create_step({
step_type: @step_type,
user: @current_user,
printer: @printer_config,
printer_config: @printer_config,
asset_group: @asset_group
})
head :ok
Expand Down
7 changes: 5 additions & 2 deletions app/javascript/components/activity.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class Activity extends React.Component {
this.onChangeStateStep = this.onChangeStateStep.bind(this)
this.changeStateStep = this.changeStateStep.bind(this)

this.onChangeTubePrinter = this.onChangeTubePrinter.bind(this)
this.onChangePlatePrinter = this.onChangePlatePrinter.bind(this)

this.onCollapseFacts = this.onCollapseFacts.bind(this)
this.onAddBarcodesToAssetGroup = this.onAddBarcodesToAssetGroup.bind(this)

Expand Down Expand Up @@ -200,10 +203,10 @@ class Activity extends React.Component {
})
}

onChangeTubePrinter() {
onChangeTubePrinter(e) {
this.setState({selectedTubePrinter: e.target.value})
}
onChangePlatePrinter() {
onChangePlatePrinter(e) {
this.setState({selectedPlatePrinter: e.target.value})
}
onExecuteStep(msg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ class PrintersSelection extends React.Component {
<div className="row">
<div className="form-group col-xs-6">
<LabelTag htmlFor="tube_printer_select">Tube Printer</LabelTag>
<SelectTag name="tube_printer_select" className="form-control"
<SelectTag name="tube_printer_select" className="form-control"
defaultValue={this.props.tubePrinter.defaultValue}
onChange={this.props.onChangeTubePrinter}
>
{this.renderOptions(this.props.tubePrinter.optionsData)}
</SelectTag>
</div>
<div className="form-group col-xs-6">
<LabelTag htmlFor="plate_printer_select">Plate Printer</LabelTag>
<SelectTag name="plate_printer_select" className="form-control"
<SelectTag name="plate_printer_select" className="form-control"
defaultValue={this.props.platePrinter.defaultValue}
onChange={this.props.onChangePlatePrinter}
>
{this.renderOptions(this.props.platePrinter.optionsData)}
</SelectTag>
Expand Down
1 change: 1 addition & 0 deletions app/models/activities/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Tasks
def create_step(params)
step = params[:step_type].class_for_task_type.create!({
activity: self,
printer_config: params[:printer_config],
step_type: params[:step_type],
asset_group: params[:asset_group],
user: params[:user]})
Expand Down
2 changes: 1 addition & 1 deletion app/models/steps/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def process
assets_for_printing = assets_for_printing.to_a.concat(updates.assets_for_printing)
end
if assets_for_printing.length > 0
AssetGroup.new(assets: assets_for_printing).print(user.printer_config, user.username)
AssetGroup.new(assets: assets_for_printing).print(printer_config, user.username)
end
end

Expand Down
18 changes: 18 additions & 0 deletions spec/controllers/steps_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@
}
}.to change{Step.all.count}
end

context 'when receiving a specific printer config' do
let(:tube_printer) { create :printer, name: 'tubes'}
let(:plate_printer) { create :printer, name: 'plates'}
it 'stores the printer_config provided as parameter' do
post :create, params: {
activity_id: activity.id, step: {
asset_group_id: asset_group.id, step_type_id: step_type.id,
tube_printer_id: tube_printer.id, plate_printer_id: plate_printer.id
}
}
expect(Step.last.printer_config).to eq({
"Tube" => tube_printer.name,
"Plate" => plate_printer.name,
"TubeRack" => plate_printer.name
})
end
end
end
context '#update' do
let(:step) {
Expand Down
11 changes: 11 additions & 0 deletions spec/models/step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ def create_assets(num, type)
num.times.map { create_asset(type) }
end

describe '#create' do
context 'when creating a step with a specific printer config' do
let(:printer_data_config) { {"Tube"=>"1234", "Plate"=>"6789"} }
it 'stores the printer config in the database' do
s = create(:step, printer_config: printer_data_config)
s2 = Step.find_by(id: s.id)
expect(s2.printer_config).to eq(printer_data_config)
end
end
end

describe '#run' do
setup do
@step_type = FactoryBot.create :step_type
Expand Down
11 changes: 9 additions & 2 deletions spec/models/steps/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
describe Steps::Task do

let(:user) { create :user, username: 'test'}
let(:printer_config) {
{
"Plate" => "plates",
"Tube" => "tubes",
"TubeRack" => "plates"
}
}
def build_instance
asset_group = build :asset_group
build :step, asset_group: asset_group
build :step, asset_group: asset_group, printer_config: printer_config
end

def create_instance(step_type, activity, group)
create(:step, step_type: step_type, activity: activity, asset_group: group, user: user)
create(:step, step_type: step_type, activity: activity, asset_group: group, user: user, printer_config: printer_config)
end

#it_behaves_like 'background task'
Expand Down
33 changes: 18 additions & 15 deletions test/javascript/components/activity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@ import Activity from 'activity';

describe('Activity', () => {
it('renders Activity component', () => {
const wrapper = shallow(<Activity {...buildActivityState(1,0)} />);
expect(wrapper.find('div')).toHaveLength(1);
const wrapper = shallow(<Activity {...buildActivityState(1,0)} />)
expect(wrapper.find('div')).toHaveLength(1)
})

it('renders only one AssetGroupEditor component', () => {
const wrapper = mount(<Activity {...buildActivityState(2,0)} />);
expect(wrapper.find('AssetGroupEditor')).toHaveLength(1);
const wrapper = mount(<Activity {...buildActivityState(2,0)} />)
expect(wrapper.find('AssetGroupEditor')).toHaveLength(1)
})

// describe('State Test failure 1', () => {

// const stateFailure1 = require('../../data/react/state_failure.json')
describe('when changing the printers', () => {
const wrapper = mount(<Activity {...buildActivityState(2,0)} />)

// it('shallows passes test failure 1', () => {
// const wrapper = shallow(<Activity {...stateFailure1} />)
// expect(wrapper.find('div')).toHaveLength(1)
// })
it('changes the selected tube printer in the react state', () => {
expect(wrapper.instance().state.selectedTubePrinter).toEqual(8)
wrapper.find({name: "tube_printer_select"}).first().simulate('change', {target: { value: 1}})
expect(wrapper.instance().state.selectedTubePrinter).toEqual(1)
})

// it('mounts test failure 1', () => {
// const wrapper = mount(<Activity {...stateFailure1} />);
// expect(wrapper.find('AssetGroupEditor')).toHaveLength(1);
// })
// })
it('changes the selected plate printer in the react state', () => {
expect(wrapper.instance().state.selectedPlatePrinter).toEqual(14)
wrapper.find({name: "plate_printer_select"}).first().simulate('change', {target: { value: 2}})
expect(wrapper.instance().state.selectedPlatePrinter).toEqual(2)
})

})
})
8 changes: 5 additions & 3 deletions test/javascript/test_helpers/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ const buildEmptyActivityState = () => {
},
"tubePrinter":{
"optionsData":[
["printer 1",1]
["printer 1",1],
["printer 2",8]
],
"defaultValue":8
},"platePrinter":{
"optionsData":[
["printer 2",2]
["printer 3",2],
["printer 14",14]
],
"defaultValue":2
"defaultValue":14
},
"shownComponents":{},
"activityRunning":false,
Expand Down

0 comments on commit f2c4a29

Please sign in to comment.