forked from dfinity/nns-dapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: actional proposals segment store (dfinity#4608)
# Motivation Adds a new store to contain current selection state of "all"|"actionable" segment controller. Should be "all" be default, same for all projects and not preserved in the local storage. Will be used here dfinity#4591 # Changes - `actionableProposalsSegmentStore` # Tests - `actionableProposalsSegmentStore` # Todos - [ ] Add entry to changelog (if necessary). Not yet.
- Loading branch information
1 parent
9c5f26e
commit 19f633d
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
frontend/src/lib/stores/actionable-proposals-segment.store.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,39 @@ | ||
import { writable, type Readable } from "svelte/store"; | ||
|
||
export type ActionableSegmentSelection = "all" | "actionable"; | ||
|
||
export interface ActionableProposalsSegmentStoreData { | ||
selected: ActionableSegmentSelection; | ||
} | ||
|
||
export interface ActionableProposalsSegmentStore | ||
extends Readable<ActionableProposalsSegmentStoreData> { | ||
set: (selected: ActionableSegmentSelection) => void; | ||
resetForTesting: () => void; | ||
} | ||
|
||
/** | ||
* A store that contains selected state of actionable proposals segment. | ||
* By default, it's "all" and not stored in LocalStorage. | ||
*/ | ||
const initActionableProposalsSegmentStore = | ||
(): ActionableProposalsSegmentStore => { | ||
const { subscribe, set } = writable<ActionableProposalsSegmentStoreData>({ | ||
selected: "all", | ||
}); | ||
|
||
return { | ||
subscribe, | ||
|
||
set(selected: ActionableSegmentSelection) { | ||
set({ selected }); | ||
}, | ||
|
||
resetForTesting(): void { | ||
set({ selected: "all" }); | ||
}, | ||
}; | ||
}; | ||
|
||
export const actionableProposalsSegmentStore = | ||
initActionableProposalsSegmentStore(); |
20 changes: 20 additions & 0 deletions
20
frontend/src/tests/lib/stores/actionable-proposals-segment.store.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,20 @@ | ||
import { actionableProposalsSegmentStore } from "$lib/stores/actionable-proposals-segment.store"; | ||
import { get } from "svelte/store"; | ||
|
||
describe("actionable proposals segment store", () => { | ||
beforeEach(() => { | ||
actionableProposalsSegmentStore.resetForTesting(); | ||
}); | ||
|
||
it('should have "all" by default ', () => { | ||
expect(get(actionableProposalsSegmentStore).selected).toEqual("all"); | ||
}); | ||
|
||
it("should set selected", () => { | ||
actionableProposalsSegmentStore.set("actionable"); | ||
expect(get(actionableProposalsSegmentStore).selected).toEqual("actionable"); | ||
|
||
actionableProposalsSegmentStore.set("all"); | ||
expect(get(actionableProposalsSegmentStore).selected).toEqual("all"); | ||
}); | ||
}); |