mirror of
https://github.com/unraid/api.git
synced 2026-01-01 06:01:18 -06:00
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>
66 lines
1.9 KiB
Vue
66 lines
1.9 KiB
Vue
<script lang="ts" setup>
|
|
import { computed } from 'vue';
|
|
import { storeToRefs } from 'pinia';
|
|
|
|
import { ArrowTopRightOnSquareIcon } from '@heroicons/vue/24/solid';
|
|
import { BrandButton, cn } from '@unraid/ui';
|
|
|
|
import type { ServerStateDataAction } from '~/types/server';
|
|
import type { ComposerTranslation } from 'vue-i18n';
|
|
|
|
import { useServerStore } from '~/store/server';
|
|
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
actions?: ServerStateDataAction[];
|
|
filterBy?: string[] | undefined;
|
|
filterOut?: string[] | undefined;
|
|
maxWidth?: boolean;
|
|
t: ComposerTranslation;
|
|
}>(),
|
|
{
|
|
actions: undefined,
|
|
filterBy: undefined,
|
|
filterOut: undefined,
|
|
maxWidth: false,
|
|
}
|
|
);
|
|
|
|
const { keyActions } = storeToRefs(useServerStore());
|
|
|
|
const computedActions = computed((): ServerStateDataAction[] | undefined =>
|
|
props.actions ? props.actions : keyActions.value
|
|
);
|
|
|
|
const filteredKeyActions = computed((): ServerStateDataAction[] | undefined => {
|
|
if (!computedActions.value || (!props.filterOut && !props.filterBy)) {
|
|
return computedActions.value;
|
|
}
|
|
|
|
return computedActions.value.filter((action: { name: string }) => {
|
|
return props.filterOut
|
|
? !props.filterOut?.includes(action.name)
|
|
: props.filterBy?.includes(action.name);
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<ul v-if="filteredKeyActions" class="flex flex-col gap-y-8px">
|
|
<li v-for="action in filteredKeyActions" :key="action.name">
|
|
<BrandButton
|
|
:class="cn('w-full', props.maxWidth ? 'sm:max-w-300px' : '')"
|
|
:disabled="action?.disabled"
|
|
:external="action?.external"
|
|
:href="action?.href"
|
|
:icon="action.icon"
|
|
:icon-right="ArrowTopRightOnSquareIcon"
|
|
:icon-right-hover-display="true"
|
|
:text="t(action.text)"
|
|
:title="action.title ? t(action.title) : undefined"
|
|
@click="action.click?.()"
|
|
/>
|
|
</li>
|
|
</ul>
|
|
</template>
|