mirror of
https://github.com/unraid/api.git
synced 2026-05-18 23:19:24 -05:00
feat(tests): add tests for fresh install state in activationCodeData
- Introduced new test cases in `activationCodeData.test.ts` to verify that `isFreshInstall` is computed as true for registration states `ENOKEYFILE1` and `ENOKEYFILE2`. - Updated the logic in `activationCodeData.ts` to ensure `isFreshInstall` correctly checks for registration states starting with 'ENOKEYFILE', enhancing the accuracy of the state management. These changes improve test coverage and ensure the correct behavior of the activation code data store in various onboarding scenarios.
This commit is contained in:
@@ -35,7 +35,9 @@ export class OnboardingStateService {
|
||||
if (!regState) {
|
||||
return false;
|
||||
}
|
||||
return String(regState).startsWith('ENOKEYFILE');
|
||||
// Only ENOKEYFILE (without number suffix) indicates a fresh install.
|
||||
// ENOKEYFILE1 and ENOKEYFILE2 are error states that can occur on existing installations.
|
||||
return regState === RegistrationState.ENOKEYFILE;
|
||||
}
|
||||
|
||||
isRegistered(regState: RegistrationState | undefined = this.getRegistrationState()): boolean {
|
||||
|
||||
@@ -105,13 +105,16 @@ describe('ActivationCodeData Store', () => {
|
||||
expect(store.activationCode).toBe(mockActivationCode);
|
||||
});
|
||||
|
||||
it('should compute isFreshInstall as true when regState is ENOKEYFILE', () => {
|
||||
it('should compute isFreshInstall from backend when regState is ENOKEYFILE', () => {
|
||||
vi.mocked(useQuery).mockImplementation((query) => {
|
||||
if (query === ACTIVATION_CODE_QUERY) {
|
||||
return createCompleteQueryMock(
|
||||
{
|
||||
customization: {
|
||||
onboardingState: { registrationState: RegistrationState.ENOKEYFILE },
|
||||
onboardingState: {
|
||||
registrationState: RegistrationState.ENOKEYFILE,
|
||||
isFreshInstall: true, // Backend determines this value
|
||||
},
|
||||
},
|
||||
},
|
||||
false
|
||||
@@ -126,13 +129,16 @@ describe('ActivationCodeData Store', () => {
|
||||
expect(store.isFreshInstall).toBe(true);
|
||||
});
|
||||
|
||||
it('should compute isFreshInstall as false when regState is not ENOKEYFILE', () => {
|
||||
it('should compute isFreshInstall from backend when regState is ENOKEYFILE1', () => {
|
||||
vi.mocked(useQuery).mockImplementation((query) => {
|
||||
if (query === ACTIVATION_CODE_QUERY) {
|
||||
return createCompleteQueryMock(
|
||||
{
|
||||
customization: {
|
||||
onboardingState: { registrationState: 'REGISTERED' as RegistrationState },
|
||||
onboardingState: {
|
||||
registrationState: RegistrationState.ENOKEYFILE1,
|
||||
isFreshInstall: false, // Backend determines this value
|
||||
},
|
||||
},
|
||||
},
|
||||
false
|
||||
@@ -147,6 +153,62 @@ describe('ActivationCodeData Store', () => {
|
||||
expect(store.isFreshInstall).toBe(false);
|
||||
});
|
||||
|
||||
it('should compute isFreshInstall from backend when regState is ENOKEYFILE2', () => {
|
||||
vi.mocked(useQuery).mockImplementation((query) => {
|
||||
if (query === ACTIVATION_CODE_QUERY) {
|
||||
return createCompleteQueryMock(
|
||||
{
|
||||
customization: {
|
||||
onboardingState: {
|
||||
registrationState: RegistrationState.ENOKEYFILE2,
|
||||
isFreshInstall: false, // Backend determines this value
|
||||
},
|
||||
},
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
return createCompleteQueryMock(null, false);
|
||||
});
|
||||
|
||||
const store = useActivationCodeDataStore();
|
||||
|
||||
expect(store.isFreshInstall).toBe(false);
|
||||
});
|
||||
|
||||
it('should compute isFreshInstall from backend when regState is not ENOKEYFILE', () => {
|
||||
vi.mocked(useQuery).mockImplementation((query) => {
|
||||
if (query === ACTIVATION_CODE_QUERY) {
|
||||
return createCompleteQueryMock(
|
||||
{
|
||||
customization: {
|
||||
onboardingState: {
|
||||
registrationState: 'REGISTERED' as RegistrationState,
|
||||
isFreshInstall: false, // Backend determines this value
|
||||
},
|
||||
},
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
return createCompleteQueryMock(null, false);
|
||||
});
|
||||
|
||||
const store = useActivationCodeDataStore();
|
||||
|
||||
expect(store.isFreshInstall).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for isFreshInstall when onboardingState is null (query not loaded)', () => {
|
||||
vi.mocked(useQuery).mockImplementation(() => createCompleteQueryMock(null, false));
|
||||
|
||||
const store = useActivationCodeDataStore();
|
||||
|
||||
expect(store.isFreshInstall).toBe(false);
|
||||
});
|
||||
|
||||
it('should use publicPartnerInfo when available', () => {
|
||||
const mockPublicPartnerInfo = { name: 'Public Partner' };
|
||||
vi.mocked(useQuery).mockImplementation((query) => {
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
ACTIVATION_CODE_QUERY,
|
||||
PARTNER_INFO_QUERY,
|
||||
} from '~/components/Activation/graphql/activationCode.query';
|
||||
import { RegistrationState } from '~/composables/gql/graphql';
|
||||
|
||||
export const useActivationCodeDataStore = defineStore('activationCodeData', () => {
|
||||
const { result: activationCodeResult, loading: activationCodeLoading } = useQuery(
|
||||
@@ -26,12 +25,7 @@ export const useActivationCodeDataStore = defineStore('activationCodeData', () =
|
||||
|
||||
const registrationState = computed(() => onboardingState.value?.registrationState ?? null);
|
||||
|
||||
const isFreshInstall = computed(() => {
|
||||
if (onboardingState.value?.isFreshInstall != null) {
|
||||
return onboardingState.value.isFreshInstall;
|
||||
}
|
||||
return registrationState.value === RegistrationState.ENOKEYFILE;
|
||||
});
|
||||
const isFreshInstall = computed(() => onboardingState.value?.isFreshInstall ?? false);
|
||||
|
||||
/**
|
||||
* Public Partner Info becomes null when the user has set a password, so we fall back to the partnerInfo from the activation code
|
||||
@@ -45,12 +39,7 @@ export const useActivationCodeDataStore = defineStore('activationCodeData', () =
|
||||
|
||||
const activationRequired = computed(() => onboardingState.value?.activationRequired ?? false);
|
||||
|
||||
const hasActivationCode = computed(() => {
|
||||
if (onboardingState.value?.hasActivationCode != null) {
|
||||
return onboardingState.value.hasActivationCode;
|
||||
}
|
||||
return Boolean(activationCode.value?.code);
|
||||
});
|
||||
const hasActivationCode = computed(() => onboardingState.value?.hasActivationCode ?? false);
|
||||
|
||||
const isRegistered = computed(() => onboardingState.value?.isRegistered ?? false);
|
||||
|
||||
|
||||
@@ -398,14 +398,14 @@ function handleLogRefresh() {
|
||||
logViewerRef.value?.refreshLogContent();
|
||||
}
|
||||
|
||||
const [transitionContainerRef] = useAutoAnimate({
|
||||
const [_transitionContainerRef] = useAutoAnimate({
|
||||
duration: 200,
|
||||
easing: 'ease-in-out',
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="transitionContainerRef">
|
||||
<div ref="_transitionContainerRef">
|
||||
<div v-if="!activeId">
|
||||
<template v-if="viewMode === 'overview'">
|
||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
|
||||
@@ -31,7 +31,7 @@ const emit = defineEmits<{
|
||||
'update:modelValue': [value: boolean];
|
||||
}>();
|
||||
|
||||
const logViewerRef = ref<InstanceType<typeof SingleLogViewer> | null>(null);
|
||||
const _logViewerRef = ref<InstanceType<typeof SingleLogViewer> | null>(null);
|
||||
|
||||
const fullLogPath = computed(() => {
|
||||
if (props.logFilePath.startsWith('/')) {
|
||||
@@ -56,7 +56,7 @@ const handleOpenChange = (open: boolean) => {
|
||||
>
|
||||
<div class="flex h-[600px] flex-col">
|
||||
<SingleLogViewer
|
||||
ref="logViewerRef"
|
||||
ref="_logViewerRef"
|
||||
:log-file-path="fullLogPath"
|
||||
:line-count="lineCount"
|
||||
:auto-scroll="autoScroll"
|
||||
|
||||
@@ -17,7 +17,7 @@ const emit = defineEmits<{
|
||||
close: [];
|
||||
}>();
|
||||
|
||||
const iframeRef = ref<HTMLIFrameElement | null>(null);
|
||||
const _iframeRef = ref<HTMLIFrameElement | null>(null);
|
||||
const isLoading = ref(true);
|
||||
|
||||
const releaseNotesUrl = computed(() => {
|
||||
@@ -58,7 +58,7 @@ const handleClose = () => {
|
||||
<!-- iframe for release notes -->
|
||||
<div class="-mx-6 -my-6 h-[75vh] max-h-[800px] w-[calc(100%+3rem)]">
|
||||
<iframe
|
||||
ref="iframeRef"
|
||||
ref="_iframeRef"
|
||||
:src="releaseNotesUrl"
|
||||
class="h-full w-full rounded-md border-0"
|
||||
sandbox="allow-scripts allow-same-origin"
|
||||
|
||||
Reference in New Issue
Block a user