🎯 Refactor test file for improved readability and consistency in formatting and mock function definitions
This commit is contained in:
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user