From efc97eea312b01cabce2938646232a1ea9905e48 Mon Sep 17 00:00:00 2001 From: FragginWagon Date: Thu, 29 Jan 2026 05:12:20 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=AF=20Refactor=20test=20file=20for=20i?= =?UTF-8?q?mproved=20readability=20and=20consistency=20in=20formatting=20a?= =?UTF-8?q?nd=20mock=20function=20definitions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../composables/useChallongeTests.test.js | 58 +++++++++---------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/code/websites/pokedex.online/tests/unit/composables/useChallongeTests.test.js b/code/websites/pokedex.online/tests/unit/composables/useChallongeTests.test.js index 3644df1..bf1eda5 100644 --- a/code/websites/pokedex.online/tests/unit/composables/useChallongeTests.test.js +++ b/code/websites/pokedex.online/tests/unit/composables/useChallongeTests.test.js @@ -7,10 +7,12 @@ import { ref } from 'vue'; // Mock dependencies vi.mock('../../../src/utilities/tournament-query.js', () => ({ - queryAllTournaments: vi.fn(() => Promise.resolve([ - { id: 1, name: 'Tournament 1', state: 'pending' }, - { id: 2, name: 'Tournament 2', state: 'underway' } - ])) + queryAllTournaments: vi.fn(() => + Promise.resolve([ + { id: 1, name: 'Tournament 1', state: 'pending' }, + { id: 2, name: 'Tournament 2', state: 'underway' } + ]) + ) })); vi.mock('../../../src/composables/useAsyncState.js', () => ({ @@ -23,7 +25,7 @@ vi.mock('../../../src/composables/useAsyncState.js', () => ({ data, isLoading, error, - execute: vi.fn(async (fn) => { + execute: vi.fn(async fn => { isLoading.value = true; error.value = null; try { @@ -58,15 +60,19 @@ describe('useChallongeTests', () => { mockClient = ref({ tournaments: { - list: vi.fn(() => Promise.resolve([ - { id: 1, name: 'Test Tournament 1' }, - { id: 2, name: 'Test Tournament 2' } - ])), - get: vi.fn((id) => Promise.resolve({ - id, - name: `Tournament ${id}`, - participants: [] - })) + list: vi.fn(() => + Promise.resolve([ + { id: 1, name: 'Test Tournament 1' }, + { id: 2, name: 'Test Tournament 2' } + ]) + ), + get: vi.fn(id => + Promise.resolve({ + id, + name: `Tournament ${id}`, + participants: [] + }) + ) } }); @@ -75,13 +81,8 @@ describe('useChallongeTests', () => { }); it('creates composable with initial state', () => { - const { - tournaments, - loading, - error, - searchQuery, - currentPage - } = useChallongeTests(mockClient, apiVersion, tournamentScope); + const { tournaments, loading, error, searchQuery, currentPage } = + useChallongeTests(mockClient, apiVersion, tournamentScope); expect(tournaments.value).toBeNull(); expect(loading.value).toBe(false); @@ -104,14 +105,11 @@ describe('useChallongeTests', () => { }); it('filters tournaments by search query', async () => { - const { testListTournaments, searchQuery, filteredTournaments } = useChallongeTests( - mockClient, - apiVersion, - tournamentScope - ); + const { testListTournaments, searchQuery, filteredTournaments } = + useChallongeTests(mockClient, apiVersion, tournamentScope); await testListTournaments(); - + // Set search query searchQuery.value = 'Tournament 1'; @@ -128,10 +126,10 @@ describe('useChallongeTests', () => { // v1 structure expect(getTournamentName({ tournament: { name: 'Test' } })).toBe('Test'); - + // v2.1 structure expect(getTournamentName({ name: 'Test' })).toBe('Test'); - + // Empty expect(getTournamentName({})).toBe(''); }); @@ -155,7 +153,7 @@ describe('useChallongeTests', () => { ); const tournament = { tournament: { state: 'pending', url: 'test-url' } }; - + expect(getTournamentProp(tournament, 'state')).toBe('pending'); expect(getTournamentProp(tournament, 'url')).toBe('test-url'); });