🎯 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
|
// 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,14 +105,11 @@ 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();
|
||||||
|
|
||||||
// Set search query
|
// Set search query
|
||||||
searchQuery.value = 'Tournament 1';
|
searchQuery.value = 'Tournament 1';
|
||||||
|
|
||||||
@@ -128,10 +126,10 @@ describe('useChallongeTests', () => {
|
|||||||
|
|
||||||
// v1 structure
|
// v1 structure
|
||||||
expect(getTournamentName({ tournament: { name: 'Test' } })).toBe('Test');
|
expect(getTournamentName({ tournament: { name: 'Test' } })).toBe('Test');
|
||||||
|
|
||||||
// v2.1 structure
|
// v2.1 structure
|
||||||
expect(getTournamentName({ name: 'Test' })).toBe('Test');
|
expect(getTournamentName({ name: 'Test' })).toBe('Test');
|
||||||
|
|
||||||
// Empty
|
// Empty
|
||||||
expect(getTournamentName({})).toBe('');
|
expect(getTournamentName({})).toBe('');
|
||||||
});
|
});
|
||||||
@@ -155,7 +153,7 @@ describe('useChallongeTests', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const tournament = { tournament: { state: 'pending', url: 'test-url' } };
|
const tournament = { tournament: { state: 'pending', url: 'test-url' } };
|
||||||
|
|
||||||
expect(getTournamentProp(tournament, 'state')).toBe('pending');
|
expect(getTournamentProp(tournament, 'state')).toBe('pending');
|
||||||
expect(getTournamentProp(tournament, 'url')).toBe('test-url');
|
expect(getTournamentProp(tournament, 'url')).toBe('test-url');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user