diff --git a/frontend/src/lib/components/reporting/ReportingTransactionsButton.svelte b/frontend/src/lib/components/reporting/ReportingTransactionsButton.svelte index f281802c5ca..1e83feabdb6 100644 --- a/frontend/src/lib/components/reporting/ReportingTransactionsButton.svelte +++ b/frontend/src/lib/components/reporting/ReportingTransactionsButton.svelte @@ -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, diff --git a/frontend/src/tests/lib/components/reporting/ReportingDateRangeSelector.spec.ts b/frontend/src/tests/lib/components/reporting/ReportingDateRangeSelector.spec.ts index 05e1ecdc78a..eee9740281b 100644 --- a/frontend/src/tests/lib/components/reporting/ReportingDateRangeSelector.spec.ts +++ b/frontend/src/tests/lib/components/reporting/ReportingDateRangeSelector.spec.ts @@ -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]; @@ -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"); + }); }); diff --git a/frontend/src/tests/lib/components/reporting/ReportingTransactionsButton.spec.ts b/frontend/src/tests/lib/components/reporting/ReportingTransactionsButton.spec.ts index cf21c4f465d..35686e5c83f 100644 --- a/frontend/src/tests/lib/components/reporting/ReportingTransactionsButton.spec.ts +++ b/frontend/src/tests/lib/components/reporting/ReportingTransactionsButton.spec.ts @@ -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, @@ -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);