mirror of
https://github.com/unraid/api.git
synced 2026-05-05 14:41:54 -05:00
31c41027fc
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - App-wide internationalization: dynamic locale detection/loading, many new locale bundles, and CLI helpers to extract/sort translation keys. - **Accessibility** - Brand button supports keyboard activation (Enter/Space). - **Documentation** - Internationalization guidance added to API and Web READMEs. - **Refactor** - UI updated to use centralized i18n keys and a unified locale loading approach. - **Tests** - Test utilities updated to support i18n and localized assertions. - **Chores** - Crowdin config and i18n scripts added; runtime locale exposed for selection. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
201 lines
5.8 KiB
TypeScript
201 lines
5.8 KiB
TypeScript
/**
|
|
* DowngradeOs Component Test Coverage
|
|
*/
|
|
|
|
import { setActivePinia } from 'pinia';
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { createTestingPinia } from '@pinia/testing';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import DowngradeOs from '~/components/DowngradeOs.standalone.vue';
|
|
import { useServerStore } from '~/store/server';
|
|
import { createTestI18n, testTranslate } from '../utils/i18n';
|
|
|
|
vi.mock('crypto-js/aes', () => ({
|
|
default: {},
|
|
}));
|
|
|
|
vi.mock('@unraid/shared-callbacks', () => ({
|
|
useCallback: vi.fn(() => ({
|
|
send: vi.fn(),
|
|
watcher: vi.fn(),
|
|
})),
|
|
}));
|
|
|
|
vi.mock('@unraid/ui', async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import('@unraid/ui')>();
|
|
|
|
return {
|
|
...actual,
|
|
};
|
|
});
|
|
|
|
vi.mock('vue-i18n', async (importOriginal) => {
|
|
const actual = (await importOriginal()) as typeof import('vue-i18n');
|
|
return {
|
|
...actual,
|
|
useI18n: () => ({
|
|
t: testTranslate,
|
|
}),
|
|
};
|
|
});
|
|
|
|
const PageContainerStub = {
|
|
template: '<div><slot /></div>',
|
|
};
|
|
const UpdateOsStatusStub = {
|
|
template: '<div />',
|
|
props: ['title', 'subtitle', 'downgradeNotAvailable', 'showExternalDowngrade', 't'],
|
|
};
|
|
const UpdateOsDowngradeStub = {
|
|
template: '<div />',
|
|
props: ['releaseDate', 'version', 't'],
|
|
};
|
|
const UpdateOsThirdPartyDriversStub = {
|
|
template: '<div />',
|
|
props: ['t'],
|
|
};
|
|
|
|
describe('DowngradeOs', () => {
|
|
let serverStore: ReturnType<typeof useServerStore>;
|
|
|
|
beforeEach(() => {
|
|
const pinia = createTestingPinia({ createSpy: vi.fn });
|
|
|
|
setActivePinia(pinia);
|
|
serverStore = useServerStore();
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('calls setRebootVersion on mount with prop value', () => {
|
|
const rebootVersionProp = '6.10.0';
|
|
|
|
mount(DowngradeOs, {
|
|
props: {
|
|
rebootVersion: rebootVersionProp,
|
|
},
|
|
global: {
|
|
plugins: [createTestI18n()],
|
|
stubs: {
|
|
PageContainer: PageContainerStub,
|
|
UpdateOsStatus: UpdateOsStatusStub,
|
|
UpdateOsDowngrade: UpdateOsDowngradeStub,
|
|
UpdateOsThirdPartyDrivers: UpdateOsThirdPartyDriversStub,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(serverStore.setRebootVersion).toHaveBeenCalledTimes(1);
|
|
expect(serverStore.setRebootVersion).toHaveBeenCalledWith(rebootVersionProp);
|
|
});
|
|
|
|
it('renders UpdateOsStatus with initial props', () => {
|
|
const wrapper = mount(DowngradeOs, {
|
|
global: {
|
|
plugins: [createTestI18n()],
|
|
stubs: {
|
|
PageContainer: PageContainerStub,
|
|
UpdateOsStatus: UpdateOsStatusStub,
|
|
UpdateOsDowngrade: UpdateOsDowngradeStub,
|
|
UpdateOsThirdPartyDrivers: UpdateOsThirdPartyDriversStub,
|
|
},
|
|
},
|
|
});
|
|
|
|
const statusStub = wrapper.findComponent(UpdateOsStatusStub);
|
|
|
|
expect(statusStub.exists()).toBe(true);
|
|
expect(statusStub.props('title')).toBe('Downgrade Unraid OS');
|
|
expect(statusStub.props('subtitle')).toBe('');
|
|
expect(statusStub.props('downgradeNotAvailable')).toBe(true);
|
|
expect(statusStub.props('showExternalDowngrade')).toBe(false);
|
|
});
|
|
|
|
it('renders UpdateOsDowngrade when restoreVersion is provided and rebootType is empty', () => {
|
|
serverStore.rebootType = '';
|
|
|
|
const wrapper = mount(DowngradeOs, {
|
|
props: {
|
|
restoreVersion: '6.9.2',
|
|
restoreReleaseDate: '2023-01-01',
|
|
},
|
|
global: {
|
|
plugins: [createTestI18n()],
|
|
stubs: {
|
|
PageContainer: PageContainerStub,
|
|
UpdateOsStatus: UpdateOsStatusStub,
|
|
UpdateOsDowngrade: UpdateOsDowngradeStub,
|
|
UpdateOsThirdPartyDrivers: UpdateOsThirdPartyDriversStub,
|
|
},
|
|
},
|
|
});
|
|
|
|
const downgradeStub = wrapper.findComponent(UpdateOsDowngradeStub);
|
|
|
|
expect(downgradeStub.exists()).toBe(true);
|
|
expect(downgradeStub.props('version')).toBe('6.9.2');
|
|
expect(downgradeStub.props('releaseDate')).toBe('2023-01-01');
|
|
|
|
expect(wrapper.findComponent(UpdateOsStatusStub).props('downgradeNotAvailable')).toBe(false);
|
|
expect(wrapper.findComponent(UpdateOsThirdPartyDriversStub).exists()).toBe(false);
|
|
});
|
|
|
|
it('renders UpdateOsThirdPartyDrivers when rebootType is thirdPartyDriversDownloading', () => {
|
|
serverStore.rebootType = 'thirdPartyDriversDownloading';
|
|
|
|
const wrapper = mount(DowngradeOs, {
|
|
props: {},
|
|
global: {
|
|
plugins: [createTestI18n()],
|
|
stubs: {
|
|
PageContainer: PageContainerStub,
|
|
UpdateOsStatus: UpdateOsStatusStub,
|
|
UpdateOsDowngrade: UpdateOsDowngradeStub,
|
|
UpdateOsThirdPartyDrivers: UpdateOsThirdPartyDriversStub,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(wrapper.findComponent(UpdateOsThirdPartyDriversStub).exists()).toBe(true);
|
|
expect(wrapper.findComponent(UpdateOsDowngradeStub).exists()).toBe(false);
|
|
});
|
|
|
|
it('passes correct subtitle to UpdateOsStatus when rebootType is update', () => {
|
|
serverStore.rebootType = 'update';
|
|
|
|
const wrapper = mount(DowngradeOs, {
|
|
global: {
|
|
stubs: {
|
|
PageContainer: PageContainerStub,
|
|
UpdateOsStatus: UpdateOsStatusStub,
|
|
UpdateOsDowngrade: UpdateOsDowngradeStub,
|
|
UpdateOsThirdPartyDrivers: UpdateOsThirdPartyDriversStub,
|
|
},
|
|
},
|
|
});
|
|
|
|
const statusStub = wrapper.findComponent(UpdateOsStatusStub);
|
|
expect(statusStub.props('subtitle')).toBe(
|
|
'Please finish the initiated update to enable a downgrade.'
|
|
);
|
|
});
|
|
|
|
it('passes correct showExternalDowngrade based on osVersionBranch', () => {
|
|
serverStore.osVersionBranch = 'next';
|
|
|
|
const wrapper = mount(DowngradeOs, {
|
|
global: {
|
|
stubs: {
|
|
PageContainer: PageContainerStub,
|
|
UpdateOsStatus: UpdateOsStatusStub,
|
|
UpdateOsDowngrade: UpdateOsDowngradeStub,
|
|
UpdateOsThirdPartyDrivers: UpdateOsThirdPartyDriversStub,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(wrapper.findComponent(UpdateOsStatusStub).props('showExternalDowngrade')).toBe(true);
|
|
});
|
|
});
|