Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NNS1-3486: period filter for reporting transactions #6032

Merged
merged 8 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]];
yhabib marked this conversation as resolved.
Show resolved Hide resolved
expect(currentValue).toBe("last-year");
yhabib marked this conversation as resolved.
Show resolved Hide resolved
});
});
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
Loading