From 5e7cbede076d0dc5fc0f74a2566876ffedd045da Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Wed, 21 Mar 2018 16:48:57 -0700 Subject: [PATCH] Test that 'change' event on TaskRow calls onChangeRuleStatus on that rule --- ui/src/kapacitor/components/TasksTable.tsx | 2 +- .../kapacitor/components/TasksTable.test.tsx | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ui/src/kapacitor/components/TasksTable.tsx b/ui/src/kapacitor/components/TasksTable.tsx index b5b5fa8f7..ae2ef6506 100644 --- a/ui/src/kapacitor/components/TasksTable.tsx +++ b/ui/src/kapacitor/components/TasksTable.tsx @@ -56,7 +56,7 @@ const TasksTable: SFC = ({ ) -class TaskRow extends PureComponent { +export class TaskRow extends PureComponent { handleClickRuleStatusEnabled(task: AlertRule) { return () => { this.props.onChangeRuleStatus(task) diff --git a/ui/test/kapacitor/components/TasksTable.test.tsx b/ui/test/kapacitor/components/TasksTable.test.tsx index 243e61efa..7b4c1e438 100644 --- a/ui/test/kapacitor/components/TasksTable.test.tsx +++ b/ui/test/kapacitor/components/TasksTable.test.tsx @@ -2,6 +2,7 @@ import React from 'react' import {shallow} from 'enzyme' import TasksTable from 'src/kapacitor/components/TasksTable' +import {TaskRow} from 'src/kapacitor/components/TasksTable' import {source, kapacitorRules} from 'test/resources' @@ -20,4 +21,23 @@ describe('Kapacitor.Components.TasksTable', () => { expect(wrapper.exists()).toBe(true) }) }) + + describe('user interaction', () => { + const props = { + source, + task: kapacitorRules[3], + onDelete: () => {}, + onChangeRuleStatus: jest.fn(), + } + + it('calls onChangeRuleStatus when checkbox is effectively clicked', () => { + const wrapper = shallow() + + const checkbox = wrapper.find(({type:'checkbox'})) + checkbox.simulate('change') + + expect(props.onChangeRuleStatus).toHaveBeenCalledTimes(1) + expect(props.onChangeRuleStatus).toHaveBeenCalledWith(kapacitorRules[3]) + }) + }) })