Skip to content

Commit

Permalink
Merge pull request #36 from n00nie/master
Browse files Browse the repository at this point in the history
First jsx unit tests
  • Loading branch information
Celeo authored Oct 29, 2019
2 parents 14670ec + 4fd1ed4 commit 891d8ab
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const CommandButtons = props => {
}
>
<Button
data-testid={'toggleInspectButton'}
disabled={!props.isCmdEditable}
onClick={onToggleInspect.bind(null, props.name)}
icon={
Expand All @@ -61,6 +62,7 @@ const CommandButtons = props => {
{props.canTarget ? (
<Tooltip title="Highlight on page">
<Button
data-testid={'onClickFindButton'}
disabled={!props.isCmdEditable}
onClick={onClickFind.bind(null, props.value)}
icon="eye-o"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React from 'react'
import { cleanup, render } from '@testing-library/react'
import { cleanup, render, fireEvent } from '@testing-library/react'
import CommandButtons from '../../../../src/components/dashboard/fields/CommandButtons.jsx'
import ipc from '../../../../src/common/ipc/ipc_cs'

jest.mock('../../../../src/common/ipc/ipc_cs', () => {})
jest.mock('../../../../src/common/ipc/ipc_bg_cs', () => ({
csInit: () => ({
ask: jest.fn().mockReturnValue(Promise.resolve())
})
}))

afterEach(() => {
cleanup()
Expand Down Expand Up @@ -35,5 +40,46 @@ describe('CommandButtons', () => {
expect(container.querySelector('.ant-btn-group')).not.toBeNull()
})

// TODO more tests ...
it('test onClickFindButton is not undefined and clickable', () => {
const { queryByTestId } = render(getComponent({
canTarget: true,
isCmdEditable: true
}))
const button = queryByTestId('onClickFindButton')
expect(button).not.toBeUndefined()
fireEvent.click(button)
expect(ipc.ask).toHaveBeenCalledTimes(1)
expect(ipc.ask).toHaveBeenCalledWith("PANEL_HIGHLIGHT_DOM", {"lastOperation": null, "locator": ""})
})

it('test toggleInspectButton inspecting true', () => {
const mockSetInspectingTarget = jest.fn()
const mockStopInspecting = jest.fn()
const { queryByTestId } = render(getComponent({
canTarget: true,
isInspecting: true,
setInspectTarget: mockSetInspectingTarget,
stopInspecting: mockStopInspecting,
isCmdEditable: true
}))
const toggleButton = queryByTestId('toggleInspectButton')
fireEvent.click(toggleButton)
expect(mockSetInspectingTarget).toHaveBeenCalledTimes(1)
expect(mockStopInspecting).toHaveBeenCalledTimes(1)
})

it('test toggleInspectButton inspecting false', () => {
const mockSetInspectingTarget = jest.fn()
const mockStartInspecting = jest.fn()
const { queryByTestId } = render(getComponent({
canTarget: true,
setInspectTarget: mockSetInspectingTarget,
startInspecting: mockStartInspecting,
isCmdEditable: true
}))
const toggleButton = queryByTestId('toggleInspectButton')
fireEvent.click(toggleButton)
expect(mockSetInspectingTarget).toHaveBeenCalledTimes(1)
expect(mockStartInspecting).toHaveBeenCalledTimes(1)
})
})

0 comments on commit 891d8ab

Please sign in to comment.