Skip to content

Commit

Permalink
car
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabib committed Dec 18, 2024
1 parent db44c51 commit d5dfce2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
import ReportingDateRangeSelector from "$lib/components/reporting/ReportingDateRangeSelector.svelte";
import type { ReportingPeriod } from "$lib/types/reporting";
import { JestPageObjectElement } from "$tests/page-objects/jest.page-object";
import { ReportingDateRangeSelectorPo } from "$tests/page-objects/ReportingDateRangeSelector.page-object";
import { render } from "@testing-library/svelte";
import { tick } from "svelte";

describe("ReportingDateRangeSelector", () => {
const renderComponent = () => {
const { container } = render(ReportingDateRangeSelector, { period: "all" });
const po = ReportingDateRangeSelectorPo.under({
element: new JestPageObjectElement(container),
const renderComponent = (
{
period,
}: {
period?: ReportingPeriod;
} = { period: "all" }
) => {
const { container, component } = render(ReportingDateRangeSelector, {
period,
});

return po;
const po = ReportingDateRangeSelectorPo.under(
new JestPageObjectElement(container)
);

return { po, component };
};

it("should render the option provided as a prop", async () => {
const { po } = renderComponent({ period: "last-year" });

const selectedOption = po.getSelectedOption();
expect(await selectedOption.getValue()).toBe("last-year");
});

it("should render three options", async () => {
const po = renderComponent();
const { po } = renderComponent();

expect(await po.getAllOptions()).toHaveLength(3);
});

it("should select 'all' option by default", async () => {
const po = renderComponent();
const { po } = renderComponent();

const selectedOption = po.getSelectedOption();
expect(await selectedOption.getValue()).toBe("all");
});

it("should change the option when interacting with a new element", async () => {
const po = renderComponent();
const { po } = renderComponent();
const allOptions = await po.getAllOptions();
const firstOptionValue = await allOptions[0].getValue();
const secondOption = allOptions[1];
Expand All @@ -41,4 +59,17 @@ describe("ReportingDateRangeSelector", () => {

expect(await currentOption.getValue()).toBe(await secondOption.getValue());
});

it("should update exported prop when selecting an option", async () => {
const { po, component } = renderComponent();
const allOptions = await po.getAllOptions();

// Click the second option
await allOptions[1].click();

await tick();

const currentValue = component.$$.ctx[component.$$.props["period"]];
expect(currentValue).toBe("last-year");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { SimpleBasePageObject } from "./simple-base.page-object";
export class ReportingDateRangeSelectorPo extends SimpleBasePageObject {
static readonly TID = "reporting-data-range-selector-component";

static under({
element,
}: {
element: PageObjectElement;
}): ReportingDateRangeSelectorPo {
static under(element: PageObjectElement): ReportingDateRangeSelectorPo {
return new ReportingDateRangeSelectorPo(
element.byTestId(ReportingDateRangeSelectorPo.TID)
);
Expand Down

0 comments on commit d5dfce2

Please sign in to comment.