ViprUITest.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: Dashboard
  7. *| (C) Copyright IBM Corp. 2018, 2020
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or disclosure
  10. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. define(['underscore', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', './api/ViprUITestApi', './BinarySearchTupleLocator', './SelectorTupleLocator'], function (_, APIFactory, ViprUITestAPI, BinarySearchTupleLocator, SelectorTupleLocator) {
  14. /**
  15. * The ViprUITest is a support class for the functional Test UI.
  16. * Its purpose is to allow the test framework to check and interact with a visualization from an external point of view.
  17. * In the case of VIPR, we assume that VIPR "does the right thing" and checking its structures via getItemsAtPoint/getItemsInPolygon is sufficient.
  18. * The hope is to have VIPR implement an interface and this class will simply adapt to the UITestAPI interface and not use private information.
  19. */
  20. var ViprUITest = function () {
  21. function ViprUITest(options) {
  22. _classCallCheck(this, ViprUITest);
  23. this.content = options.content;
  24. }
  25. ViprUITest.prototype.getAPI = function getAPI() {
  26. if (!this._api) {
  27. this._api = APIFactory.createAPI(this, [ViprUITestAPI]);
  28. }
  29. return this._api;
  30. };
  31. ViprUITest.prototype._initLocators = function _initLocators() {
  32. if (!this.locators) {
  33. var viprView = this.content.getFeature('livewidget.internal').getVisView();
  34. var viprWidget = viprView.viprWidget;
  35. var viprViewElement = viprView.$el;
  36. this.locators = {
  37. data: new BinarySearchTupleLocator({ viprWidget: viprWidget }), //Most test logic will want this one
  38. axis: new SelectorTupleLocator({ '$el': viprViewElement, viprWidget: viprWidget, selector: '.axis-label' }), //Most cases won't need selectors like these
  39. legend: new SelectorTupleLocator({ '$el': viprViewElement, viprWidget: viprWidget, selector: '.Legend li' }) //however these features only work with selectors (at the moment)
  40. };
  41. }
  42. };
  43. /**
  44. * given a searchTuple of captions, return points in the visualization that match.
  45. * @param searchTuple - an array of captions to match eg: ['2004', 'Friday'] for dataPoint which is the intersection of Year and Release Day.
  46. * @param [options]
  47. * @param [options.axis] - return axis matches (eg: for bar charts)
  48. * @param [options.legend] - return legend matches
  49. * @param [options.data] - return data point matches
  50. * @returns an object with the match (or null).
  51. */
  52. ViprUITest.prototype.findPoint = function findPoint(searchTuple, options) {
  53. this._initLocators();
  54. if (!options) {
  55. options = {
  56. axis: true,
  57. legend: true,
  58. data: true
  59. };
  60. }
  61. var locatorKeys = Object.keys(this.locators);
  62. for (var i = 0; i < locatorKeys.length; i++) {
  63. var locatorKey = locatorKeys[i];
  64. if (options[locatorKey]) {
  65. var locator = this.locators[locatorKey];
  66. var results = locator.findTupleVisualInfo({ tuple: searchTuple }, { includePoints: true });
  67. if (results.length) {
  68. return results[0].point;
  69. }
  70. }
  71. }
  72. };
  73. /**
  74. * Take a 'snapshot' of the visualization which includes the tuples which are part of the visualization
  75. * and their selection state.
  76. * @param filter - (optional) - if specified, only the itemInfo which matches the filter are returned. eg: { isSelected: true }
  77. */
  78. ViprUITest.prototype.takeSnapshot = function takeSnapshot(filter) {
  79. var _this = this;
  80. this._initLocators();
  81. var results = {};
  82. Object.keys(this.locators).forEach(function (locatorKey) {
  83. return results[locatorKey + 'Points'] = _this.locators[locatorKey].findTupleVisualInfo(filter, { includeInfo: true }).map(function (_ref) {
  84. var info = _ref.info;
  85. return info;
  86. });
  87. });
  88. return results;
  89. };
  90. return ViprUITest;
  91. }();
  92. return ViprUITest;
  93. });
  94. //# sourceMappingURL=ViprUITest.js.map