import * as React from 'react' ; import { shallow , mount } from 'enzyme' ; import * as CustomLabwareFixtures from '../../../../redux/custom-labware/__fixtures__' ; import * as CustomLabware from '../../../../redux/custom-labware' ; import { LabwareItem } from '../LabwareItem' ; import { Warning } from '../Warning' ; import type { InvalidLabwareFile , ValidLabwareFile , } from '../../../../redux/custom-labware/types' ; describe ( 'LabwareItem' , ( ) => { const invalidFile = { type : CustomLabware . INVALID_LABWARE_FILE , filename : 'some_file.json' , modified : 1571688000000 , } ; const validFile = { type : CustomLabware . VALID_LABWARE_FILE , filename : 'some_file.json' , modified : 1571688000000 , definition : { ... CustomLabwareFixtures . mockDefinition , parameters : { ... CustomLabwareFixtures . mockDefinition . parameters , loadName : 'foo_bar' , } , metadata : { ... CustomLabwareFixtures . mockDefinition . metadata , displayName : 'Foo Bar' , displayCategory : 'wellPlate' , } , } , } ; it ( 'component renders' , ( ) => { const treeInvalid = shallow ( < LabwareItem file = { invalidFile } / > ) ; const treeValid = shallow ( < LabwareItem file = { validFile } / > ) ; expect ( treeInvalid ) . toMatchSnapshot ( ) ; expect ( treeValid ) . toMatchSnapshot ( ) ; } ) ; it ( 'is a <li>' , ( ) => { const tree = mount ( < LabwareItem file = { invalidFile } / > ) ; expect ( tree . getDOMNode ( ) . tagName ) . toBe ( 'LI' ) ; } ) ; it ( 'renders props' , ( ) => { const html = mount ( < LabwareItem file = { validFile } / > ) . html ( ) ; expect ( html ) . toContain ( 'some_file.json' ) ; expect ( html ) . toContain ( 'foo_bar' ) ; expect ( html ) . toContain ( 'Foo Bar' ) ; expect ( html ) . toContain ( 'Well Plate' ) ; expect ( html ) . toContain ( '2019-10-21' ) ; } ) ; it ( 'displays a Warning for invalid files' , ( ) => { const SPECS = [ { file : CustomLabwareFixtures . mockInvalidLabware , expectation : /not a valid Opentrons labware definition/ , } , { file : CustomLabwareFixtures . mockDuplicateLabware , expectation : /conflicts with another labware definition/ , } , { file : CustomLabwareFixtures . mockOpentronsLabware , expectation : /conflicts with an Opentrons standard labware definition/ , } , ] ; SPECS . forEach ( ( { file , expectation } ) => { const wrapper = mount ( < LabwareItem file = { file } / > ) ; expect ( wrapper . find ( Warning ) . html ( ) ) . toMatch ( expectation ) ; } ) ; } ) ; } ) ;