'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Dashboard *| (C) Copyright IBM Corp. 2018, 2020 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['underscore', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', './api/ViprUITestApi', './BinarySearchTupleLocator', './SelectorTupleLocator'], function (_, APIFactory, ViprUITestAPI, BinarySearchTupleLocator, SelectorTupleLocator) { /** * The ViprUITest is a support class for the functional Test UI. * Its purpose is to allow the test framework to check and interact with a visualization from an external point of view. * In the case of VIPR, we assume that VIPR "does the right thing" and checking its structures via getItemsAtPoint/getItemsInPolygon is sufficient. * The hope is to have VIPR implement an interface and this class will simply adapt to the UITestAPI interface and not use private information. */ var ViprUITest = function () { function ViprUITest(options) { _classCallCheck(this, ViprUITest); this.content = options.content; } ViprUITest.prototype.getAPI = function getAPI() { if (!this._api) { this._api = APIFactory.createAPI(this, [ViprUITestAPI]); } return this._api; }; ViprUITest.prototype._initLocators = function _initLocators() { if (!this.locators) { var viprView = this.content.getFeature('livewidget.internal').getVisView(); var viprWidget = viprView.viprWidget; var viprViewElement = viprView.$el; this.locators = { data: new BinarySearchTupleLocator({ viprWidget: viprWidget }), //Most test logic will want this one axis: new SelectorTupleLocator({ '$el': viprViewElement, viprWidget: viprWidget, selector: '.axis-label' }), //Most cases won't need selectors like these legend: new SelectorTupleLocator({ '$el': viprViewElement, viprWidget: viprWidget, selector: '.Legend li' }) //however these features only work with selectors (at the moment) }; } }; /** * given a searchTuple of captions, return points in the visualization that match. * @param searchTuple - an array of captions to match eg: ['2004', 'Friday'] for dataPoint which is the intersection of Year and Release Day. * @param [options] * @param [options.axis] - return axis matches (eg: for bar charts) * @param [options.legend] - return legend matches * @param [options.data] - return data point matches * @returns an object with the match (or null). */ ViprUITest.prototype.findPoint = function findPoint(searchTuple, options) { this._initLocators(); if (!options) { options = { axis: true, legend: true, data: true }; } var locatorKeys = Object.keys(this.locators); for (var i = 0; i < locatorKeys.length; i++) { var locatorKey = locatorKeys[i]; if (options[locatorKey]) { var locator = this.locators[locatorKey]; var results = locator.findTupleVisualInfo({ tuple: searchTuple }, { includePoints: true }); if (results.length) { return results[0].point; } } } }; /** * Take a 'snapshot' of the visualization which includes the tuples which are part of the visualization * and their selection state. * @param filter - (optional) - if specified, only the itemInfo which matches the filter are returned. eg: { isSelected: true } */ ViprUITest.prototype.takeSnapshot = function takeSnapshot(filter) { var _this = this; this._initLocators(); var results = {}; Object.keys(this.locators).forEach(function (locatorKey) { return results[locatorKey + 'Points'] = _this.locators[locatorKey].findTupleVisualInfo(filter, { includeInfo: true }).map(function (_ref) { var info = _ref.info; return info; }); }); return results; }; return ViprUITest; }(); return ViprUITest; }); //# sourceMappingURL=ViprUITest.js.map