|
| 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 return the current value when calling get()', () => { |
| 18 | + expect(store.get()).toBe('abcLatest20Rounds'); |
| 19 | + |
| 20 | + // Change the value and verify get() returns the new value |
| 21 | + store.value = 'abc319Onwards' as ContestTableProviders; |
| 22 | + expect(store.get()).toBe('abc319Onwards'); |
| 23 | + }); |
| 24 | + |
| 25 | + test('expects to update the value when calling set()', () => { |
| 26 | + store.set('fromAbc212ToAbc318' as ContestTableProviders); |
| 27 | + expect(store.value).toBe('fromAbc212ToAbc318'); |
| 28 | + expect(store.get()).toBe('fromAbc212ToAbc318'); |
| 29 | + |
| 30 | + store.set('abc319Onwards' as ContestTableProviders); |
| 31 | + expect(store.value).toBe('abc319Onwards'); |
| 32 | + expect(store.get()).toBe('abc319Onwards'); |
| 33 | + }); |
| 34 | + |
| 35 | + test('expects to correctly determine if contest type is the same with isSame()', () => { |
| 36 | + expect(store.isSame('abcLatest20Rounds' as ContestTableProviders)).toBe(true); |
| 37 | + expect(store.isSame('abc319Onwards' as ContestTableProviders)).toBe(false); |
| 38 | + expect(store.isSame('fromAbc212ToAbc318' as ContestTableProviders)).toBe(false); |
| 39 | + |
| 40 | + store.set('abc319Onwards' as ContestTableProviders); |
| 41 | + expect(store.isSame('abc319Onwards' as ContestTableProviders)).toBe(true); |
| 42 | + expect(store.isSame('abcLatest20Rounds' as ContestTableProviders)).toBe(false); |
| 43 | + expect(store.isSame('fromAbc212ToAbc318' as ContestTableProviders)).toBe(false); |
| 44 | + |
| 45 | + store.set('fromAbc212ToAbc318' as ContestTableProviders); |
| 46 | + expect(store.isSame('fromAbc212ToAbc318' as ContestTableProviders)).toBe(true); |
| 47 | + expect(store.isSame('abcLatest20Rounds' as ContestTableProviders)).toBe(false); |
| 48 | + expect(store.isSame('abc319Onwards' as ContestTableProviders)).toBe(false); |
| 49 | + }); |
| 50 | +}); |
0 commit comments