UNPKG

@carbon/ibm-cloud-cognitive-cdai

Version:
82 lines (81 loc) 2.93 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; // // 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 { IdeEmptyState } from '.'; import customImage from './test_assets/custom.lg.svg'; import * as jth from '../../component_helpers/jest_test_helper_functions.js'; describe('IdeEmptyState', function () { var component, unmount; var mountTestComponent = function mountTestComponent(props) { var getJSXForComponent = jth.getJSXForComponent, mountComponent = jth.mountComponent; var test = mountComponent(getJSXForComponent(IdeEmptyState, {}, props), false); component = test.component; unmount = test.unmount; }; afterEach(function () { return unmount && unmount(); }); it('renders when no props are defined', function () { mountTestComponent(); expect(component.getElements()).toMatchSnapshot(); }); var rendersWhenPropIsDefined = function rendersWhenPropIsDefined(propName, propValue, suffix) { var name = "renders when the ".concat(propName, " prop is defined"); if (suffix) { name += " as ".concat(suffix); } it(name, function () { mountTestComponent(_defineProperty({}, propName, propValue)); expect(component.getElements()).toMatchSnapshot(); }); }; rendersWhenPropIsDefined('format', 'lg', 'lg'); rendersWhenPropIsDefined('format', 'sm', 'sm'); rendersWhenPropIsDefined('image', 'apiError', 'apiError'); rendersWhenPropIsDefined('image', 'default', 'default'); rendersWhenPropIsDefined('image', 'deploy', 'deploy'); rendersWhenPropIsDefined('image', 'noSearchResults', 'noSearchResults'); rendersWhenPropIsDefined('image', 'notAuthorized', 'notAuthorized'); rendersWhenPropIsDefined('image', { alt: 'Custom alt', className: 'custom-classname', src: customImage }, 'an object'); rendersWhenPropIsDefined('image', function () { return customImage; }, 'a function that returns an image'); rendersWhenPropIsDefined('title', 'Custom title', 'a string'); rendersWhenPropIsDefined('body', 'Custom body', 'a string'); rendersWhenPropIsDefined('button', { kind: 'primary', onClick: function onClick() {}, text: 'Custom text' }, 'an object'); rendersWhenPropIsDefined('button', function () { return ''; }, 'a function'); rendersWhenPropIsDefined('links', { text: 'Custom link', url: 'http://ibm.com' }, 'an object'); rendersWhenPropIsDefined('links', [{ text: 'Custom link 1', url: 'http://ibm.com' }, { text: 'Custom external link 2', url: 'http://ibm.com', target: '_blank' }], 'an array of objects'); rendersWhenPropIsDefined('links', [{ text: 'Custom link 1', url: '#', onClick: function onClick() { return console.log('custom function'); } }], 'an object'); });