@@ -3,13 +3,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
33import { createVuetify } from "vuetify" ;
44import { createStore } from "vuex" ;
55import AdvancedSearchResultTable from "@/views/AdvancedSearch/AdvancedSearchResultTable.vue" ;
6- import advancedSearch from "@/store" ;
7-
8- vi . mock ( "@/store" , ( ) => ( {
9- default : {
10- commit : vi . fn ( ) ,
11- } ,
12- } ) ) ;
136
147vi . mock ( "@/utils/recordsCardUtils" , ( ) => ( {
158 default : {
@@ -26,7 +19,6 @@ describe("AdvancedSearchResultTable.vue", () => {
2619 let store ;
2720 let vuetify ;
2821 let mockFetchAction ;
29- let originalLocation ;
3022
3123 const mockRoute = { query : { } } ;
3224
@@ -44,13 +36,19 @@ describe("AdvancedSearchResultTable.vue", () => {
4436 getterOverrides . query || { fields : [ ] } ,
4537 } ,
4638 actions : { fetchAdvancedSearchResults : mockFetchAction } ,
39+ mutations : {
40+ setEditAdvancedSearch : vi . fn ( ) ,
41+ setAdvancedSearch : vi . fn ( ) ,
42+ } ,
4743 } ,
4844 } ,
4945 } ) ;
5046 } ;
5147
5248 const mountComponent = ( getters = { } , routeQuery = { } ) => {
5349 store = createVuexStore ( getters ) ;
50+ vi . spyOn ( store , "commit" ) ;
51+
5452 vuetify = createVuetify ( ) ;
5553 mockRoute . query = routeQuery ;
5654
@@ -69,14 +67,15 @@ describe("AdvancedSearchResultTable.vue", () => {
6967 beforeEach ( ( ) => {
7068 vi . clearAllMocks ( ) ;
7169 global . URL . createObjectURL = vi . fn ( ( ) => "blob:mock-url" ) ;
72- originalLocation = window . location ;
73- delete window . location ;
74- window . location = { href : "" } ;
70+
71+ vi . stubGlobal ( "location" , {
72+ href : "" ,
73+ } ) ;
7574 } ) ;
7675
7776 afterEach ( ( ) => {
7877 if ( wrapper ) wrapper . unmount ( ) ;
79- window . location = originalLocation ;
78+ vi . unstubAllGlobals ( ) ;
8079 } ) ;
8180
8281 it ( "renders ErrorPage when getErrorStatus is true" , ( ) => {
@@ -94,11 +93,9 @@ describe("AdvancedSearchResultTable.vue", () => {
9493 // --- COMPUTED PROPERTY TESTS ---
9594
9695 it ( "computes noPagination correctly" , ( ) => {
97- // Empty array = true (no pagination)
9896 wrapper = mountComponent ( { response : [ ] } ) ;
9997 expect ( wrapper . vm . noPagination ) . toBe ( true ) ;
10098
101- // Array with items = false (show pagination)
10299 wrapper = mountComponent ( { response : [ { id : 1 } ] } ) ;
103100 expect ( wrapper . vm . noPagination ) . toBe ( false ) ;
104101 } ) ;
@@ -121,6 +118,7 @@ describe("AdvancedSearchResultTable.vue", () => {
121118 wrapper . vm . sortDesc = false ;
122119 expect ( wrapper . vm . sortData ) . toEqual ( [ { key : "registry" , order : "asc" } ] ) ;
123120 } ) ;
121+
124122 it ( "computes sortData correctly for Type" , ( ) => {
125123 wrapper = mountComponent ( ) ;
126124 wrapper . vm . sortBy = "Type" ;
@@ -130,6 +128,7 @@ describe("AdvancedSearchResultTable.vue", () => {
130128 wrapper . vm . sortDesc = false ;
131129 expect ( wrapper . vm . sortData ) . toEqual ( [ { key : "type" , order : "asc" } ] ) ;
132130 } ) ;
131+
133132 it ( "computes sortData correctly for Status" , ( ) => {
134133 wrapper = mountComponent ( ) ;
135134 wrapper . vm . sortBy = "Status" ;
@@ -139,6 +138,7 @@ describe("AdvancedSearchResultTable.vue", () => {
139138 wrapper . vm . sortDesc = false ;
140139 expect ( wrapper . vm . sortData ) . toEqual ( [ { key : "status" , order : "asc" } ] ) ;
141140 } ) ;
141+
142142 it ( "computes sortData correctly for Description" , ( ) => {
143143 wrapper = mountComponent ( ) ;
144144 wrapper . vm . sortBy = "Description" ;
@@ -170,13 +170,10 @@ describe("AdvancedSearchResultTable.vue", () => {
170170 ] ;
171171 wrapper = mountComponent ( { response : mockData } ) ;
172172
173- // Trigger the download
174173 wrapper . vm . downloadResults ( ) ;
175174
176- // Verify Blob creation
177175 expect ( global . URL . createObjectURL ) . toHaveBeenCalled ( ) ;
178-
179- // Verify it assigned the mocked blob URL to the window location
176+ // Verify our stub location URL caught the payload assignment
180177 expect ( window . location . href ) . toBe ( "blob:mock-url" ) ;
181178 } ) ;
182179
@@ -186,47 +183,41 @@ describe("AdvancedSearchResultTable.vue", () => {
186183 wrapper . vm . recordPublicationsLength ( { publications : [ 1 , 2 , 3 ] } ) ,
187184 ) . toBe ( 3 ) ;
188185 expect ( wrapper . vm . recordPublicationsLength ( { publications : [ ] } ) ) . toBe ( 0 ) ;
189- expect ( wrapper . vm . recordPublicationsLength ( { } ) ) . toBe ( 0 ) ; // missing property
186+ expect ( wrapper . vm . recordPublicationsLength ( { } ) ) . toBe ( 0 ) ;
190187 } ) ;
191188
192189 it ( "parses URL query parameters and dispatches store actions on mount" , ( ) => {
193- // We must provide a string formatted exactly how fetchQueryParams expects it
194190 const testRouteQuery = {
195191 operator : "AND" ,
196192 fields : "(operator=OR®istry=true+false)" ,
197193 q : "searchterm" ,
198194 } ;
199195
200- // Mount triggers mounted(), which calls fetchQueryParams()
201196 wrapper = mountComponent (
202- { response : [ ] , query : { fields : [ ] } } , // Ensure requirements to run the if-block are met
197+ { response : [ ] , query : { fields : [ ] } } ,
203198 testRouteQuery ,
204199 ) ;
205200
206- // 1. Check direct store commits
207- expect ( advancedSearch . commit ) . toHaveBeenCalledWith (
201+ expect ( store . commit ) . toHaveBeenCalledWith (
208202 "advancedSearch/setAdvancedSearch" ,
209203 expect . any ( Object ) ,
210204 ) ;
211- expect ( advancedSearch . commit ) . toHaveBeenCalledWith (
205+ expect ( store . commit ) . toHaveBeenCalledWith (
212206 "advancedSearch/setEditAdvancedSearch" ,
213207 expect . any ( Object ) ,
214208 ) ;
215209
216- // Inspect the exact object that was built and committed by the parser
217- const committedPayload = advancedSearch . commit . mock . calls [ 0 ] [ 1 ] ;
210+ const committedPayload = store . commit . mock . calls [ 0 ] [ 1 ] ;
218211 expect ( committedPayload . operatorIdentifier ) . toBe ( "AND" ) ;
219212 expect ( committedPayload . children [ 0 ] . operatorIdentifier ) . toBe ( "OR" ) ;
220213 expect ( committedPayload . children [ 0 ] . children [ 0 ] . identifier ) . toBe (
221214 "registry" ,
222215 ) ;
223- // "true+false" splits to ["true", "false"] in your logic
224216 expect ( committedPayload . children [ 0 ] . children [ 0 ] . value ) . toEqual ( [
225217 "true" ,
226218 "false" ,
227219 ] ) ;
228220
229- // 2. Check Vuex mapped action
230221 expect ( mockFetchAction ) . toHaveBeenCalledWith (
231222 expect . any ( Object ) ,
232223 "searchterm" ,
0 commit comments