Skip to content

Commit

Permalink
Fix more tests (#14)
Browse files Browse the repository at this point in the history
* Fix DashboardPanelContainer tests.

* Update KuiColorPicker tests.

* Fix ControlsTab tests.

* Rename vis to input_control_vis. Update and fix InputControlVis tests.

* Fix KuiListingTable tests.

* Fix KuiTextInput tests.

* Update DashboardGrid test snapshots.
  • Loading branch information
cjcenizal authored and nreese committed Dec 7, 2017
1 parent 264a9df commit 4dd65d1
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exports[`renders ControlsTab 1`] = `
handleLabelChange={[Function]}
handleNumberOptionChange={[Function]}
handleRemoveControl={[Function]}
key="1"
moveControl={[Function]}
/>
<ControlEditor
Expand All @@ -51,6 +52,7 @@ exports[`renders ControlsTab 1`] = `
handleLabelChange={[Function]}
handleNumberOptionChange={[Function]}
handleRemoveControl={[Function]}
key="2"
moveControl={[Function]}
/>
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import sinon from 'sinon';
import { mount, shallow } from 'enzyme';

import { findTestSubject } from 'ui_framework/test';
import {
ControlsTab,
} from './controls_tab';
Expand Down Expand Up @@ -84,7 +84,7 @@ test('add control btn', () => {
scope={scopeMock}
stageEditorParams={stageEditorParams}
/>);
component.find('[data-test-subj="inputControlEditorAddBtn"]').simulate('click');
findTestSubject(component, 'inputControlEditorAddBtn', false).simulate('click');
// Use custom match function since control.id is dynamically generated and never the same.
sinon.assert.calledWith(stageEditorParams, sinon.match((newParams) => {
if (newParams.controls.length !== 3) {
Expand All @@ -99,7 +99,7 @@ test('remove control btn', () => {
scope={scopeMock}
stageEditorParams={stageEditorParams}
/>);
component.find('[data-test-subj="inputControlEditorRemoveControl0"]').simulate('click');
findTestSubject(component, 'inputControlEditorRemoveControl0', false).simulate('click');
const expectedParams = {
'controls': [
{
Expand All @@ -123,7 +123,7 @@ test('move down control btn', () => {
scope={scopeMock}
stageEditorParams={stageEditorParams}
/>);
component.find('[data-test-subj="inputControlEditorMoveDownControl0"]').simulate('click');
findTestSubject(component, 'inputControlEditorMoveDownControl0', false).simulate('click');
const expectedParams = {
'controls': [
{
Expand Down Expand Up @@ -159,7 +159,7 @@ test('move up control btn', () => {
scope={scopeMock}
stageEditorParams={stageEditorParams}
/>);
component.find('[data-test-subj="inputControlEditorMoveUpControl1"]').simulate('click');
findTestSubject(component, 'inputControlEditorMoveUpControl1', false).simulate('click');
const expectedParams = {
'controls': [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`Apply and Cancel change btns enabled when there are changes 1`] = `
>
<KuiFlexItem
grow={true}
key="mock-list-control"
style={
Object {
"minWidth": "250px",
Expand Down Expand Up @@ -106,6 +107,7 @@ exports[`Clear btns enabled when there are values 1`] = `
>
<KuiFlexItem
grow={true}
key="mock-list-control"
style={
Object {
"minWidth": "250px",
Expand Down Expand Up @@ -200,6 +202,7 @@ exports[`Renders list control 1`] = `
>
<KuiFlexItem
grow={true}
key="mock-list-control"
style={
Object {
"minWidth": "250px",
Expand Down Expand Up @@ -294,6 +297,7 @@ exports[`Renders range control 1`] = `
>
<KuiFlexItem
grow={true}
key="mock-range-control"
style={
Object {
"minWidth": "250px",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import sinon from 'sinon';
import { mount, shallow } from 'enzyme';
import { findTestSubject } from 'ui_framework/test';

import {
InputControlVis,
} from './vis';
} from './input_control_vis';

const mockListControl = {
id: 'mock-list-control',
Expand Down Expand Up @@ -114,7 +115,7 @@ test('clearControls', () => {
hasChanges={() => { return true; }}
hasValues={() => { return true; }}
/>);
component.find('[data-test-subj="inputControlClearBtn"]').simulate('click');
findTestSubject(component, 'inputControlClearBtn', false).simulate('click');
sinon.assert.calledOnce(clearControls);
sinon.assert.notCalled(submitFilters);
sinon.assert.notCalled(resetControls);
Expand All @@ -132,7 +133,7 @@ test('submitFilters', () => {
hasChanges={() => { return true; }}
hasValues={() => { return true; }}
/>);
component.find('[data-test-subj="inputControlSubmitBtn"]').simulate('click');
findTestSubject(component, 'inputControlSubmitBtn', false).simulate('click');
sinon.assert.calledOnce(submitFilters);
sinon.assert.notCalled(clearControls);
sinon.assert.notCalled(resetControls);
Expand All @@ -150,7 +151,7 @@ test('resetControls', () => {
hasChanges={() => { return true; }}
hasValues={() => { return true; }}
/>);
component.find('[data-test-subj="inputControlCancelBtn"]').simulate('click');
findTestSubject(component, 'inputControlCancelBtn', false).simulate('click');
sinon.assert.calledOnce(resetControls);
sinon.assert.notCalled(clearControls);
sinon.assert.notCalled(submitFilters);
Expand All @@ -168,7 +169,7 @@ test('stageFilter list control', () => {
hasChanges={() => { return true; }}
hasValues={() => { return true; }}
/>);
const reactSelectInput = component.find(`#${mockListControl.id}`);
const reactSelectInput = component.find(`#${mockListControl.id}`).hostNodes();
reactSelectInput.simulate('change', { target: { value: 'choice1' } });
reactSelectInput.simulate('keyDown', { keyCode: 9, key: 'Tab' });
sinon.assert.notCalled(clearControls);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { InputControlVis } from './components/vis/vis';
import { InputControlVis } from './components/vis/input_control_vis';
import { controlFactory } from './control/control_factory';

class VisController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exports[`renders DashboardGrid 1`] = `
>
<div
className=""
key="1"
>
<Connect(DashboardPanel)
embeddableFactory={
Expand All @@ -45,6 +46,7 @@ exports[`renders DashboardGrid 1`] = `
</div>
<div
className=""
key="2"
>
<Connect(DashboardPanel)
embeddableFactory={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ test('renders an error when embeddableFactory.render throws an error', (done) =>
});
};
const component = mount(<Provider store={store}><DashboardPanelContainer {...props} /></Provider>);

setTimeout(() => {
component.update();
const panelError = component.find(PanelError);
expect(panelError.length).toBe(1);
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`renders KuiColorPicker 1`] = `
aria-label="aria-label"
class="kuiColorPicker__swatch"
data-test-subj="colorSwatch"
style="background:#ffeedd;"
style="background:#ffeedd"
/>
<div
aria-label="Color selection is #ffeedd"
Expand All @@ -36,7 +36,7 @@ exports[`renders KuiColorPicker with an empty swatch when color is null 1`] = `
aria-label="aria-label"
class="kuiColorPicker__swatch kuiColorPicker__emptySwatch"
data-test-subj="colorSwatch"
style="background:;"
style="background:"
>
<svg>
<line
Expand Down Expand Up @@ -69,7 +69,7 @@ exports[`renders KuiColorPicker without a color label when showColorLabel is fal
aria-label="aria-label"
class="kuiColorPicker__swatch"
data-test-subj="colorSwatch"
style="background:#ffffff;"
style="background:#ffffff"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ test('Setting a new color calls onChange', () => {
const event = { target: { value: '#000000' } };
const inputs = colorPicker.find('input');
expect(inputs.length).toBe(1);
inputs.get(0).value = '';
inputs.simulate('change', event);
sinon.assert.calledOnce(onChange);
sinon.assert.calledWith(onChange, '#000000');
Expand Down
10 changes: 5 additions & 5 deletions ui_framework/src/components/form/text_input/text_input.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render, shallow, mount } from 'enzyme';
import { requiredProps } from '../../../test/required_props';
import { requiredProps, findTestSubject } from '../../../test';
import sinon from 'sinon';

import {
Expand Down Expand Up @@ -55,8 +55,8 @@ describe('KuiTextInput', () => {
);

expect(
component.find('[data-test-subj="input"]').matchesElement(document.activeElement)
).toBe(true);
findTestSubject(component, 'input')
).toBe(document.activeElement);
});

test('does not focus the element by default', () => {
Expand All @@ -68,8 +68,8 @@ describe('KuiTextInput', () => {
);

expect(
component.find('[data-test-subj="input"]').matchesElement(document.activeElement)
).toBe(false);
findTestSubject(component, 'input')
).not.toBe(document.activeElement);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from 'react';
import { mount, shallow } from 'enzyme';
import { requiredProps } from '../../../test/required_props';
import {
takeMountedSnapshot,
} from 'ui_framework/src/test';
import { requiredProps, takeMountedSnapshot } from '../../../test';
import {
KuiListingTable,
} from './listing_table';
Expand Down

0 comments on commit 4dd65d1

Please sign in to comment.