Skip to content

Commit

Permalink
Merge branch 'feat/testing'
Browse files Browse the repository at this point in the history
# Conflicts:
#	components/__tests__/login/ProviderButton.test.ts
#	package.json
  • Loading branch information
Likqez committed Dec 23, 2024
2 parents 3c27949 + 8f7b98f commit 01eebcd
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
63 changes: 63 additions & 0 deletions components/__tests__/home/Controls/GameButtons.test.ts
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);
});
});
37 changes: 37 additions & 0 deletions components/__tests__/login/ProviderButton.test.ts
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
});

});
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"start": "nuxt build && nuxt start",
"postinstall": "nuxt prepare",
"docs": "typedoc",
"docs:serve": "typedoc && npx serve docs"
"docs:serve": "typedoc && npx serve docs",
"test": "vitest"
},
"dependencies": {
"@hebilicious/authjs-nuxt": "^0.3.5",
Expand All @@ -30,6 +31,12 @@
"@types/jsonpath": "^0.2.4",
"@types/node": "^22.8.5",
"eslint": "^9.11.1",
"typedoc": "^0.26.10"
"typedoc": "^0.26.10",
"@nuxt/test-utils": "^3.14.4",
"@vue/test-utils": "^2.4.6",
"happy-dom": "^15.7.4",
"nitro-test-utils": "^0.9.0",
"playwright-core": "^1.48.1",
"vitest": "^2.1.3"
}
}

0 comments on commit 01eebcd

Please sign in to comment.