Skip to content

Commit

Permalink
NNS1-3485: new LinkToReporting component (#5965)
Browse files Browse the repository at this point in the history
# Motivation

The new reporting page will be accessible through the `AccountMenu`.
This component, which is behind a feature flag, redirects users to this
page as long as they are logged in.

Deployed
[here](https://qsgjb-riaaa-aaaaa-aaaga-cai.yhabib-ingress.devenv.dfinity.network/reporting/)

# Changes

- New `LinkToReporting` component
- Added new component to the `AccountMenu`

# Tests

- Unit tests for the component within the `AccountMenu`

# Todos

- [ ] Add entry to changelog (if necessary).
Not necessary

Prev. PR: #5964
  • Loading branch information
yhabib authored Dec 10, 2024
1 parent 403de48 commit fc24286
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
3 changes: 3 additions & 0 deletions frontend/src/lib/components/header/AccountMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import Logout from "./Logout.svelte";
import { IconUser, Popover } from "@dfinity/gix-components";
import ExportIcpTransactionsButton from "$lib/components/header/ExportIcpTransactionsButton.svelte";
import LinkToReporting from "$lib/components/header/LinkToReporting.svelte";
let visible = false;
let button: HTMLButtonElement | undefined;
Expand Down Expand Up @@ -43,6 +44,8 @@
<LinkToCanisters on:nnsLink={closeMenu} />

{#if $ENABLE_EXPORT_NEURONS_REPORT}
<LinkToReporting on:nnsLink={closeMenu} />

<ExportNeuronsButton on:nnsExportNeuronsCsvTriggered={toggle} />

<ExportIcpTransactionsButton
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/lib/components/header/LinkToReporting.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script lang="ts">
import { beforeNavigate } from "$app/navigation";
import { i18n } from "$lib/stores/i18n";
import { IconDocument } from "@dfinity/gix-components";
import { createEventDispatcher } from "svelte";
const dispatcher = createEventDispatcher();
const linkToReporting = "/reporting";
beforeNavigate(() => dispatcher("nnsLink"));
</script>

<a data-tid="reporting" href={linkToReporting} class="text">
<IconDocument />
{$i18n.navigation.reporting}
</a>

<style lang="scss">
@use "../../themes/mixins/account-menu";
a {
@include account-menu.button;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
</style>
45 changes: 43 additions & 2 deletions frontend/src/tests/lib/components/header/AccountMenu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ describe("AccountMenu", () => {
);
const canistersLinkPo = accountMenuPo.getCanistersLinkPo();
const linkToSettingsPo = accountMenuPo.getLinkToSettingsPo();
const linkToReportingPo = accountMenuPo.getLinkToReportingPo();

canistersLinkPo.root.addEventListener("click", mockLinkClickEvent);
linkToSettingsPo.root.addEventListener("click", mockLinkClickEvent);

return { accountMenuPo, canistersLinkPo, linkToSettingsPo };
linkToReportingPo.root.addEventListener("click", mockLinkClickEvent);

return {
accountMenuPo,
canistersLinkPo,
linkToSettingsPo,
linkToReportingPo,
};
};

it("should be closed by default", async () => {
Expand Down Expand Up @@ -196,6 +203,40 @@ describe("AccountMenu", () => {
expect(await accountMenuPo.isOpen()).toBe(false);
});
});

it("should not show the LinkToReporting button if feature flag is off(by default", async () => {
const { accountMenuPo } = renderComponent();
await accountMenuPo.openMenu();

expect(await accountMenuPo.getLinkToReportingPo().isPresent()).toBe(
false
);
});

it("should display Reporting button link", async () => {
overrideFeatureFlagsStore.setFlag("ENABLE_EXPORT_NEURONS_REPORT", true);

const { accountMenuPo } = renderComponent();
await accountMenuPo.openMenu();

expect(await accountMenuPo.getLinkToReportingPo().isPresent()).toBe(
true
);
});

it("should close popover on click on reporting", async () => {
overrideFeatureFlagsStore.setFlag("ENABLE_EXPORT_NEURONS_REPORT", true);

const { accountMenuPo, linkToReportingPo } = renderComponent();
await accountMenuPo.openMenu();

await linkToReportingPo.click();

//wait for goto to be triggered
await runResolvedPromises();

expect(await accountMenuPo.isOpen()).toBe(false);
});
});
});
});
7 changes: 7 additions & 0 deletions frontend/src/tests/page-objects/AccountMenu.page-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,11 @@ export class AccountMenuPo extends BasePageObject {
getExportIcpTransactionsButtonPo(): ExportIcpTransactionsButtonPo {
return ExportIcpTransactionsButtonPo.under({ element: this.root });
}

getLinkToReportingPo(): LinkPo {
return LinkPo.under({
element: this.root,
testId: "reporting",
});
}
}

0 comments on commit fc24286

Please sign in to comment.