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 581b2a0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
label: $i18n.reporting.timestamp,
},
];
const fileName = `icp_transactions_export_${period}_${formatDateCompact(new Date())}`;
const fileName = `icp_transactions_export_${formatDateCompact(new Date())}`;
await generateCsvFileToSave({
datasets,
Expand Down
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 renderComponent = (
{
period,
}: {
period?: ReportingPeriod;
} = { period: "all" }
) => {
const { container, component } = render(ReportingDateRangeSelector, {
period,
});

const po = ReportingDateRangeSelectorPo.under({
element: new JestPageObjectElement(container),
});

return po;
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 @@ -102,7 +102,7 @@ describe("ReportingTransactionsButton", () => {
await po.click();
await runResolvedPromises();

const expectedFileName = `icp_transactions_export_all_20231014`;
const expectedFileName = `icp_transactions_export_20231014`;
expect(spyGenerateCsvFileToSave).toHaveBeenCalledWith(
expect.objectContaining({
fileName: expectedFileName,
Expand Down Expand Up @@ -261,13 +261,6 @@ describe("ReportingTransactionsButton", () => {
await po.click();
await runResolvedPromises();

const expectedFileName = `icp_transactions_export_year-to-date_20231014`;
expect(spyGenerateCsvFileToSave).toHaveBeenCalledWith(
expect.objectContaining({
fileName: expectedFileName,
})
);

const expectation = [mockMainAccount, mockNeuron];
expect(spyQueryNeurons).toBeCalledTimes(1);
expect(spyExportDataService).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit 581b2a0

Please sign in to comment.