-
Cal Herries authored
* Limit session timeout amount to less than 1 million * Limit the max timeout to 100 years * Validate on BE too * Typo * Add comment to FE * Fix BE validation * Fix BE validation * Add BE test * Change FE validation to mirror BE validation * Add unit test for SessionTimeoutSetting * Refactor FE unit tests * Move comment * Add check for positive amount to BE validation * Add more BE tests * Refactor validate function * Remove cleanup() * Use ToBeInTheDocument instead * Use getByText * Remove conditional expect * Remove unused import * Refactor for clarity * Formatting * Validate session-timeout in getter too * Add docstring to check-session-timeout and make private * Change getter to print warning string instead of throw exception * Format import * i18n and use log/warn in getter, and throw 400 in setter * Reorder require * Use cam's suggestion Co-authored-by:
Cam Saul <1455846+camsaul@users.noreply.github.com> Co-authored-by:
Cam Saul <1455846+camsaul@users.noreply.github.com>
Cal Herries authored* Limit session timeout amount to less than 1 million * Limit the max timeout to 100 years * Validate on BE too * Typo * Add comment to FE * Fix BE validation * Fix BE validation * Add BE test * Change FE validation to mirror BE validation * Add unit test for SessionTimeoutSetting * Refactor FE unit tests * Move comment * Add check for positive amount to BE validation * Add more BE tests * Refactor validate function * Remove cleanup() * Use ToBeInTheDocument instead * Use getByText * Remove conditional expect * Remove unused import * Refactor for clarity * Formatting * Validate session-timeout in getter too * Add docstring to check-session-timeout and make private * Change getter to print warning string instead of throw exception * Format import * i18n and use log/warn in getter, and throw 400 in setter * Reorder require * Use cam's suggestion Co-authored-by:
Cam Saul <1455846+camsaul@users.noreply.github.com> Co-authored-by:
Cam Saul <1455846+camsaul@users.noreply.github.com>
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
SessionTimeoutSetting.unit.spec.tsx 1.73 KiB
import React from "react";
import { render, cleanup, screen } from "@testing-library/react";
import SessionTimeoutSetting from "metabase-enterprise/auth/components/SessionTimeoutSetting";
describe("SessionTimeoutSetting", () => {
beforeAll(() => {
window.HTMLElement.prototype.scrollIntoView = jest.fn();
});
const SUCCEED_TEST_CASES = [
{ value: { amount: 1, unit: "minutes" } },
{ value: { amount: 1, unit: "hours" } },
{ value: { amount: 60 * 24 * 365.25 * 100 - 1, unit: "minutes" } },
{ value: { amount: 24 * 365.25 * 100 - 1, unit: "hours" } },
];
const FAIL_TEST_CASES = [
{
value: { amount: 0, unit: "minutes" },
error: "Timeout must be greater than 0",
},
{
value: { amount: 0, unit: "hours" },
error: "Timeout must be greater than 0",
},
{
value: { amount: 60 * 24 * 365.25 * 100, unit: "minutes" },
error: "Timeout must be less than 100 years",
},
{
value: { amount: 24 * 365.25 * 100, unit: "hours" },
error: "Timeout must be less than 100 years",
},
];
SUCCEED_TEST_CASES.map(({ value }) => {
it(`validates ${value.amount} ${value.unit} correctly`, () => {
const setting = { value: value, key: "...", default: "..." };
render(<SessionTimeoutSetting setting={setting} onChange={jest.fn()} />);
expect(screen.queryByText(/Timeout must be/)).not.toBeInTheDocument();
});
});
FAIL_TEST_CASES.map(({ value, error }) => {
it(`validates ${value.amount} ${value.unit} correctly`, () => {
const setting = { value: value, key: "...", default: "..." };
render(<SessionTimeoutSetting setting={setting} onChange={jest.fn()} />);
expect(screen.getByText(error)).toBeInTheDocument();
});
});
});