-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # components/__tests__/login/ProviderButton.test.ts # package.json
- Loading branch information
Showing
3 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import {mount} from "@vue/test-utils"; | ||
import { describe, it, expect } from 'vitest'; | ||
import GameButtons from "@/components/home/Controls/GameButtons.vue"; | ||
|
||
|
||
describe('GameButtons', () => { | ||
// Test component mounting | ||
it('renders properly', () => { | ||
const wrapper = mount(GameButtons); | ||
|
||
// Check if both buttons are rendered | ||
expect(wrapper.findAll('button')).toHaveLength(2); | ||
|
||
// Check button text content | ||
const buttons = wrapper.findAll('button'); | ||
expect(buttons[0].text()).toBe('Start Game'); | ||
expect(buttons[1].text()).toBe('Quick Game'); | ||
}); | ||
|
||
// Test Start Game button emission | ||
it('emits startGame event when Start Game button is clicked', async () => { | ||
const wrapper = mount(GameButtons); | ||
|
||
// Find and click the Start Game button | ||
const startGameButton = wrapper.findAll('button')[0]; | ||
await startGameButton.trigger('click'); | ||
|
||
// Check if the event was emitted | ||
expect(wrapper.emitted()).toHaveProperty('startGame'); | ||
expect(wrapper.emitted('startGame')).toHaveLength(1); | ||
}); | ||
|
||
// Test Quick Game button emission | ||
it('emits quickGame event when Quick Game button is clicked', async () => { | ||
const wrapper = mount(GameButtons); | ||
|
||
// Find and click the Quick Game button | ||
const quickGameButton = wrapper.findAll('button')[1]; | ||
await quickGameButton.trigger('click'); | ||
|
||
// Check if the event was emitted | ||
expect(wrapper.emitted()).toHaveProperty('quickGame'); | ||
expect(wrapper.emitted('quickGame')).toHaveLength(1); | ||
}); | ||
|
||
// Test multiple clicks | ||
it('emits multiple events on multiple clicks', async () => { | ||
const wrapper = mount(GameButtons); | ||
const [startButton, quickButton] = wrapper.findAll('button'); | ||
|
||
// Click start game button twice | ||
await startButton.trigger('click'); | ||
await startButton.trigger('click'); | ||
|
||
// Click quick game button twice | ||
await quickButton.trigger('click'); | ||
await quickButton.trigger('click'); | ||
|
||
// Check if events were emitted correct number of times | ||
expect(wrapper.emitted('startGame')).toHaveLength(2); | ||
expect(wrapper.emitted('quickGame')).toHaveLength(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { mountSuspended } from '@nuxt/test-utils/runtime'; | ||
import ProviderButton from "~/components/login/ProviderButton.vue"; | ||
|
||
|
||
describe('ProviderButton', () => { | ||
const provider = {id: 'spotify', name: 'Spotify'}; | ||
|
||
it('renders the message correctly', async () => { | ||
const wrapper = await mountSuspended(ProviderButton,{props: {provider: provider.id, name: provider.name}}); | ||
expect(wrapper.text()).toContain('Sign in with ' + provider.name); | ||
}); | ||
|
||
// Test default props | ||
it('uses default props when none provided', async () => { | ||
const wrapper = await mountSuspended(ProviderButton); | ||
expect(wrapper.text()).toContain('Sign in with Spotify'); | ||
}); | ||
|
||
// Test image rendering | ||
it('renders the correct provider icon', async () => { | ||
const wrapper = await mountSuspended(ProviderButton, { | ||
props: {provider: provider.id} | ||
}); | ||
const img = wrapper.find('img'); | ||
expect(img.attributes('src')).toContain('icons/spotify.svg'); | ||
expect(img.attributes('alt')).toBe('spotify'); | ||
}); | ||
|
||
// Test button styling | ||
it('has correct styling classes', async () => { | ||
const wrapper = await mountSuspended(ProviderButton); | ||
const buttonDiv = wrapper.find('.flex'); | ||
expect(buttonDiv.classes()).toContain('bg-[#1DB954]'); // Spotify color | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters