Files
api/web/__test__/components/KeyActions.test.ts
Eli Bosley 2c62e0ad09 feat: tailwind v4 (#1522)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Streamlined Tailwind CSS integration using Vite plugin, eliminating
the need for separate Tailwind config files.
* Updated theme and color variables for improved consistency and
maintainability.

* **Style**
* Standardized spacing, sizing, and font classes across all components
using Tailwind’s default scale.
* Reduced excessive gaps, padding, and font sizes for a more compact and
cohesive UI.
* Updated gradient, border, and shadow classes to match Tailwind v4
conventions.
* Replaced custom pixel-based classes with Tailwind’s bracketed
arbitrary value syntax where needed.
* Replaced focus outline styles from `outline-none` to `outline-hidden`
for consistent focus handling.
* Updated flex shrink/grow utility classes to use newer shorthand forms.
* Converted several component templates to use self-closing tags for
cleaner markup.
  * Adjusted icon sizes and spacing for improved visual balance.

* **Chores**
* Removed legacy Tailwind/PostCSS configuration files and related
scripts.
* Updated and cleaned up package dependencies for Tailwind v4 and
related plugins.
  * Removed unused or redundant build scripts and configuration exports.
  * Updated documentation to reflect new Tailwind v4 usage.
  * Removed Prettier Tailwind plugin from formatting configurations.
* Removed Nuxt Tailwind module in favor of direct Vite plugin
integration.
  * Cleaned up ESLint config by removing Prettier integration.

* **Bug Fixes**
  * Corrected invalid or outdated Tailwind class names and syntax.
* Fixed issues with max-width and other utility classes for improved
layout consistency.

* **Tests**
* Updated test assertions to match new class names and styling
conventions.

* **Documentation**
* Revised README and internal notes to clarify Tailwind v4 adoption and
configuration changes.
* Added new development notes emphasizing Tailwind v4 usage and
documentation references.

* **UI Components**
* Enhanced BrandButton stories with detailed variant, size, and padding
showcases for better visual testing.
* Improved theme store to apply dark mode class on both `<html>` and
`<body>` elements for compatibility.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-21 09:58:02 -04:00

201 lines
5.4 KiB
TypeScript

/**
* KeyActions Component Test Coverage
*/
import { mount } from '@vue/test-utils';
import { ArrowTopRightOnSquareIcon } from '@heroicons/vue/24/solid';
import { BrandButton } from '@unraid/ui';
import { createTestingPinia } from '@pinia/testing';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { ServerStateDataAction, ServerStateDataActionType } from '~/types/server';
import KeyActions from '../../components/KeyActions.vue';
import '~/__test__/mocks/ui-components';
vi.mock('crypto-js/aes', () => ({
default: {},
}));
vi.mock('@unraid/shared-callbacks', () => ({
useCallback: vi.fn(() => ({
send: vi.fn(),
watcher: vi.fn(),
})),
}));
const t = (key: string) => `translated_${key}`;
describe('KeyActions', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('renders buttons from props when actions prop is provided', () => {
const actions: ServerStateDataAction[] = [
{ name: 'purchase' as ServerStateDataActionType, text: 'Custom Action 1', click: vi.fn() },
];
const wrapper = mount(KeyActions, {
props: {
t,
actions,
},
});
const buttons = wrapper.findAllComponents(BrandButton);
expect(buttons.length).toBe(1);
expect(buttons[0].text()).toContain('translated_Custom Action 1');
});
it('renders an empty list container when actions array is empty', () => {
const wrapper = mount(KeyActions, {
props: {
t,
actions: [],
},
global: {
plugins: [createTestingPinia({ createSpy: vi.fn })],
},
});
expect(wrapper.find('ul').exists()).toBe(true);
expect(wrapper.findAll('li').length).toBe(0);
});
it('calls action click handler when button is clicked', async () => {
const click = vi.fn();
const actions: ServerStateDataAction[] = [
{ name: 'purchase' as ServerStateDataActionType, text: 'Clickable Action', click },
];
const wrapper = mount(KeyActions, {
props: {
t,
actions,
},
});
await wrapper.findComponent(BrandButton).trigger('click');
expect(click).toHaveBeenCalledTimes(1);
});
it('does not call click handler for disabled buttons', async () => {
const click = vi.fn();
const actions: ServerStateDataAction[] = [
{
name: 'purchase' as ServerStateDataActionType,
text: 'Disabled Action',
disabled: true,
click,
},
];
const wrapper = mount(KeyActions, {
props: {
t,
actions,
},
});
await wrapper.findComponent(BrandButton).trigger('click');
expect(click).not.toHaveBeenCalled();
});
it('filters actions using filterBy prop', () => {
const actions: ServerStateDataAction[] = [
{ name: 'purchase' as ServerStateDataActionType, text: 'Action 1', click: vi.fn() },
{ name: 'redeem' as ServerStateDataActionType, text: 'Action 2', click: vi.fn() },
{ name: 'upgrade' as ServerStateDataActionType, text: 'Action 3', click: vi.fn() },
];
const wrapper = mount(KeyActions, {
props: {
t,
actions,
filterBy: ['purchase', 'upgrade'],
},
});
const buttons = wrapper.findAllComponents(BrandButton);
expect(buttons.length).toBe(2);
expect(buttons[0].text()).toContain('translated_Action 1');
expect(buttons[1].text()).toContain('translated_Action 3');
});
it('filters out actions using filterOut prop', () => {
const actions: ServerStateDataAction[] = [
{ name: 'purchase' as ServerStateDataActionType, text: 'Action 1', click: vi.fn() },
{ name: 'redeem' as ServerStateDataActionType, text: 'Action 2', click: vi.fn() },
{ name: 'upgrade' as ServerStateDataActionType, text: 'Action 3', click: vi.fn() },
];
const wrapper = mount(KeyActions, {
props: {
t,
actions,
filterOut: ['redeem'],
},
});
const buttons = wrapper.findAllComponents(BrandButton);
expect(buttons.length).toBe(2);
expect(buttons[0].text()).toContain('translated_Action 1');
expect(buttons[1].text()).toContain('translated_Action 3');
});
it('applies maxWidth styling when maxWidth prop is true', () => {
const actions: ServerStateDataAction[] = [
{ name: 'purchase' as ServerStateDataActionType, text: 'Action 1', click: vi.fn() },
];
const wrapper = mount(KeyActions, {
props: {
t,
actions,
maxWidth: true,
},
});
const button = wrapper.findComponent(BrandButton);
expect(button.props('class')).toContain('sm:max-w-[300px]');
});
it('passes all required props to BrandButton component', () => {
const actions: ServerStateDataAction[] = [
{
name: 'purchase' as ServerStateDataActionType,
text: 'Test Action',
title: 'Action Title',
href: '/test-link',
external: true,
disabled: true,
icon: ArrowTopRightOnSquareIcon,
click: vi.fn(),
},
];
const wrapper = mount(KeyActions, {
props: {
t,
actions,
},
});
const button = wrapper.findComponent(BrandButton);
expect(button.props('text')).toBe('translated_Test Action');
expect(button.props('title')).toBe('translated_Action Title');
expect(button.props('href')).toBe('/test-link');
expect(button.props('external')).toBe(true);
expect(button.props('disabled')).toBe(true);
expect(button.props('icon')).toBe(ArrowTopRightOnSquareIcon);
});
});