mirror of
https://github.com/unraid/api.git
synced 2026-01-04 23:50:37 -06:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added new modal dialogs and UI components, including activation steps, OS update feedback, and expanded notification management. * Introduced a plugin to configure internationalization, state management, and Apollo client support in web components. * Added a new Log Viewer page with a streamlined interface for viewing logs. * **Improvements** * Centralized Pinia state management by consolidating all stores to use a shared global Pinia instance. * Simplified component templates by removing redundant internationalization host wrappers. * Enhanced ESLint configuration with stricter rules and global variable declarations. * Refined custom element build process to prevent jQuery conflicts and optimize minification. * Updated component imports and templates for consistent structure and maintainability. * Streamlined log viewer dropdowns using simplified select components with improved formatting. * Improved notification sidebar with filtering by importance and modular components. * Replaced legacy notification popups with new UI components and added automatic root session creation for localhost requests. * Updated OS version display and user profile UI with refined styling and component usage. * **Bug Fixes** * Fixed component tag capitalization and improved type annotations across components. * **Chores** * Updated development dependencies including ESLint plugins and build tools. * Removed deprecated log viewer patch class and cleaned up related test fixtures. * Removed unused imports and simplified Apollo client setup. * Cleaned up test mocks and removed obsolete i18n host component tests. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210730229632804 --------- Co-authored-by: Pujit Mehrotra <pujit@lime-technology.com> Co-authored-by: Zack Spear <zackspear@users.noreply.github.com>
151 lines
4.4 KiB
TypeScript
151 lines
4.4 KiB
TypeScript
/**
|
|
* HeaderOsVersion Component Test Coverage
|
|
*/
|
|
|
|
import { nextTick } from 'vue';
|
|
import { setActivePinia } from 'pinia';
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { createTestingPinia } from '@pinia/testing';
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import type { TestingPinia } from '@pinia/testing';
|
|
import type { VueWrapper } from '@vue/test-utils';
|
|
import type { Error as CustomApiError } from '~/store/errors';
|
|
import type { ServerUpdateOsResponse } from '~/types/server';
|
|
|
|
import HeaderOsVersion from '~/components/HeaderOsVersion.ce.vue';
|
|
import { useErrorsStore } from '~/store/errors';
|
|
import { useServerStore } from '~/store/server';
|
|
|
|
const testMockReleaseNotesUrl = 'http://mock.release.notes/v';
|
|
|
|
vi.mock('crypto-js/aes', () => ({ default: {} }));
|
|
vi.mock('@unraid/shared-callbacks', () => ({
|
|
useCallback: vi.fn(() => ({ send: vi.fn(), watcher: vi.fn() })),
|
|
}));
|
|
|
|
vi.mock('@vue/apollo-composable', () => ({
|
|
useQuery: () => ({
|
|
result: { value: {} },
|
|
loading: { value: false },
|
|
}),
|
|
useLazyQuery: () => ({
|
|
result: { value: {} },
|
|
loading: { value: false },
|
|
load: vi.fn(),
|
|
refetch: vi.fn(),
|
|
onResult: vi.fn(),
|
|
onError: vi.fn(),
|
|
}),
|
|
provideApolloClient: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('~/helpers/urls', async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import('~/helpers/urls')>();
|
|
const mockReleaseNotesUrl = 'http://mock.release.notes/v';
|
|
const mockWebGuiToolsUpdate = '/mock/Tools/Update';
|
|
const mockWebGuiToolsDowngrade = '/mock/Tools/Downgrade';
|
|
|
|
return {
|
|
...actual,
|
|
getReleaseNotesUrl: vi.fn((version: string) => `${mockReleaseNotesUrl}${version}`),
|
|
WEBGUI_TOOLS_UPDATE: mockWebGuiToolsUpdate,
|
|
WEBGUI_TOOLS_DOWNGRADE: mockWebGuiToolsDowngrade,
|
|
};
|
|
});
|
|
|
|
vi.mock('vue-i18n', () => ({
|
|
useI18n: () => ({
|
|
t: (key: string, params?: unknown) => {
|
|
if (params && Array.isArray(params)) {
|
|
let result = key;
|
|
params.forEach((val, index) => {
|
|
result = result.replace(`{${index}}`, String(val));
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
const keyMap: Record<string, string> = {
|
|
'Reboot Required for Update': 'Reboot Required for Update',
|
|
'Reboot Required for Downgrade': 'Reboot Required for Downgrade',
|
|
'Updating 3rd party drivers': 'Updating 3rd party drivers',
|
|
'Update Available': 'Update Available',
|
|
'Update Released': 'Update Released',
|
|
'View release notes': 'View release notes',
|
|
};
|
|
|
|
return keyMap[key] ?? key;
|
|
},
|
|
}),
|
|
}));
|
|
|
|
describe('HeaderOsVersion', () => {
|
|
let wrapper: VueWrapper<unknown>;
|
|
let testingPinia: TestingPinia;
|
|
let serverStore: ReturnType<typeof useServerStore>;
|
|
let errorsStore: ReturnType<typeof useErrorsStore>;
|
|
|
|
const findUpdateStatusComponent = () => {
|
|
const statusElement = wrapper.find('a.group:not([title*="release notes"]), button.group');
|
|
return statusElement.exists() ? statusElement : null;
|
|
};
|
|
|
|
beforeEach(() => {
|
|
testingPinia = createTestingPinia({ createSpy: vi.fn });
|
|
setActivePinia(testingPinia);
|
|
|
|
serverStore = useServerStore();
|
|
errorsStore = useErrorsStore();
|
|
|
|
serverStore.osVersion = '6.12.0';
|
|
serverStore.rebootType = '';
|
|
serverStore.updateOsResponse = undefined;
|
|
serverStore.regExp = 0;
|
|
serverStore.updateOsIgnoredReleases = [];
|
|
errorsStore.errors = [];
|
|
|
|
wrapper = mount(HeaderOsVersion, {
|
|
global: {
|
|
plugins: [testingPinia],
|
|
},
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
wrapper?.unmount();
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it('renders OS version link with correct URL and no update status initially', () => {
|
|
const versionLink = wrapper.find('a[title*="release notes"]');
|
|
|
|
expect(versionLink.exists()).toBe(true);
|
|
expect(versionLink.attributes('href')).toBe(`${testMockReleaseNotesUrl}6.12.0`);
|
|
|
|
expect(versionLink.text()).toContain('6.12.0');
|
|
expect(findUpdateStatusComponent()).toBeNull();
|
|
});
|
|
|
|
it('does not render update status when stateDataError is present', async () => {
|
|
const mockError: CustomApiError = {
|
|
message: 'State data fetch failed',
|
|
heading: 'Fetch Error',
|
|
level: 'error',
|
|
type: 'serverState',
|
|
};
|
|
errorsStore.errors = [mockError];
|
|
serverStore.updateOsResponse = {
|
|
version: '6.13.0',
|
|
isNewer: true,
|
|
isEligible: true,
|
|
} as ServerUpdateOsResponse;
|
|
serverStore.rebootType = '';
|
|
|
|
await nextTick();
|
|
|
|
expect(findUpdateStatusComponent()).toBeNull();
|
|
});
|
|
});
|