Skip to content

Commit

Permalink
enzyme removed from button-bar and delete-buton-base
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelDau committed Apr 10, 2024
1 parent 9e5a48b commit 1b6f814
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import ButtonBar from '../../../src/scripts/common/components/button-bar'
import renderer from 'react-test-renderer'
import { mount } from 'enzyme'

describe('ButtonBar', () => {
test('ButtonBar component', () => {
Expand Down Expand Up @@ -35,21 +34,18 @@ describe('ButtonBar', () => {
}
]
const mockClick = jest.fn()
const component = mount(<ButtonBar onClick={mockClick}>{children}</ButtonBar>)
const component = renderer.create(<ButtonBar onClick={mockClick}>{children}</ButtonBar>)
const buttonInstance = component.root.findByType('button')

component
.childAt(0)
.find('button')
.simulate('click')
expect(mockClick).toBeCalledTimes(1)
buttonInstance.props.onClick()
expect(mockClick).toHaveBeenCalledTimes(1)

// default function coverage for buttonBarOnClick
const componentNoClick = mount(<ButtonBar>{children}</ButtonBar>)
componentNoClick
.childAt(0)
.find('button')
.simulate('click')
expect(mockClick).toBeCalledTimes(1)
const componentNoClick = renderer.create(<ButtonBar>{children}</ButtonBar>)
const buttonInstanceNoClick = componentNoClick.root.findByType('button')

buttonInstanceNoClick.props.onClick()
expect(mockClick).toHaveBeenCalledTimes(1)
})

test('ButtonBar component clicks button but does not fire', () => {
Expand All @@ -59,13 +55,10 @@ describe('ButtonBar', () => {
}
]
const mockClick = jest.fn()
const component = mount(<ButtonBar onClick={mockClick}>{children}</ButtonBar>)

component
.childAt(0)
.find('button')
.simulate('click')
const component = renderer.create(<ButtonBar onClick={mockClick}>{children}</ButtonBar>)
const buttonInstance = component.root.findByType('button')

buttonInstance.props.onClick()
expect(mockClick).toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import DeleteButton from '../../../src/scripts/common/components/delete-button'
import DeleteButtonBase from '../../../src/scripts/common/components/delete-button-base'
import { mount } from 'enzyme'
import renderer from 'react-test-renderer'

jest.mock('../../../src/scripts/common/page/focus')
Expand Down Expand Up @@ -44,9 +43,9 @@ describe('DeleteButton', () => {

test('DeleteButton calls focus callback with ref argument', () => {
const focus = require('../../../src/scripts/common/page/focus').default
const wrapper = mount(<DeleteButton focus={focus} />)
const inst = wrapper.find(DeleteButtonBase).instance()
inst.focus()
expect(focus).toHaveBeenCalledWith(inst.deleteButtonRef)
const component = renderer.create(<DeleteButton focus={focus} />)
const inst = component.root.findByType(DeleteButtonBase).instance // Get the instance of DeleteButton
inst.focus() // Call the focus method
expect(focus).toHaveBeenCalledWith(inst.deleteButtonRef) // Check if focus callback is called with correct argument
})
})

0 comments on commit 1b6f814

Please sign in to comment.