Files
api/web/__test__/mocks/ui-components.ts
Michael Datelle 03be042410 test: create tests for stores (#1338)
This gets the original 3 component tests refactored to better follow the
Vue Testing Library philosophy and test behavior. This also adds a new
test file for the server store. Additional batches of tests will be
added in proceeding PR's.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Chores**  
- Streamlined internal code organization and improved maintenance
through refined import structures and cleanup of redundant files.

- **Tests**  
- Expanded and restructured automated tests across core components,
including new test files for `Auth`, `DownloadApiLogs`, and `KeyActions`
to ensure robust behavior.
- Enhanced test configuration and mock implementations for a more
reliable, consistent testing environment.
- Introduced best practices for testing Vue components and Pinia stores.

These updates optimize performance and stability behind the scenes
without altering the end-user experience.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: mdatelle <mike@datelle.net>
2025-04-09 11:57:11 -04:00

45 lines
1.1 KiB
TypeScript

import { vi } from 'vitest';
// Mock @unraid/ui components and functions
const mockCn = (...args: unknown[]) => args.filter(Boolean).join(' ');
const MockBrandButton = {
name: 'BrandButton',
props: [
'class',
'disabled',
'external',
'href',
'icon',
'iconRight',
'iconRightHoverDisplay',
'text',
'title',
'download',
],
template: `
<component :is="props.href ? 'a' : 'button'"
:class="props.class"
:disabled="props.disabled"
:href="props.href"
:target="props.external ? '_blank' : undefined"
:rel="props.external ? 'noopener noreferrer' : undefined"
:title="props.title"
:download="props.download"
>
<span v-if="props.icon" class="icon">{{ props.icon }}</span>
{{ props.text || '' }} <slot />
<span v-if="props.iconRight" class="icon-right" :class="{ 'hover-only': props.iconRightHoverDisplay }">{{ props.iconRight }}</span>
</component>
`,
setup(props: Record<string, unknown>) {
return { props };
},
};
vi.mock('@unraid/ui', () => ({
cn: mockCn,
BrandButton: MockBrandButton,
// Add other UI components as needed
}));