🎯 Refactor test file for improved readability and consistency in formatting and mock function definitions

This commit is contained in:
2026-01-29 05:12:20 +00:00
parent 7b04d39768
commit efc97eea31

View File

@@ -7,10 +7,12 @@ import { ref } from 'vue';
// Mock dependencies // Mock dependencies
vi.mock('../../../src/utilities/tournament-query.js', () => ({ vi.mock('../../../src/utilities/tournament-query.js', () => ({
queryAllTournaments: vi.fn(() => Promise.resolve([ queryAllTournaments: vi.fn(() =>
{ id: 1, name: 'Tournament 1', state: 'pending' }, Promise.resolve([
{ id: 2, name: 'Tournament 2', state: 'underway' } { id: 1, name: 'Tournament 1', state: 'pending' },
])) { id: 2, name: 'Tournament 2', state: 'underway' }
])
)
})); }));
vi.mock('../../../src/composables/useAsyncState.js', () => ({ vi.mock('../../../src/composables/useAsyncState.js', () => ({
@@ -23,7 +25,7 @@ vi.mock('../../../src/composables/useAsyncState.js', () => ({
data, data,
isLoading, isLoading,
error, error,
execute: vi.fn(async (fn) => { execute: vi.fn(async fn => {
isLoading.value = true; isLoading.value = true;
error.value = null; error.value = null;
try { try {
@@ -58,15 +60,19 @@ describe('useChallongeTests', () => {
mockClient = ref({ mockClient = ref({
tournaments: { tournaments: {
list: vi.fn(() => Promise.resolve([ list: vi.fn(() =>
{ id: 1, name: 'Test Tournament 1' }, Promise.resolve([
{ id: 2, name: 'Test Tournament 2' } { id: 1, name: 'Test Tournament 1' },
])), { id: 2, name: 'Test Tournament 2' }
get: vi.fn((id) => Promise.resolve({ ])
id, ),
name: `Tournament ${id}`, get: vi.fn(id =>
participants: [] Promise.resolve({
})) id,
name: `Tournament ${id}`,
participants: []
})
)
} }
}); });
@@ -75,13 +81,8 @@ describe('useChallongeTests', () => {
}); });
it('creates composable with initial state', () => { it('creates composable with initial state', () => {
const { const { tournaments, loading, error, searchQuery, currentPage } =
tournaments, useChallongeTests(mockClient, apiVersion, tournamentScope);
loading,
error,
searchQuery,
currentPage
} = useChallongeTests(mockClient, apiVersion, tournamentScope);
expect(tournaments.value).toBeNull(); expect(tournaments.value).toBeNull();
expect(loading.value).toBe(false); expect(loading.value).toBe(false);
@@ -104,11 +105,8 @@ describe('useChallongeTests', () => {
}); });
it('filters tournaments by search query', async () => { it('filters tournaments by search query', async () => {
const { testListTournaments, searchQuery, filteredTournaments } = useChallongeTests( const { testListTournaments, searchQuery, filteredTournaments } =
mockClient, useChallongeTests(mockClient, apiVersion, tournamentScope);
apiVersion,
tournamentScope
);
await testListTournaments(); await testListTournaments();