@carbon/ibm-cloud-cognitive-cdai
Version:
Carbon for Cloud & Cognitive CD&AI UI components
73 lines (71 loc) • 3.62 kB
JavaScript
;
var _typeof = require("@babel/runtime/helpers/typeof");
var _ = require(".");
var props = _interopRequireWildcard(require("./test_assets/testProps.js"));
var jth = _interopRequireWildcard(require("../../component_helpers/jest_test_helper_functions.js"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
//
// 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.
//
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);
});
});
});