@carbon/ibm-cloud-cognitive-cdai
Version:
Carbon for Cloud & Cognitive CD&AI UI components
114 lines (112 loc) • 5.55 kB
JavaScript
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.
//
var _require = require('gherkin-jest'),
cucumber = _require.cucumber;
import { IdeHome } from '.';
import * as props from './test_assets/testProps.js';
import { idAttributeSelector } from '../../component_helpers/IDHelper';
var TASK_BASIC = 'Basics';
var TASK_RECENT = 'Recent tasks';
var TASK_ACC = 'Accelerators';
var TASK_CUSTOM = 'Custom';
var IDE_CARD = 'IDE_CARD';
var testSets = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, TASK_BASIC, props.gettingStartedSetFunc), TASK_RECENT, props.recentTasksSetFunc), TASK_ACC, props.cardWidthSetFunc), TASK_CUSTOM, props.customCardContentSetFunc), IDE_CARD, props.tasksForEachIdeCardType);
cucumber.defineRule('Setup of the IdeHome world', function (world) {
world.componentToRender = IdeHome;
});
var setHelper = function setHelper() {
var currentProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var newSetToAdd = arguments.length > 1 ? arguments[1] : undefined;
if (currentProps.sets) {
return {
sets: currentProps.sets.concat(newSetToAdd)
};
} else {
return {
sets: [newSetToAdd]
};
}
};
var getSetForActivity = function getSetForActivity() {
var taskName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : TASK_BASIC;
var interactFunction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
return true;
};
return testSets[taskName](interactFunction);
};
cucumber.defineRule('a set of activities called {string}', function (world, activitySet) {
world.ideInteractionCb = jest.fn();
world.defaultProps = props.coreConfigFunc();
world.props = setHelper(world.props, getSetForActivity(activitySet, world.ideInteractionCb));
});
cucumber.defineRule('the {string} set is the selected tab', function (world, setName) {
var propsToCheckFor = getSetForActivity(setName, world.ideInteractionCb);
var indexOfSet = world.props.sets.findIndex(function (set) {
return set.id === propsToCheckFor.id;
});
expect(world.mountedComponent.find(idAttributeSelector("IdeHome-Tabs")).props().selected).toBe(indexOfSet);
});
cucumber.defineRule('the {string} activities set is rendered', function (world, setName) {
var propsToCheckFor = getSetForActivity(setName, world.ideInteractionCb);
var tabSelector = idAttributeSelector("IdeHome-Tab-".concat(propsToCheckFor.id));
// confirm a tab for this set is present
expect(world.mountedComponent.exists(tabSelector)).toBe(true);
world.mountedComponent.simulate('click'); // click it to get items on screen
});
cucumber.defineRule('the {string} activities set is rendered only', function (world, setName) {
var propsToCheckFor = getSetForActivity(setName, world.ideInteractionCb);
var noMatchSelector = idAttributeSelector("IdeHome-Tab-".concat(propsToCheckFor.id));
// as only one set, there should be no Tabs
expect(world.mountedComponent.exists(noMatchSelector)).toBe(false);
});
cucumber.defineRule('the selected tab is changed to {string}', function (world, setName) {
var propsToCheckFor = getSetForActivity(setName, world.ideInteractionCb);
var tabSelector = idAttributeSelector("IdeHome-Tab-".concat(propsToCheckFor.id));
// confirm a tab for this set is present
expect(world.mountedComponent.exists(tabSelector)).toBe(true);
world.mountedComponent.find(tabSelector).prop('onClick')({
type: 'click'
}); // trigger the click handler directly, rather than using simulate (assume browser passes event through)
});
cucumber.defineRule('the callback is invoked with {string} task id as its parameter', function (world, taskId) {
expect(world.ideInteractionCb).toBeCalled();
expect(world.ideInteractionCb.mock.calls[0][0]).toEqual(taskId);
});
cucumber.defineRule('the property startSelected is added to the {string} set', function (world, setId) {
world.props.sets.find(function (set) {
return set.id === setId;
}).startSelected = true;
});
cucumber.defineRule('I want to render sections rather than tabs', function (world) {
world.props.multipleSetType = 'section';
});
cucumber.defineRule('the {string} activities set is rendered as a section', function (world, setName) {
var propsToCheckFor = getSetForActivity(setName, world.ideInteractionCb);
var sectionSelector = idAttributeSelector("IdeHome-Section-".concat(propsToCheckFor.id));
// confirm a section for this set is present
expect(world.mountedComponent.exists(sectionSelector)).toBe(true);
});
cucumber.defineRule('the expected IDECard components are rendered', function (world) {
var _getSetForActivity = getSetForActivity(IDE_CARD),
tasks = _getSetForActivity.tasks;
// mapping of the card IDs from the tasks (in IDE_CARD) to the expected IdeCard type property given at render
var expectedTypesById = {
ide_card: 'text',
custom_card: 'custom',
link_card: 'link',
external_link_card: 'externalLink',
no_type: 'text'
};
tasks.forEach(function (_ref) {
var taskId = _ref.taskId;
var selectorForCard = "IdeCard[cardId=\"".concat(taskId, "\"]");
expect(world.mountedComponent.exists(selectorForCard)).toBe(true);
var ideCardForTask = world.mountedComponent.find(selectorForCard);
expect(ideCardForTask.props().cardType).toBe(expectedTypesById[taskId]);
});
});