UNPKG

@carbon/ibm-cloud-cognitive-cdai

Version:
68 lines (67 loc) 2.7 kB
// // Copyright IBM Corp. 2020, 2020 // // This source code is licensed under the Apache-2.0 license found in the // LICENSE file in the root directory of this source tree. // import { IdeRemove } from '.'; import * as props from './test_assets/testProps.js'; import * as jth from '../../component_helpers/jest_test_helper_functions.js'; describe('IdeRemove unit tests', function () { var component, unmount; var mountTestComponent = function mountTestComponent() { var defaultProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var test = jth.mountComponent(jth.getJSXForComponent(IdeRemove, defaultProps, props)); component = test.component; unmount = test.unmount; }; beforeEach(function () { jest.useFakeTimers(); }); afterEach(function () { // if unmount defined, call it to clear up any mounted component unmount && unmount(); // reset clocks jest.clearAllTimers(); }); describe('view tests', function () { it('IdeRemove tolerates no props being provided, and renders with defaults', function () { mountTestComponent(); expect(component.getElements()).toMatchSnapshot(); }); it('IdeRemove renders an alternative state if provided post delete', function () { mountTestComponent(props.configWithPostDeleteContent()); component.setState({ didDelete: true }); expect(component.getElements()).toMatchSnapshot(); }); }); describe('unit tests', function () { it('textFieldChange() does nothing is the incorrect event object is passed', function () { mountTestComponent(); var componentInstance = component.instance(); var startingValue = componentInstance.state.itemName; componentInstance.textFieldChange(); // invoked the function with nothing expect(componentInstance.state.itemName).toEqual(startingValue); componentInstance.textFieldChange({ target: {} }); // invoked the function with partial shape expect(componentInstance.state.itemName).toEqual(startingValue); }); it('textFieldChange() updates state when a valid event object is passed', function () { mountTestComponent(); var componentInstance = component.instance(); var startingValue = componentInstance.state.itemName; var testValue = 'test text'; componentInstance.textFieldChange({ target: { value: testValue } }); expect(componentInstance.state.itemName).not.toEqual(startingValue); expect(componentInstance.state.itemName).toEqual(testValue); }); }); });