<commit_before>/* global describe, it */
import { expect } from 'chai'
import sinon from 'sinon'
import CalibratePlaceable from 'renderer/components/CalibratePlaceable.vue'
import { getRenderedVm } from '../../util.js'

function getMockStore () {
  return {
    actions: {
      pickUpTip: sinon.spy(),
      dropTip: sinon.spy(),
      moveToPosition: sinon.spy(),
      calibrate: sinon.spy()
    }
  }
}

const mockStore = getMockStore()

let placeable = {
  'slot': 'A1',
  'label': 'tiprack-12ml',
  'sanitizedType': 'tiprack',
  'calibrated': true
}
let instrument = {'axis': 'a'}

describe('CalibratePlaceable.vue', () => {
  it('renders pick_up/drop tip if placeable is tiprack', () => {
    expect(getRenderedVm(CalibratePlaceable, {
      placeable,
      instrument
    }).$el.querySelectorAll('button').length).to.equal(4)
  })

  it('does not render tip buttons if placeable is not tiprack', () => {
    let plate = JSON.parse(JSON.stringify(placeable))
    plate['sanitizedType'] = 'default'

    expect(getRenderedVm(CalibratePlaceable, {
      placeable: plate,
      instrument
    }).$el.querySelectorAll('button').length).to.equal(2)
  })

  it('disables all buttons except for save when not calibrated', () => {
    let uncalibratedPlate = JSON.parse(JSON.stringify(placeable))
    uncalibratedPlate['calibrated'] = false

    expect(getRenderedVm(CalibratePlaceable, {
      placeable: uncalibratedPlate,
      instrument
    }).$el.querySelectorAll('button.disabled').length).to.equal(3)
  })

  it('enables all buttons when calibrated', () => {
    expect(getRenderedVm(CalibratePlaceable, {
      placeable,
      instrument
    }).$el.querySelectorAll('button.disabled').length).to.equal(0)
  })

  it('calls the correct actions for each button click', () => {
    let renderedCalibratePlaceable = getRenderedVm(CalibratePlaceable, {
      placeable,
      instrument
    }, mockStore)

    renderedCalibratePlaceable.calibrate()
    renderedCalibratePlaceable.moveToPosition()
    renderedCalibratePlaceable.pickUpTip()
    renderedCalibratePlaceable.dropTip()

    expect(mockStore.actions.calibrate.called).to.be.true
    expect(mockStore.actions.moveToPosition.called).to.be.true
    expect(mockStore.actions.pickUpTip.called).to.be.true
    expect(mockStore.actions.dropTip.called).to.be.true
  })
})
<commit_msg>refactor calibratePlaceable spec to be like others and be DRY<commit_after>/* global describe, it */
import { expect } from 'chai'
import sinon from 'sinon'
import CalibratePlaceable from 'renderer/components/CalibratePlaceable.vue'
import { getRenderedVm } from '../../util.js'

function getMockStore () {
  return {
    actions: {
      pickUpTip: sinon.spy(),
      dropTip: sinon.spy(),
      moveToPosition: sinon.spy(),
      calibrate: sinon.spy()
    }
  }
}

let placeable = {
  'slot': 'A1',
  'label': 'tiprack-12ml',
  'sanitizedType': 'tiprack',
  'calibrated': true
}
let instrument = {'axis': 'a'}

const mockStore = getMockStore()
const propsData = { placeable, instrument }
let calibratePlaceable = getRenderedVm(CalibratePlaceable, propsData, mockStore)

describe('CalibratePlaceable.vue', () => {
  it('renders pick_up/drop tip if placeable is tiprack', () => {
    const buttons = calibratePlaceable.$el.querySelectorAll('button')
    expect(buttons.length).to.equal(4)
  })

  it('does not render tip buttons if placeable is not tiprack', () => {
    let plate = JSON.parse(JSON.stringify(placeable))
    plate['sanitizedType'] = 'default'

    expect(getRenderedVm(CalibratePlaceable, {
      placeable: plate,
      instrument
    }).$el.querySelectorAll('button').length).to.equal(2)
  })

  it('disables all buttons except for save when not calibrated', () => {
    let uncalibratedPlate = JSON.parse(JSON.stringify(placeable))
    uncalibratedPlate['calibrated'] = false

    expect(getRenderedVm(CalibratePlaceable, {
      placeable: uncalibratedPlate,
      instrument
    }).$el.querySelectorAll('button.disabled').length).to.equal(3)
  })

  it('enables all buttons when calibrated', () => {
    let buttons = calibratePlaceable.$el.querySelectorAll('button.disabled')
    expect(buttons.length).to.equal(0)
  })

  it('calls the correct actions for each button click', () => {
    calibratePlaceable.calibrate()
    calibratePlaceable.moveToPosition()
    calibratePlaceable.pickUpTip()
    calibratePlaceable.dropTip()

    expect(mockStore.actions.calibrate.called).to.be.true
    expect(mockStore.actions.moveToPosition.called).to.be.true
    expect(mockStore.actions.pickUpTip.called).to.be.true
    expect(mockStore.actions.dropTip.called).to.be.true
  })
})

{'fraction_non_alphanumeric': 0.13774520370769563, 'fraction_numerical': 0.003017891787023065, 'mean_word_length': 3.994617868675996, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3951005', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1504, 'n_words': 274}