@@ -10,7 +10,12 @@ import { useBoardStore } from "@/modules/data/board/Board.store";
1010import { ParentNodeInfo , ParentNodeType } from "@/types/board/ContentElement" ;
1111import { FileRecordParent } from "@/types/file/File" ;
1212import * as FileHelper from "@/utils/fileHelper" ;
13- import { fileRecordFactory , mockedPiniaStoreTyping , parentNodeInfoFactory } from "@@/tests/test-utils" ;
13+ import {
14+ boardResponseFactory ,
15+ fileRecordFactory ,
16+ mockedPiniaStoreTyping ,
17+ parentNodeInfoFactory ,
18+ } from "@@/tests/test-utils" ;
1419import { createTestingI18n , createTestingVuetify } from "@@/tests/test-utils/setup" ;
1520import * as BoardApi from "@data-board" ;
1621import * as FileStorageApi from "@data-file" ;
@@ -76,7 +81,7 @@ describe("Folder.vue", () => {
7681 describe ( "when user has board edit permission" , ( ) => {
7782 describe ( "when folder contains no files" , ( ) => {
7883 describe ( "when component is loaded" , ( ) => {
79- const setup = async ( ) => {
84+ const setup = async ( boardInStoreUndefined = false , boardInStoreIsParent = true ) => {
8085 const folderStateMock = createMock < ReturnType < typeof FolderState . useFolderState > > ( ) ;
8186 vi . spyOn ( FolderState , "useFolderState" ) . mockReturnValueOnce ( folderStateMock ) ;
8287
@@ -107,6 +112,10 @@ describe("Folder.vue", () => {
107112
108113 const { wrapper } = setupWrapper ( ) ;
109114 const useBoardStoreMock = mockedPiniaStoreTyping ( useBoardStore ) ;
115+ const board = boardResponseFactory . build ( {
116+ id : boardInStoreIsParent ? parent . id : "different-board-id" ,
117+ } ) ;
118+ useBoardStoreMock . board = boardInStoreUndefined ? undefined : board ;
110119
111120 await nextTick ( ) ;
112121 await nextTick ( ) ;
@@ -135,14 +144,6 @@ describe("Folder.vue", () => {
135144 expect ( fileStorageApiMock . fetchFiles ) . toHaveBeenCalled ( ) ;
136145 } ) ;
137146
138- it ( "should call fetchBoardRequest" , async ( ) => {
139- const { useBoardStoreMock, parent } = await setup ( ) ;
140-
141- expect ( useBoardStoreMock . fetchBoardRequest ) . toHaveBeenCalledWith ( {
142- boardId : parent . id ,
143- } ) ;
144- } ) ;
145-
146147 it ( "should not show the loading spinner" , async ( ) => {
147148 const { wrapper } = await setup ( ) ;
148149
@@ -164,6 +165,31 @@ describe("Folder.vue", () => {
164165 expect ( includesFolderName ) . toBe ( true ) ;
165166 } ) ;
166167
168+ describe ( "when board is not in store" , ( ) => {
169+ it ( "should call fetchBoardRequest" , async ( ) => {
170+ const { useBoardStoreMock, parent } = await setup ( true ) ;
171+
172+ expect ( useBoardStoreMock . fetchBoardRequest ) . toHaveBeenCalledWith ( {
173+ boardId : parent . id ,
174+ } ) ;
175+ } ) ;
176+ } ) ;
177+ describe ( "when board in store is not the same as parent" , ( ) => {
178+ it ( "should call fetchBoardRequest" , async ( ) => {
179+ const { useBoardStoreMock, parent } = await setup ( false , false ) ;
180+
181+ expect ( useBoardStoreMock . fetchBoardRequest ) . toHaveBeenCalledWith ( {
182+ boardId : parent . id ,
183+ } ) ;
184+ } ) ;
185+ } ) ;
186+ describe ( "when board in store is the same as parent" , ( ) => {
187+ it ( "should not call fetchBoardRequest" , async ( ) => {
188+ const { useBoardStoreMock } = await setup ( false , true ) ;
189+
190+ expect ( useBoardStoreMock . fetchBoardRequest ) . not . toHaveBeenCalled ( ) ;
191+ } ) ;
192+ } ) ;
167193 describe ( "when folder is board" , ( ) => {
168194 it ( "should call createPageInformation with the correct parentId" , async ( ) => {
169195 const { boardState, parent } = await setup ( ) ;
0 commit comments