11/*
2- * Copyright (c) [2022-2024 ] SUSE LLC
2+ * Copyright (c) [2022-2026 ] SUSE LLC
33 *
44 * All Rights Reserved.
55 *
2323import React from "react" ;
2424import { screen } from "@testing-library/react" ;
2525import { plainRender } from "~/test-utils" ;
26- import InstallationFinished from "./InstallationFinished" ;
2726import type { Storage } from "~/model/config" ;
27+ import InstallationFinished from "~/components/core/InstallationFinished" ;
28+
29+ jest . mock ( "~/components/core/InstallerOptions" , ( ) => ( ) => < div > Installer Options</ div > ) ;
2830
2931jest . mock ( "~/queries/status" , ( ) => ( {
3032 ...jest . requireActual ( "~/queries/status" ) ,
@@ -38,8 +40,7 @@ type guidedEncryption = {
3840 pbkdFunction ?: string ;
3941} ;
4042
41- let mockEncryption : undefined | Storage . Encryption | guidedEncryption ;
42- let mockType : storageConfigType ;
43+ const mockUseExtendedConfigFn = jest . fn ( ) ;
4344
4445const mockStorageConfig = (
4546 type : storageConfigType ,
@@ -51,56 +52,57 @@ const mockStorageConfig = (
5152 switch ( type ) {
5253 case "guided" :
5354 return {
54- guided : {
55- ...encryptionHash ,
55+ storage : {
56+ guided : {
57+ ...encryptionHash ,
58+ } ,
5659 } ,
5760 } ;
5861 case "raw" :
5962 return {
60- drives : [
61- {
62- partitions : [
63- {
64- filesystem : {
65- path : "/" ,
63+ storage : {
64+ drives : [
65+ {
66+ partitions : [
67+ {
68+ filesystem : {
69+ path : "/" ,
70+ } ,
71+ id : "linux" ,
72+ ...encryptionHash ,
6673 } ,
67- id : "linux" ,
68- ... encryptionHash ,
69- } ,
70- {
71- filesystem : {
72- mountBy : "uuid" ,
73- path : "swap" ,
74- type : "swap " ,
74+ {
75+ filesystem : {
76+ mountBy : "uuid" ,
77+ path : "swap" ,
78+ type : "swap" ,
79+ } ,
80+ id : "swap" ,
81+ size : "2 GiB " ,
7582 } ,
76- id : "swap" ,
77- size : "2 GiB" ,
78- } ,
79- ] ,
80- } ,
81- ] ,
83+ ] ,
84+ } ,
85+ ] ,
86+ } ,
8287 } ;
8388 }
8489} ;
8590
86- jest . mock ( "~/queries/storage " , ( ) => ( {
87- ...jest . requireActual ( "~/queries/storage " ) ,
88- useConfig : ( ) => mockStorageConfig ( mockType , mockEncryption ) ,
91+ jest . mock ( "~/hooks/model/config " , ( ) => ( {
92+ ...jest . requireActual ( "~/hooks/model/config " ) ,
93+ useExtendedConfig : ( ) => mockUseExtendedConfigFn ( ) ,
8994} ) ) ;
9095
9196const mockFinishInstallation = jest . fn ( ) ;
9297
93- jest . mock ( "~/api /manager" , ( ) => ( {
94- ...jest . requireActual ( "~/api /manager" ) ,
98+ jest . mock ( "~/model /manager" , ( ) => ( {
99+ ...jest . requireActual ( "~/model /manager" ) ,
95100 finishInstallation : ( ) => mockFinishInstallation ( ) ,
96101} ) ) ;
97102
98- jest . mock ( "~/components/core/InstallerOptions" , ( ) => ( ) => < div > Installer Options</ div > ) ;
99-
100103describe ( "InstallationFinished" , ( ) => {
101104 beforeEach ( ( ) => {
102- mockEncryption = null ;
103- mockType = "guided" ;
105+ mockUseExtendedConfigFn . mockReturnValue ( mockStorageConfig ( "guided" , null ) ) ;
104106 } ) ;
105107
106108 it ( "shows the finished installation screen" , ( ) => {
@@ -122,16 +124,18 @@ describe("InstallationFinished", () => {
122124
123125 describe ( "when running storage config in raw mode" , ( ) => {
124126 beforeEach ( ( ) => {
125- mockType = "raw" ;
127+ mockUseExtendedConfigFn . mockReturnValue ( mockStorageConfig ( "raw" , null ) ) ;
126128 } ) ;
127129
128130 describe ( "when TPM is set as encryption method" , ( ) => {
129131 beforeEach ( ( ) => {
130- mockEncryption = {
131- tpmFde : {
132- password : "n0tS3cr3t" ,
133- } ,
134- } ;
132+ mockUseExtendedConfigFn . mockReturnValue (
133+ mockStorageConfig ( "raw" , {
134+ tpmFde : {
135+ password : "n0tS3cr3t" ,
136+ } ,
137+ } ) ,
138+ ) ;
135139 } ) ;
136140
137141 it ( "shows the TPM reminder" , async ( ) => {
@@ -141,6 +145,10 @@ describe("InstallationFinished", () => {
141145 } ) ;
142146
143147 describe ( "when TPM is not set as encryption method" , ( ) => {
148+ beforeEach ( ( ) => {
149+ mockUseExtendedConfigFn . mockReturnValue ( mockStorageConfig ( "raw" , null ) ) ;
150+ } ) ;
151+
144152 it ( "does not show the TPM reminder" , async ( ) => {
145153 plainRender ( < InstallationFinished /> ) ;
146154 expect ( screen . queryAllByText ( / T P M / ) ) . toHaveLength ( 0 ) ;
@@ -151,10 +159,12 @@ describe("InstallationFinished", () => {
151159 describe ( "when running storage config in guided mode" , ( ) => {
152160 describe ( "when TPM is set as encryption method" , ( ) => {
153161 beforeEach ( ( ) => {
154- mockEncryption = {
155- method : "tpm_fde" ,
156- password : "n0tS3cr3t" ,
157- } ;
162+ mockUseExtendedConfigFn . mockReturnValue (
163+ mockStorageConfig ( "guided" , {
164+ method : "tpm_fde" ,
165+ password : "n0tS3cr3t" ,
166+ } ) ,
167+ ) ;
158168 } ) ;
159169
160170 it ( "shows the TPM reminder" , async ( ) => {
@@ -164,6 +174,10 @@ describe("InstallationFinished", () => {
164174 } ) ;
165175
166176 describe ( "when TPM is not set as encryption method" , ( ) => {
177+ beforeEach ( ( ) => {
178+ mockUseExtendedConfigFn . mockReturnValue ( mockStorageConfig ( "guided" , null ) ) ;
179+ } ) ;
180+
167181 it ( "does not show the TPM reminder" , async ( ) => {
168182 plainRender ( < InstallationFinished /> ) ;
169183 expect ( screen . queryAllByText ( / T P M / ) ) . toHaveLength ( 0 ) ;
0 commit comments