Skip to content

Commit

Permalink
feat: actional proposals segment store (dfinity#4608)
Browse files Browse the repository at this point in the history
# 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
mstrasinskis authored Mar 11, 2024
1 parent 9c5f26e commit 19f633d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
39 changes: 39 additions & 0 deletions frontend/src/lib/stores/actionable-proposals-segment.store.ts
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();
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");
});
});

0 comments on commit 19f633d

Please sign in to comment.