-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NNS1-3486: period filter for reporting transactions (#6032)
# Motivation We want users to be able to generate three types of reports: * full history * year-to-date * last year https://qsgjb-riaaa-aaaaa-aaaga-cai.yhabib-ingress.devenv.dfinity.network/reporting/ # Changes * Adds `period` state to `ReportingTransactions`. It binds it to `ReportingDateRangeSelector` so it can be updated, and it passes it down to `ReportingTransactionsButton` to be used when generating the report. # Tests * Unit tests for `ReportingTransactions` # Todos - [x] Add entry to changelog (if necessary).
- Loading branch information
Showing
7 changed files
with
220 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
frontend/src/lib/components/reporting/ReportingTransactions.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
frontend/src/tests/lib/components/reporting/ReportingTransactions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import * as governanceApi from "$lib/api/governance.api"; | ||
import * as icpIndexApi from "$lib/api/icp-index.api"; | ||
import ReportingTransactions from "$lib/components/reporting/ReportingTransactions.svelte"; | ||
import * as exportDataService from "$lib/services/reporting.services"; | ||
import * as exportToCsv from "$lib/utils/reporting.utils"; | ||
import { mockIdentity, resetIdentity } from "$tests/mocks/auth.store.mock"; | ||
import { | ||
mockAccountsStoreData, | ||
mockMainAccount, | ||
} from "$tests/mocks/icp-accounts.store.mock"; | ||
import { ReportingTransactionsPo } from "$tests/page-objects/ReportingTransactions.page-object"; | ||
import { JestPageObjectElement } from "$tests/page-objects/jest.page-object"; | ||
import { | ||
resetAccountsForTesting, | ||
setAccountsForTesting, | ||
} from "$tests/utils/accounts.test-utils"; | ||
import { render } from "@testing-library/svelte"; | ||
|
||
vi.mock("$lib/api/icp-ledger.api"); | ||
vi.mock("$lib/api/governance.api"); | ||
|
||
describe("ReportingTransactions", () => { | ||
let getAccountTransactionsConcurrently; | ||
|
||
const renderComponent = () => { | ||
const { container } = render(ReportingTransactions); | ||
|
||
const po = ReportingTransactionsPo.under({ | ||
element: new JestPageObjectElement(container), | ||
}); | ||
return po; | ||
}; | ||
|
||
beforeEach(() => { | ||
vi.clearAllTimers(); | ||
resetIdentity(); | ||
resetAccountsForTesting(); | ||
|
||
vi.spyOn(exportToCsv, "generateCsvFileToSave").mockImplementation(() => | ||
Promise.resolve() | ||
); | ||
vi.spyOn(governanceApi, "queryNeurons").mockResolvedValue([]); | ||
vi.spyOn(console, "error").mockImplementation(() => {}); | ||
vi.spyOn(icpIndexApi, "getTransactions").mockResolvedValue({ | ||
transactions: [], | ||
balance: 0n, | ||
oldestTxId: 1n, | ||
}); | ||
|
||
const mockDate = new Date("2023-10-14T00:00:00Z"); | ||
vi.useFakeTimers(); | ||
vi.setSystemTime(mockDate); | ||
|
||
setAccountsForTesting({ | ||
...mockAccountsStoreData, | ||
}); | ||
|
||
getAccountTransactionsConcurrently = vi.spyOn( | ||
exportDataService, | ||
"getAccountTransactionsConcurrently" | ||
); | ||
}); | ||
|
||
it("should fetch all transactions by default", async () => { | ||
const po = renderComponent(); | ||
await po.getReportingTransactionsButtonPo().click(); | ||
|
||
expect(getAccountTransactionsConcurrently).toHaveBeenCalledTimes(1); | ||
expect(getAccountTransactionsConcurrently).toHaveBeenCalledWith({ | ||
entities: [mockMainAccount], | ||
identity: mockIdentity, | ||
range: {}, | ||
}); | ||
}); | ||
|
||
it("should fetch year-to-date transactions when selecting such option", async () => { | ||
const beginningOfYear = new Date("2023-01-01T00:00:00Z"); | ||
const NANOS_IN_MS = BigInt(1_000_000); | ||
const beginningOfYearInNanoseconds = | ||
BigInt(beginningOfYear.getTime()) * NANOS_IN_MS; | ||
|
||
const po = renderComponent(); | ||
await po | ||
.getReportingDateRangeSelectorPo() | ||
.selectProvidedOption("year-to-date"); | ||
await po.getReportingTransactionsButtonPo().click(); | ||
|
||
expect(getAccountTransactionsConcurrently).toHaveBeenCalledTimes(1); | ||
expect(getAccountTransactionsConcurrently).toHaveBeenCalledWith({ | ||
entities: [mockMainAccount], | ||
identity: mockIdentity, | ||
range: { | ||
from: beginningOfYearInNanoseconds, | ||
}, | ||
}); | ||
}); | ||
|
||
it("should fetch last-year transactions when selecting such option", async () => { | ||
const beginningOfYear = new Date("2023-01-01T00:00:00Z"); | ||
const beginningOfLastYear = new Date("2022-01-01T00:00:00Z"); | ||
const NANOS_IN_MS = BigInt(1_000_000); | ||
const beginningOfYearInNanoseconds = | ||
BigInt(beginningOfYear.getTime()) * NANOS_IN_MS; | ||
|
||
const beginningOfLastYearInNanoseconds = | ||
BigInt(beginningOfLastYear.getTime()) * NANOS_IN_MS; | ||
|
||
const po = renderComponent(); | ||
await po | ||
.getReportingDateRangeSelectorPo() | ||
.selectProvidedOption("last-year"); | ||
await po.getReportingTransactionsButtonPo().click(); | ||
|
||
expect(getAccountTransactionsConcurrently).toHaveBeenCalledTimes(1); | ||
expect(getAccountTransactionsConcurrently).toHaveBeenCalledWith({ | ||
entities: [mockMainAccount], | ||
identity: mockIdentity, | ||
range: { | ||
from: beginningOfLastYearInNanoseconds, | ||
to: beginningOfYearInNanoseconds, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
frontend/src/tests/page-objects/ReportingTransactions.page-object.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { PageObjectElement } from "$tests/types/page-object.types"; | ||
import { ReportingDateRangeSelectorPo } from "./ReportingDateRangeSelector.page-object"; | ||
import { ReportingTransactionsButtonPo } from "./ReportingTransactionsButton.page-object"; | ||
import { BasePageObject } from "./base.page-object"; | ||
|
||
export class ReportingTransactionsPo extends BasePageObject { | ||
static readonly TID = "reporting-transactions-component"; | ||
|
||
static under({ | ||
element, | ||
}: { | ||
element: PageObjectElement; | ||
}): ReportingTransactionsPo { | ||
return new ReportingTransactionsPo( | ||
element.byTestId(ReportingTransactionsPo.TID) | ||
); | ||
} | ||
|
||
getReportingDateRangeSelectorPo() { | ||
return ReportingDateRangeSelectorPo.under({ | ||
element: this.root, | ||
}); | ||
} | ||
|
||
getReportingTransactionsButtonPo() { | ||
return ReportingTransactionsButtonPo.under({ | ||
element: this.root, | ||
}); | ||
} | ||
} |