|
| 1 | +import { describe, test, expect, beforeEach } from 'vitest'; |
| 2 | + |
| 3 | +import type { ContestTableProviders } from '$lib/utils/contest_table_provider'; |
| 4 | +import { ActiveContestTypeStore } from '$lib/stores/active_contest_type.svelte'; |
| 5 | + |
| 6 | +describe('ActiveContestTypeStore', () => { |
| 7 | + let store: ActiveContestTypeStore; |
| 8 | + |
| 9 | + beforeEach(() => { |
| 10 | + store = new ActiveContestTypeStore(); |
| 11 | + }); |
| 12 | + |
| 13 | + test('expects to initialize with default value', () => { |
| 14 | + expect(store.get()).toBe('abcLatest20Rounds'); |
| 15 | + }); |
| 16 | + |
| 17 | + test('expects to initialize with provided value', () => { |
| 18 | + const customStore = new ActiveContestTypeStore('abc319Onwards' as ContestTableProviders); |
| 19 | + expect(customStore.get()).toBe('abc319Onwards'); |
| 20 | + }); |
| 21 | + |
| 22 | + test('expects to return the current value when calling get()', () => { |
| 23 | + expect(store.get()).toBe('abcLatest20Rounds'); |
| 24 | + |
| 25 | + // Change the value and verify get() returns the new value |
| 26 | + store.set('abc319Onwards' as ContestTableProviders); |
| 27 | + expect(store.get()).toBe('abc319Onwards'); |
| 28 | + }); |
| 29 | + |
| 30 | + test('expects to update the value when calling set()', () => { |
| 31 | + store.set('fromAbc212ToAbc318' as ContestTableProviders); |
| 32 | + expect(store.value).toBe('fromAbc212ToAbc318'); |
| 33 | + expect(store.get()).toBe('fromAbc212ToAbc318'); |
| 34 | + |
| 35 | + store.set('abc319Onwards' as ContestTableProviders); |
| 36 | + expect(store.value).toBe('abc319Onwards'); |
| 37 | + expect(store.get()).toBe('abc319Onwards'); |
| 38 | + }); |
| 39 | + |
| 40 | + test('expects to correctly determine if contest type is the same with isSame()', () => { |
| 41 | + expect(store.isSame('abcLatest20Rounds' as ContestTableProviders)).toBe(true); |
| 42 | + expect(store.isSame('abc319Onwards' as ContestTableProviders)).toBe(false); |
| 43 | + expect(store.isSame('fromAbc212ToAbc318' as ContestTableProviders)).toBe(false); |
| 44 | + |
| 45 | + store.set('abc319Onwards' as ContestTableProviders); |
| 46 | + expect(store.isSame('abc319Onwards' as ContestTableProviders)).toBe(true); |
| 47 | + expect(store.isSame('abcLatest20Rounds' as ContestTableProviders)).toBe(false); |
| 48 | + expect(store.isSame('fromAbc212ToAbc318' as ContestTableProviders)).toBe(false); |
| 49 | + |
| 50 | + store.set('fromAbc212ToAbc318' as ContestTableProviders); |
| 51 | + expect(store.isSame('fromAbc212ToAbc318' as ContestTableProviders)).toBe(true); |
| 52 | + expect(store.isSame('abcLatest20Rounds' as ContestTableProviders)).toBe(false); |
| 53 | + expect(store.isSame('abc319Onwards' as ContestTableProviders)).toBe(false); |
| 54 | + }); |
| 55 | + |
| 56 | + test('expects to reset the value to default when calling reset()', () => { |
| 57 | + // First change the value to something else |
| 58 | + store.set('abc319Onwards' as ContestTableProviders); |
| 59 | + expect(store.get()).toBe('abc319Onwards'); |
| 60 | + |
| 61 | + // Call reset and verify it goes back to default |
| 62 | + store.reset(); |
| 63 | + expect(store.get()).toBe('abcLatest20Rounds'); |
| 64 | + |
| 65 | + // Change to a different value and reset again to verify consistency |
| 66 | + store.set('fromAbc212ToAbc318' as ContestTableProviders); |
| 67 | + expect(store.get()).toBe('fromAbc212ToAbc318'); |
| 68 | + |
| 69 | + store.reset(); |
| 70 | + expect(store.get()).toBe('abcLatest20Rounds'); |
| 71 | + }); |
| 72 | +}); |
0 commit comments