import React from 'react' ; import Enzyme from 'enzyme' ; import EnzymeToJson from 'enzyme-to-json' ; import Adapter from 'enzyme-adapter-react-16' ; import ScanQRStep from './ScanQRStep' ; Enzyme . configure ( { adapter : new Adapter ( ) } ) ; jest . useFakeTimers ( ) ; const bp3QRCodeDialogRootSelector = '#bp3-qr-code-dialog-root' ; const magnifyQRCodeButtonSelector = '#magnify-qr-code-button' ; const qrCodeDialogInnerSelector = '#qr-code-dialog-inner' ; describe ( '<ScanQRStep />' , ( ) => { let wrapper = Enzyme . shallow ( < ScanQRStep />); beforeEach ( ( ) => { wrapper = Enzyme . shallow ( < ScanQRStep />); } ) ; afterEach ( ( ) => { jest . clearAllMocks ( ) ; } ) ; describe ( 'when rendered' , ( ) => { it ( 'should match exact snapshot' , ( ) => { expect ( EnzymeToJson ( wrapper ) ) . toMatchSnapshot ( ) ; } ) ; } ) ; describe ( 'when user clicks on magnify QR code button' , ( ) => { it ( 'should set "QR Code Dialog Root" isOpen property to "true"' , ( ) => { wrapper . find ( magnifyQRCodeButtonSelector ) . props ( ) . onClick ( ) ; expect ( wrapper . find ( bp3QRCodeDialogRootSelector ) . props ( ) . isOpen ) . toBe ( true ) ; } ) ; } ) ; describe ( `when magnified QR code dialog is opened,
  and when user closes magnified QR code dialog` , ( ) => { it ( 'should set "QR Code Dialog Root" isOpen property to "false"' , ( ) => { wrapper . find ( magnifyQRCodeButtonSelector ) . props ( ) . onClick ( ) ; wrapper . find ( bp3QRCodeDialogRootSelector ) . props ( ) . onClose ( ) ; expect ( wrapper . find ( bp3QRCodeDialogRootSelector ) . props ( ) . isOpen ) . toBe ( false ) ; } ) ; } ) ; describe ( `when magnified QR code dialog is opened,
  and when user clicks on qr code dialog inner` , ( ) => { it ( 'should set "QR Code Dialog Root" isOpen property to "false"' , ( ) => { wrapper . find ( magnifyQRCodeButtonSelector ) . props ( ) . onClick ( ) ; wrapper . find ( qrCodeDialogInnerSelector ) . props ( ) . onClick ( ) ; expect ( wrapper . find ( bp3QRCodeDialogRootSelector ) . props ( ) . isOpen ) . toBe ( false ) ; } ) ; } ) ; } ) ;