Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 180 additions & 55 deletions web/__test__/components/Onboarding/OnboardingInternalBootStep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { flushPromises, mount } from '@vue/test-utils';

import { beforeEach, describe, expect, it, vi } from 'vitest';

import type { GetInternalBootContextQuery } from '~/composables/gql/graphql';

import OnboardingInternalBootStep from '~/components/Onboarding/steps/OnboardingInternalBootStep.vue';
import {
ArrayState,
DiskInterfaceType,
GetInternalBootContextDocument,
} from '~/composables/gql/graphql';
import { createTestI18n } from '../../utils/i18n';

type MockInternalBootSelection = {
Expand All @@ -13,30 +20,7 @@ type MockInternalBootSelection = {
updateBios: boolean;
};

type MockContext = {
array: {
state?: string | null;
boot?: { device?: string | null } | null;
parities: Array<{ device?: string | null }>;
disks: Array<{ device?: string | null }>;
caches: Array<{ name?: string | null; device?: string | null }>;
};
vars?: {
fsState?: string | null;
bootEligible?: boolean | null;
enableBootTransfer?: string | null;
reservedNames?: string | null;
} | null;
shares: Array<{ name?: string | null }>;
disks: Array<{
device: string;
size: number;
emhttpDeviceId?: string | null;
interfaceType?: string | null;
}>;
};

const { draftStore, contextResult, contextLoading, contextError } = vi.hoisted(() => {
const { draftStore, contextResult, contextLoading, contextError, useQueryMock } = vi.hoisted(() => {
const store = {
bootMode: 'usb' as 'usb' | 'storage',
internalBootSelection: null as MockInternalBootSelection | null,
Expand All @@ -54,9 +38,10 @@ const { draftStore, contextResult, contextLoading, contextError } = vi.hoisted((

return {
draftStore: store,
contextResult: { value: null as MockContext | null, __v_isRef: true },
contextResult: { value: null as GetInternalBootContextQuery | null, __v_isRef: true },
contextLoading: { value: false, __v_isRef: true },
contextError: { value: null as unknown, __v_isRef: true },
useQueryMock: vi.fn(),
};
});

Expand All @@ -70,11 +55,13 @@ vi.mock('@unraid/ui', () => ({
}));

vi.mock('@vue/apollo-composable', () => ({
useQuery: () => ({
result: contextResult,
loading: contextLoading,
error: contextError,
}),
useQuery: useQueryMock,
}));

useQueryMock.mockImplementation(() => ({
result: contextResult,
loading: contextLoading,
error: contextError,
}));

vi.mock('@/components/Onboarding/store/onboardingDraft', () => ({
Expand Down Expand Up @@ -108,7 +95,7 @@ describe('OnboardingInternalBootStep', () => {
draftStore.bootMode = 'storage';
contextResult.value = {
array: {
state: 'STARTED',
state: ArrayState.STARTED,
boot: { device: '/dev/sda' },
parities: [{ device: '/dev/sdb' }],
disks: [{ device: '/dev/sdc' }],
Expand All @@ -122,12 +109,48 @@ describe('OnboardingInternalBootStep', () => {
},
shares: [],
disks: [
{ device: '/dev/sda', size: gib(32), emhttpDeviceId: 'boot-disk', interfaceType: 'SATA' },
{ device: '/dev/sdb', size: gib(32), emhttpDeviceId: 'parity-disk', interfaceType: 'SATA' },
{ device: '/dev/sdc', size: gib(32), emhttpDeviceId: 'array-disk', interfaceType: 'SATA' },
{ device: '/dev/sdd', size: gib(32), emhttpDeviceId: 'cache-disk', interfaceType: 'SATA' },
{ device: '/dev/sde', size: gib(6), emhttpDeviceId: 'small-disk', interfaceType: 'SATA' },
{ device: '/dev/sdf', size: gib(32), emhttpDeviceId: 'usb-disk', interfaceType: 'USB' },
{
device: '/dev/sda',
size: gib(32),
serialNum: 'BOOT-1',
emhttpDeviceId: 'boot-disk',
interfaceType: DiskInterfaceType.SATA,
},
{
device: '/dev/sdb',
size: gib(32),
serialNum: 'PARITY-1',
emhttpDeviceId: 'parity-disk',
interfaceType: DiskInterfaceType.SATA,
},
{
device: '/dev/sdc',
size: gib(32),
serialNum: 'ARRAY-1',
emhttpDeviceId: 'array-disk',
interfaceType: DiskInterfaceType.SATA,
},
{
device: '/dev/sdd',
size: gib(32),
serialNum: 'CACHE-1',
emhttpDeviceId: 'cache-disk',
interfaceType: DiskInterfaceType.SATA,
},
{
device: '/dev/sde',
size: gib(6),
serialNum: 'SMALL-1',
emhttpDeviceId: 'small-disk',
interfaceType: DiskInterfaceType.SATA,
},
{
device: '/dev/sdf',
size: gib(32),
serialNum: 'USB-1',
emhttpDeviceId: 'usb-disk',
interfaceType: DiskInterfaceType.USB,
},
],
};

Expand All @@ -152,11 +175,59 @@ describe('OnboardingInternalBootStep', () => {
expect(wrapper.find('[data-testid="brand-button"]').attributes('disabled')).toBeDefined();
});

it('loads internal boot context from the network when the step mounts', async () => {
mountComponent();
await flushPromises();

expect(useQueryMock).toHaveBeenCalledWith(
GetInternalBootContextDocument,
null,
expect.objectContaining({
fetchPolicy: 'network-only',
})
);
});

it('shows drive serials in the selectable device labels', async () => {
draftStore.bootMode = 'storage';
contextResult.value = {
array: {
state: ArrayState.STOPPED,
boot: null,
parities: [],
disks: [],
caches: [],
},
vars: {
fsState: 'Stopped',
bootEligible: true,
enableBootTransfer: 'yes',
reservedNames: '',
},
shares: [],
disks: [
{
device: '/dev/sda',
size: gib(32),
serialNum: 'WD-TEST-1234',
emhttpDeviceId: 'eligible-disk',
interfaceType: DiskInterfaceType.SATA,
},
],
};

const wrapper = mountComponent();
await flushPromises();

expect(wrapper.text()).toContain('WD-TEST-1234 - 32.0 GB (sda)');
expect(wrapper.text()).not.toContain('eligible-disk - 32.0 GB (sda)');
});

it('defaults the storage pool name to cache', async () => {
draftStore.bootMode = 'storage';
contextResult.value = {
array: {
state: 'STOPPED',
state: ArrayState.STOPPED,
boot: null,
parities: [],
disks: [],
Expand All @@ -170,7 +241,13 @@ describe('OnboardingInternalBootStep', () => {
},
shares: [],
disks: [
{ device: '/dev/sda', size: gib(32), emhttpDeviceId: 'eligible-disk', interfaceType: 'SATA' },
{
device: '/dev/sda',
size: gib(32),
serialNum: 'ELIGIBLE-1',
emhttpDeviceId: 'eligible-disk',
interfaceType: DiskInterfaceType.SATA,
},
],
};

Expand All @@ -188,7 +265,7 @@ describe('OnboardingInternalBootStep', () => {
draftStore.bootMode = 'storage';
contextResult.value = {
array: {
state: 'STOPPED',
state: ArrayState.STOPPED,
boot: null,
parities: [],
disks: [],
Expand All @@ -202,7 +279,13 @@ describe('OnboardingInternalBootStep', () => {
},
shares: [],
disks: [
{ device: '/dev/sda', size: gib(32), emhttpDeviceId: 'eligible-disk', interfaceType: 'SATA' },
{
device: '/dev/sda',
size: gib(32),
serialNum: 'ELIGIBLE-1',
emhttpDeviceId: 'eligible-disk',
interfaceType: DiskInterfaceType.SATA,
},
],
};

Expand All @@ -216,7 +299,7 @@ describe('OnboardingInternalBootStep', () => {
draftStore.bootMode = 'storage';
contextResult.value = {
array: {
state: 'STOPPED',
state: ArrayState.STOPPED,
boot: { device: '/dev/sda' },
parities: [{ device: '/dev/sdb' }],
disks: [],
Expand All @@ -230,8 +313,20 @@ describe('OnboardingInternalBootStep', () => {
},
shares: [],
disks: [
{ device: '/dev/sda', size: gib(32), emhttpDeviceId: 'boot-disk', interfaceType: 'SATA' },
{ device: '/dev/sdb', size: gib(32), emhttpDeviceId: 'parity-disk', interfaceType: 'SATA' },
{
device: '/dev/sda',
size: gib(32),
serialNum: 'BOOT-1',
emhttpDeviceId: 'boot-disk',
interfaceType: DiskInterfaceType.SATA,
},
{
device: '/dev/sdb',
size: gib(32),
serialNum: 'PARITY-1',
emhttpDeviceId: 'parity-disk',
interfaceType: DiskInterfaceType.SATA,
},
],
};

Expand All @@ -250,7 +345,7 @@ describe('OnboardingInternalBootStep', () => {
draftStore.bootMode = 'storage';
contextResult.value = {
array: {
state: 'STARTED',
state: ArrayState.STARTED,
boot: null,
parities: [],
disks: [],
Expand All @@ -264,7 +359,13 @@ describe('OnboardingInternalBootStep', () => {
},
shares: [],
disks: [
{ device: '/dev/sda', size: gib(32), emhttpDeviceId: 'eligible-disk', interfaceType: 'SATA' },
{
device: '/dev/sda',
size: gib(32),
serialNum: 'ELIGIBLE-1',
emhttpDeviceId: 'eligible-disk',
interfaceType: DiskInterfaceType.SATA,
},
],
};

Expand All @@ -280,7 +381,7 @@ describe('OnboardingInternalBootStep', () => {
draftStore.bootMode = 'storage';
contextResult.value = {
array: {
state: 'STOPPED',
state: ArrayState.STOPPED,
boot: null,
parities: [],
disks: [],
Expand All @@ -294,10 +395,34 @@ describe('OnboardingInternalBootStep', () => {
},
shares: [],
disks: [
{ device: '/dev/sda', size: gib(32), emhttpDeviceId: 'cache-disk', interfaceType: 'SATA' },
{ device: '/dev/sdb', size: gib(6), emhttpDeviceId: 'small-disk', interfaceType: 'SATA' },
{ device: '/dev/sdc', size: gib(32), emhttpDeviceId: 'eligible-disk', interfaceType: 'SATA' },
{ device: '/dev/sdd', size: gib(32), emhttpDeviceId: 'usb-disk', interfaceType: 'USB' },
{
device: '/dev/sda',
size: gib(32),
serialNum: 'CACHE-1',
emhttpDeviceId: 'cache-disk',
interfaceType: DiskInterfaceType.SATA,
},
{
device: '/dev/sdb',
size: gib(6),
serialNum: 'SMALL-1',
emhttpDeviceId: 'small-disk',
interfaceType: DiskInterfaceType.SATA,
},
{
device: '/dev/sdc',
size: gib(32),
serialNum: 'ELIGIBLE-1',
emhttpDeviceId: 'eligible-disk',
interfaceType: DiskInterfaceType.SATA,
},
{
device: '/dev/sdd',
size: gib(32),
serialNum: 'USB-1',
emhttpDeviceId: 'usb-disk',
interfaceType: DiskInterfaceType.USB,
},
],
};

Expand All @@ -308,10 +433,10 @@ describe('OnboardingInternalBootStep', () => {
const selects = wrapper.findAll('select');
expect(selects).toHaveLength(3);
const deviceSelect = selects[1];
expect(deviceSelect.text()).toContain('eligible-disk');
expect(deviceSelect.text()).toContain('usb-disk');
expect(deviceSelect.text()).not.toContain('cache-disk');
expect(deviceSelect.text()).not.toContain('small-disk');
expect(deviceSelect.text()).toContain('ELIGIBLE-1');
expect(deviceSelect.text()).toContain('USB-1');
expect(deviceSelect.text()).not.toContain('CACHE-1');
expect(deviceSelect.text()).not.toContain('SMALL-1');
expect(wrapper.text()).not.toContain('ASSIGNED_TO_CACHE');
const biosWarning = wrapper.get('[data-testid="internal-boot-update-bios-warning"]');
const eligibilityPanel = wrapper.get('[data-testid="internal-boot-eligibility-panel"]');
Expand Down
Loading
Loading