import { mockNuxtImport, renderSuspended } from '@nuxt/test-utils/runtime';
import { screen } from '@testing-library/vue';
import userEvent from '@testing-library/user-event';
import { describe, it, expect, beforeEach } from 'vitest';
import ColorModeButton from '~/components/ColorModeButton.vue';
const colorMode = {
_preference: 'light' as 'light' | 'dark',
get preference() {
return this._preference;
},
set preference(val: 'light' | 'dark') {
this._preference = val;
},
get value() {
return this._preference;
}
};
mockNuxtImport('useColorMode', () => {
return () => colorMode;
});
describe('ColorModeButton', () => {
beforeEach(() => {
colorMode.preference = 'light';
});
it('should render a toggle button with sun icon in light mode', async () => {
await renderSuspended(ColorModeButton);
const button = await screen.findByRole('button', { name: /toggle color mode/i });
const icon = await button.querySelector('span')
expect(icon).toHaveClass('i-lucide:sun');
});
// TODO: fix this test...cant figure out why clicking on the button wont switch the icon
// it('should display a moon icon when the sun is clicked', async () => {
// const user = userEvent.setup()
// await renderSuspended(ColorModeButton);
// const button = await screen.findByRole('button', { name: /toggle color mode/i });
// await user.click(button);
// const icon = await button.querySelector('span');
// expect(icon).toHaveClass('i-lucide:moon');
// });
});