UNPKG

@hisptz/react-ui

Version:

A collection of reusable complex DHIS2 react ui components.

105 lines (102 loc) 3.46 kB
import { mount } from "@cypress/react"; import React from "react"; import PeriodSelector from "./index"; describe("Period Selector Tests", () => { it("Renders", () => { mount( /*#__PURE__*/React.createElement(PeriodSelector, { onSelect: () => { return; }, selectedPeriods: [] })); }); it("should exclude fixed periods", function () { mount( /*#__PURE__*/React.createElement(PeriodSelector, { 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 () { mount( /*#__PURE__*/React.createElement(PeriodSelector, { 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(() => mount( /*#__PURE__*/React.createElement(PeriodSelector, { 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"]; mount( /*#__PURE__*/React.createElement(PeriodSelector, { 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 () { mount( /*#__PURE__*/React.createElement(PeriodSelector, { 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]; }; mount( /*#__PURE__*/React.createElement(PeriodSelector, { 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"); }); }); });