@octopusdeploy/design-system-components
Version:
The design systems component library.
91 lines (90 loc) • 3.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const testing_library_1 = require("@octopusdeploy/testing-library");
const react_1 = require("@testing-library/react");
const vitest_1 = require("vitest");
const DeprecatedSwitch_1 = require("../DeprecatedSwitch");
(0, vitest_1.describe)("DeprecatedSwitch", () => {
(0, vitest_1.it)("should be checked when the value is true", () => {
const DeprecatedSwitch = renderSwitch({
value: true,
});
DeprecatedSwitch.shouldBeChecked();
});
(0, vitest_1.it)("should not be checked when the value is false", () => {
const DeprecatedSwitch = renderSwitch({
value: false,
});
DeprecatedSwitch.shouldNotBeChecked();
});
(0, vitest_1.it)("should show the label", () => {
const DeprecatedSwitch = renderSwitch({
value: false,
label: "The label",
});
DeprecatedSwitch.shouldHaveText("The label");
});
(0, vitest_1.it)("should be focused when autoFocus is on", () => {
const DeprecatedSwitch = renderSwitch({
value: false,
autoFocus: true,
});
DeprecatedSwitch.shouldHaveFocus();
});
(0, vitest_1.it)("should be enabled when disabled is false", () => {
const DeprecatedSwitch = renderSwitch({
value: false,
disabled: false,
});
DeprecatedSwitch.shouldBeEnabled();
});
(0, vitest_1.it)("should be disabled when disabled is true", () => {
const DeprecatedSwitch = renderSwitch({
value: false,
disabled: true,
});
DeprecatedSwitch.shouldBeDisabled();
});
(0, vitest_1.it)("should run onChange callback with the new value when toggled", async () => {
const DeprecatedSwitch = renderSwitch({
value: false,
});
await DeprecatedSwitch.toggle();
DeprecatedSwitch.shouldHaveCalledOnChangeWith(true);
});
});
const SwitchName = "Switch";
function renderSwitch({ value, title, autoFocus, note, disabled, label }) {
const onChange = vitest_1.vi.fn();
(0, react_1.render)((0, jsx_runtime_1.jsx)(DeprecatedSwitch_1.DeprecatedSwitch, { value: value, onChange: onChange, autoFocus: autoFocus, disabled: disabled, label: label, accessibleName: SwitchName }));
return getActionButtonInteractions(onChange);
}
function getActionButtonInteractions(onChange) {
return {
toggle: async () => {
await testing_library_1.domQueries.getCheckbox(SwitchName).toggle();
},
shouldHaveCalledOnChangeWith: (value) => {
(0, vitest_1.expect)(onChange).toHaveBeenCalledWith(value);
},
shouldBeChecked: () => {
(0, vitest_1.expect)(testing_library_1.domQueries.getCheckbox(SwitchName).isChecked).toBe(true);
},
shouldNotBeChecked: () => {
(0, vitest_1.expect)(testing_library_1.domQueries.getCheckbox(SwitchName).isChecked).toBe(false);
},
shouldHaveText: (text) => {
(0, vitest_1.expect)(react_1.screen.getByText(text)).toBeInTheDocument();
},
shouldHaveFocus: () => {
testing_library_1.domQueries.getCheckbox(SwitchName).assertHasFocus();
},
shouldBeEnabled: () => {
testing_library_1.domQueries.getCheckbox(SwitchName).assertIsEnabled();
},
shouldBeDisabled: () => {
testing_library_1.domQueries.getCheckbox(SwitchName).assertIsDisabled();
},
};
}