| 1 | import { useMoodEntryStore } from "@/stores";
|
| 2 |
|
| 3 | const state = () => useMoodEntryStore.getState();
|
| 4 | const component = (id: string, intensity: number) => ({ id, intensity });
|
| 5 |
|
| 6 | beforeEach(() => {
|
| 7 | useMoodEntryStore.setState({ selectedMood: null, components: [] });
|
| 8 | });
|
| 9 |
|
| 10 | describe("setSelectedMood", () => {
|
| 11 | it("records the selected mood", () => {
|
| 12 | state().setSelectedMood("good");
|
| 13 |
|
| 14 | expect(state().selectedMood).toBe("good");
|
| 15 | });
|
| 16 | });
|
| 17 |
|
| 18 | describe("setComponents", () => {
|
| 19 | it("replaces the whole component list at once", () => {
|
| 20 | state().setComponents([component("joy", 3), component("calm", 2)]);
|
| 21 |
|
| 22 | expect(state().components).toStrictEqual([
|
| 23 | component("joy", 3),
|
| 24 | component("calm", 2),
|
| 25 | ]);
|
| 26 | });
|
| 27 | });
|
| 28 |
|
| 29 | describe("addComponent", () => {
|
| 30 | it("appends with the default intensity", () => {
|
| 31 | state().addComponent("joy");
|
| 32 |
|
| 33 | expect(state().components).toStrictEqual([component("joy", 1)]);
|
| 34 | });
|
| 35 |
|
| 36 | it("keeps the order the components were added in", () => {
|
| 37 | state().addComponent("joy");
|
| 38 | state().addComponent("calm");
|
| 39 |
|
| 40 | expect(state().components).toStrictEqual([
|
| 41 | component("joy", 1),
|
| 42 | component("calm", 1),
|
| 43 | ]);
|
| 44 | });
|
| 45 |
|
| 46 | it("ignores a re-add, keeping the intensity already set", () => {
|
| 47 | state().addComponent("joy");
|
| 48 | state().setComponentIntensity("joy", 3);
|
| 49 |
|
| 50 | state().addComponent("joy");
|
| 51 |
|
| 52 | expect(state().components).toStrictEqual([component("joy", 3)]);
|
| 53 | });
|
| 54 | });
|
| 55 |
|
| 56 | describe("removeComponent", () => {
|
| 57 | it("drops the component and leaves the rest", () => {
|
| 58 | state().setComponents([component("joy", 1), component("calm", 2)]);
|
| 59 |
|
| 60 | state().removeComponent("joy");
|
| 61 |
|
| 62 | expect(state().components).toStrictEqual([component("calm", 2)]);
|
| 63 | });
|
| 64 | });
|
| 65 |
|
| 66 | describe("setComponentIntensity", () => {
|
| 67 | it("changes only the target component", () => {
|
| 68 | state().setComponents([component("joy", 2), component("calm", 1)]);
|
| 69 |
|
| 70 | state().setComponentIntensity("calm", 3);
|
| 71 |
|
| 72 | expect(state().components).toStrictEqual([
|
| 73 | component("joy", 2),
|
| 74 | component("calm", 3),
|
| 75 | ]);
|
| 76 | });
|
| 77 | });
|
| 78 |
|
| 79 | describe("reset", () => {
|
| 80 | it("clears the mood and the component list", () => {
|
| 81 | state().setSelectedMood("good");
|
| 82 | state().addComponent("joy");
|
| 83 |
|
| 84 | state().reset();
|
| 85 |
|
| 86 | expect(state().selectedMood).toBeNull();
|
| 87 | expect(state().components).toStrictEqual([]);
|
| 88 | });
|
| 89 | });
|