1- import { describe , it , expect , beforeEach } from "vitest" ;
1+ import { beforeEach , describe , expect , it } from "vitest" ;
22import { store } from "@/store" ;
3- import { handleHostStoreChange } from "./handleHostStoreChange" ;
3+ import {
4+ getCallbackRequests ,
5+ handleHostStoreChange ,
6+ type PropertyRef ,
7+ } from "./handleHostStoreChange" ;
8+ import type { ContribPoint } from "@/types/model/extension" ;
9+ import type { ContributionState } from "@/types/state/contribution" ;
410
511describe ( "handleHostStoreChange" , ( ) => {
612 let listeners : ( ( ) => void ) [ ] = [ ] ;
@@ -15,10 +21,12 @@ describe("handleHostStoreChange", () => {
1521 listeners . push ( _l ) ;
1622 } ,
1723 } ;
24+ let lastInputValues : Record < string , unknown [ ] > = { } ;
1825
1926 beforeEach ( ( ) => {
2027 listeners = [ ] ;
2128 hostState = { } ;
29+ lastInputValues = { } ;
2230 } ) ;
2331
2432 it ( "should do nothing without host store" , ( ) => {
@@ -82,4 +90,89 @@ describe("handleHostStoreChange", () => {
8290 hostStore . set ( "variableName" , "CHL" ) ;
8391 handleHostStoreChange ( ) ;
8492 } ) ;
93+
94+ it ( "should memoize second call with same arguments" , ( ) => {
95+ const extensions = [ { name : "e0" , version : "0" , contributes : [ "panels" ] } ] ;
96+ store . setState ( {
97+ configuration : { hostStore, logging : { enabled : false } } ,
98+ extensions,
99+ contributionsResult : {
100+ status : "ok" ,
101+ data : {
102+ extensions,
103+ contributions : {
104+ panels : [
105+ {
106+ name : "ext.p1" ,
107+ extension : "ext" ,
108+ layout : {
109+ function : {
110+ name : "layout" ,
111+ parameters : [ ] ,
112+ return : { } ,
113+ } ,
114+ inputs : [ ] ,
115+ outputs : [ ] ,
116+ } ,
117+ callbacks : [
118+ {
119+ function : {
120+ name : "callback" ,
121+ parameters : [ ] ,
122+ return : { } ,
123+ } ,
124+ inputs : [ { id : "@app" , property : "variableName" } ] ,
125+ outputs : [ { id : "select" , property : "value" } ] ,
126+ } ,
127+ ] ,
128+ initialState : { } ,
129+ } ,
130+ ] ,
131+ } ,
132+ } ,
133+ } ,
134+ lastInputValues : lastInputValues ,
135+ } ) ;
136+ hostStore . set ( "variableName" , "CHL" ) ;
137+ const propertyRefs : PropertyRef [ ] = [
138+ {
139+ id : "panel-0-0-0" ,
140+ contribPoint : "panel" ,
141+ contribIndex : 0 ,
142+ callbackIndex : 0 ,
143+ property : "value" ,
144+ inputIndex : 0 ,
145+ } ,
146+ ] ;
147+ const contributionsRecord : Record < ContribPoint , ContributionState [ ] > = {
148+ panel : [
149+ {
150+ name : "ext.p1" ,
151+ container : { title : "Panel A" } ,
152+ extension : "ext" ,
153+ componentResult : { } ,
154+ initialState : { title : "Panel A" } ,
155+ callbacks : [
156+ {
157+ function : {
158+ name : "callback" ,
159+ parameters : [ { name : "param1" } ] ,
160+ return : { } ,
161+ } ,
162+ inputs : [ { id : "@app" , property : "variableName" } ] ,
163+ } ,
164+ ] ,
165+ } ,
166+ ] ,
167+ } ;
168+ const result = getCallbackRequests (
169+ propertyRefs ,
170+ contributionsRecord ,
171+ hostStore ,
172+ ) ;
173+ expect ( result [ 0 ] ) . toEqual ( {
174+ ...propertyRefs [ 0 ] ,
175+ inputValues : [ "CHL" ] ,
176+ } ) ;
177+ } ) ;
85178} ) ;
0 commit comments