UNPKG

@hisptz/react-ui

Version:

A collection of reusable complex DHIS2 react ui components.

112 lines (104 loc) 3.78 kB
"use strict"; var _react = require("@cypress/react"); var _react2 = _interopRequireDefault(require("react")); var _index = _interopRequireDefault(require("./index")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } describe("Period Selector Tests", () => { it("Renders", () => { (0, _react.mount)( /*#__PURE__*/_react2.default.createElement(_index.default, { onSelect: () => { return; }, selectedPeriods: [] })); }); it("should exclude fixed periods", function () { (0, _react.mount)( /*#__PURE__*/_react2.default.createElement(_index.default, { selectedPeriods: [], onSelect: () => { return; }, excludeFixedPeriods: true })); cy.get('[data-test="relative-tab"]').should("be.visible"); cy.get('[data-test="fixed-tab"]').should("not.exist"); }); it("should exclude relative periods", function () { (0, _react.mount)( /*#__PURE__*/_react2.default.createElement(_index.default, { selectedPeriods: [], onSelect: () => { return; }, excludeRelativePeriods: true })); cy.get('[data-test="fixed-tab"]').should("be.visible"); cy.get('[data-test="relative-tab"]').should("not.exist"); }); it("should throw an error if both fixed and relative periods are excluded", function () { expect(() => (0, _react.mount)( /*#__PURE__*/_react2.default.createElement(_index.default, { selectedPeriods: [], onSelect: () => { return; }, excludeRelativePeriods: true, excludeFixedPeriods: true }))).to.throw; }); it("should not have the period types specified in the excludedPeriodTypes array", function () { const excludedPeriodTypes = ["Weekly", "Monthly"]; (0, _react.mount)( /*#__PURE__*/_react2.default.createElement(_index.default, { selectedPeriods: [], onSelect: () => { return; }, excludedPeriodTypes: excludedPeriodTypes })); cy.get('[data-test="fixed-tab"]').click(); cy.get('[data-test="fixed-period-type-selector"]').click(); cy.get('[data-test="Weekly-type"]').should("not.exist"); cy.get('[data-test="Monthly-type"]').should("not.exist"); cy.get('[data-test="Yearly-type"]').should("exist"); }); it("should list on periods of the selected type", function () { (0, _react.mount)( /*#__PURE__*/_react2.default.createElement(_index.default, { selectedPeriods: [], onSelect: () => { return; } })); cy.get('[data-test="fixed-tab"]').click(); cy.get('[data-test="fixed-period-type-selector"]').click(); cy.get('[data-test="Yearly-type"]').click({ force: true }); const previousYears = Array.from({ length: 9 }, (_, i) => new Date().getFullYear() - (i + 1)); previousYears.forEach(prevYear => { const identifier = "data-test=\"".concat(prevYear, "-option\""); cy.get("[".concat(identifier, "]")).should("exist"); }); }); it("should return a selected period", function () { let selectedPeriod; const onSelect = _ref => { let { items } = _ref; selectedPeriod = items[0]; }; (0, _react.mount)( /*#__PURE__*/_react2.default.createElement(_index.default, { selectedPeriods: [], onSelect: onSelect })); cy.get('[data-test="fixed-tab"]').click(); cy.get('[data-test="fixed-period-type-selector"]').click(); cy.get('[data-test="Yearly-type"]').click({ force: true }); cy.get('[data-test="2020-option"]').dblclick().then(() => { var _selectedPeriod; expect((_selectedPeriod = selectedPeriod) === null || _selectedPeriod === void 0 ? void 0 : _selectedPeriod.id).to.equal("2020"); }); }); });