Skip to content

Commit c2783a2

Browse files
authored
Sort follow neuron topics (#6408)
# Motivation To improve the user experience, proposal topics need to be displayed in a sorted order ([the ticket](https://dfinity.atlassian.net/browse/NNS1-3491)). This applies to the topic filter and the follow neuron topic list. In this PR, we address the follow neurons modal. **Expected order:** 1. Governance. 2. SNS & Neurons' Fund. 3. All Except Governance, and SNS & Neurons' Fund. 4. Rest topics (ExchangeRate included) sorted alphabetically. # Changes - Display topics in a specific order. # Tests - Added. # Todos - [ ] Add entry to changelog (if necessary). Not necessary.
1 parent ca8e845 commit c2783a2

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

frontend/src/lib/components/neurons/EditFollowNeurons.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { topicsToFollow } from "$lib/utils/neuron.utils";
88
import type { NeuronId, NeuronInfo, Topic } from "@dfinity/nns";
99
import { onMount } from "svelte";
10+
import { sortNnsTopics } from "$lib/utils/proposals.utils";
1011
1112
export let neuronId: NeuronId;
1213
@@ -16,8 +17,10 @@
1617
// Load KnownNeurons which are used in the FollowNnsTopicSections
1718
onMount(() => listKnownNeurons());
1819
19-
let topics: Topic[];
20-
$: topics = neuron ? topicsToFollow(neuron) : [];
20+
let sortedTopics: Topic[];
21+
$: sortedTopics = neuron
22+
? sortNnsTopics({ topics: topicsToFollow(neuron), i18n: $i18n })
23+
: [];
2124
</script>
2225

2326
{#if neuron !== undefined}
@@ -26,7 +29,7 @@
2629

2730
<Separator spacing="medium" />
2831

29-
{#each topics as topic}
32+
{#each sortedTopics as topic}
3033
<FollowNnsTopicSection {neuron} {topic} />
3134
{/each}
3235
</div>

frontend/src/lib/components/neurons/FollowTopicSection.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<article data-tid={`follow-topic-${id}-section`}>
1616
<Collapsible {id} iconSize="medium" testId="collapsible">
1717
<div class="wrapper" slot="header">
18-
<span class="value"><slot name="title" /></span>
18+
<span class="value" data-tid="topic-title"><slot name="title" /></span>
1919
<span class="badge" data-tid={`topic-${id}-followees-badge`}>
2020
{count}
2121
</span>

frontend/src/tests/lib/components/neurons/EditFollowNeurons.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as governanceApi from "$lib/api/governance.api";
22
import EditFollowNeurons from "$lib/components/neurons/EditFollowNeurons.svelte";
3+
import { DEPRECATED_TOPICS } from "$lib/constants/proposals.constants";
34
import { neuronsStore } from "$lib/stores/neurons.store";
5+
import { enumValues } from "$lib/utils/enum.utils";
46
import { resetIdentity } from "$tests/mocks/auth.store.mock";
57
import { mockFullNeuron, mockNeuron } from "$tests/mocks/neurons.mock";
68
import { EditFollowNeuronsPo } from "$tests/page-objects/EditFollowNeurons.page-object";
@@ -50,6 +52,37 @@ describe("EditFollowNeurons", () => {
5052
expect(await po.getBadgeNumber(Topic.Governance)).toBe(0);
5153
});
5254

55+
it("renders topics in specific order", async () => {
56+
const po = renderComponent();
57+
const sectionTitles = await po.getFollowNnsTopicTitles();
58+
59+
// Deprecated + NeuronManagement (because it's not public)
60+
const hiddenTopicCount = DEPRECATED_TOPICS.length + 1;
61+
expect(sectionTitles.length).toBe(
62+
enumValues(Topic).length - hiddenTopicCount
63+
);
64+
65+
expect(sectionTitles).toEqual([
66+
"Governance",
67+
"SNS & Neurons' Fund",
68+
"All Except Governance, and SNS & Neurons' Fund",
69+
"API Boundary Node Management",
70+
"Application Canister Management",
71+
"Exchange Rate",
72+
"IC OS Version Deployment",
73+
"IC OS Version Election",
74+
"KYC",
75+
"Network Economics",
76+
"Node Admin",
77+
"Node Provider Rewards",
78+
"Participant Management",
79+
"Protocol Canister Management",
80+
"Service Nervous System Management",
81+
"Subnet Management",
82+
"Subnet Rental",
83+
]);
84+
});
85+
5386
it("displays the followees of the user in specific topic", async () => {
5487
const po = renderComponent();
5588
const topicSectionPo = await po.getFollowTopicSectionPo(Topic.ExchangeRate);

frontend/src/tests/page-objects/EditFollowNeurons.page-object.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ export class EditFollowNeuronsPo extends BasePageObject {
1414
return FollowNnsTopicSectionPo.allUnder(this.root);
1515
}
1616

17+
async getFollowNnsTopicTitles(): Promise<string[]> {
18+
const topicSectionPos = await this.getFollowNnsTopicSectionPos();
19+
return Promise.all(
20+
topicSectionPos.map(async (po) =>
21+
(await po.getFollowTopicSectionPo()).getTopicTitle()
22+
)
23+
);
24+
}
25+
1726
getFollowTopicSectionPo(topic: number): FollowTopicSectionPo {
1827
return FollowTopicSectionPo.under({
1928
element: this.root,

frontend/src/tests/page-objects/FollowTopicSection.page-object.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class FollowTopicSectionPo extends BasePageObject {
4141
return this.getButton("open-new-followee-modal");
4242
}
4343

44+
getTopicTitle(): Promise<string> {
45+
return this.getText("topic-title");
46+
}
47+
4448
async getBadgeNumber(): Promise<number> {
4549
return Number(await this.getText(`topic-${this.topic}-followees-badge`));
4650
}

0 commit comments

Comments
 (0)