Skip to content

Commit d583a46

Browse files
committed
♻️ Add reset() and tests (#1845)
1 parent 3768309 commit d583a46

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/lib/stores/active_contest_type.svelte.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ export class ActiveContestTypeStore {
5050
isSame(contestType: ContestTableProviders): boolean {
5151
return this.value === contestType;
5252
}
53+
54+
/**
55+
* Resets the active contest type to the default value.
56+
* Sets the internal value to 'abcLatest20Rounds'.
57+
*/
58+
reset(): void {
59+
this.value = 'abcLatest20Rounds';
60+
}
5361
}
5462

5563
export const activeContestTypeStore = new ActiveContestTypeStore();

src/test/lib/stores/active_contest_type.svelte.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,21 @@ describe('ActiveContestTypeStore', () => {
4747
expect(store.isSame('abcLatest20Rounds' as ContestTableProviders)).toBe(false);
4848
expect(store.isSame('abc319Onwards' as ContestTableProviders)).toBe(false);
4949
});
50+
51+
test('expects to reset the value to default when calling reset()', () => {
52+
// First change the value to something else
53+
store.set('abc319Onwards' as ContestTableProviders);
54+
expect(store.get()).toBe('abc319Onwards');
55+
56+
// Call reset and verify it goes back to default
57+
store.reset();
58+
expect(store.get()).toBe('abcLatest20Rounds');
59+
60+
// Change to a different value and reset again to verify consistency
61+
store.set('fromAbc212ToAbc318' as ContestTableProviders);
62+
expect(store.get()).toBe('fromAbc212ToAbc318');
63+
64+
store.reset();
65+
expect(store.get()).toBe('abcLatest20Rounds');
66+
});
5067
});

0 commit comments

Comments
 (0)