@@ -20,7 +20,9 @@ import {
20
20
GET_BOOKMARKS ,
21
21
AppState ,
22
22
SYNCHRONIZE_BOOKMARK ,
23
- UPDATE_BOOKMARKS
23
+ UPDATE_BOOKMARKS ,
24
+ GET_LAST_VISITED_GUIDES ,
25
+ UPDATE_LAST_VISITED_GUIDES
24
26
} from '@sap/guided-answers-extension-types' ;
25
27
import type {
26
28
Bookmarks ,
@@ -31,13 +33,15 @@ import type {
31
33
GuidedAnswerNodeId ,
32
34
GuidedAnswerTree ,
33
35
GuidedAnswerTreeId ,
34
- GuidedAnswerTreeSearchResult
36
+ GuidedAnswerTreeSearchResult ,
37
+ LastVisitedGuide
35
38
} from '@sap/guided-answers-extension-types' ;
36
39
import { GuidedAnswersPanel , GuidedAnswersSerializer } from '../../src/panel/guidedAnswersPanel' ;
37
40
import * as logger from '../../src/logger/logger' ;
38
41
import * as telemetry from '../../src/telemetry' ;
39
42
import type { StartOptions } from '../../src/types' ;
40
43
import { initBookmarks } from '../../src/bookmarks' ;
44
+ import { initLastVisited } from '../../src/last-visited' ;
41
45
42
46
type WebviewMessageCallback = ( action : GuidedAnswerActions ) => void ;
43
47
@@ -192,7 +196,8 @@ describe('GuidedAnswersPanel', () => {
192
196
[ { type : UPDATE_ACTIVE_NODE , payload : { NODE_ID : 1234 , TITLE : 'Node 1234' } } ] ,
193
197
[ { type : BETA_FEATURES , payload : false } ] ,
194
198
[ { type : UPDATE_NETWORK_STATUS , payload : 'OK' } ] ,
195
- [ { type : GET_BOOKMARKS , payload : { } } ]
199
+ [ { type : GET_BOOKMARKS , payload : { } } ] ,
200
+ [ { type : GET_LAST_VISITED_GUIDES , payload : [ ] } ]
196
201
] ) ;
197
202
} ) ;
198
203
@@ -219,7 +224,8 @@ describe('GuidedAnswersPanel', () => {
219
224
[ { type : UPDATE_ACTIVE_NODE , payload : { NODE_ID : 300 } } ] ,
220
225
[ { type : BETA_FEATURES , payload : false } ] ,
221
226
[ { type : UPDATE_NETWORK_STATUS , payload : 'OK' } ] ,
222
- [ { type : GET_BOOKMARKS , payload : { } } ]
227
+ [ { type : GET_BOOKMARKS , payload : { } } ] ,
228
+ [ { type : GET_LAST_VISITED_GUIDES , payload : [ ] } ]
223
229
] ) ;
224
230
} ) ;
225
231
@@ -728,6 +734,42 @@ describe('GuidedAnswersPanel', () => {
728
734
expect ( globalStateMock . update ) . toBeCalledWith ( 'bookmark' , expectBookmarks ) ;
729
735
} ) ;
730
736
737
+ test ( 'GuidedAnswersPanel communication UPDATE_LAST_VISITED_GUIDES' , async ( ) => {
738
+ // Mock setup
739
+ let onDidReceiveMessageMock : WebviewMessageCallback = ( ) => { } ;
740
+ jest . spyOn ( window , 'createWebviewPanel' ) . mockImplementation ( ( ) =>
741
+ getWebViewPanelMock ( ( callback : WebviewMessageCallback ) => {
742
+ onDidReceiveMessageMock = callback ;
743
+ } )
744
+ ) ;
745
+ const lastVisitedMock = [
746
+ {
747
+ tree : {
748
+ TREE_ID : 1 ,
749
+ TITLE : 'Bookmark Title' ,
750
+ } ,
751
+ nodePath : [ { NODE_ID : 2 } , { NODE_ID : 3 } ] ,
752
+ createdAt : '2023-05-23T15:41:00.478Z'
753
+ }
754
+ ] as LastVisitedGuide [ ] ;
755
+
756
+ const globalStateMock = {
757
+ update : jest . fn ( )
758
+ } as Partial < Memento > ;
759
+ initLastVisited ( globalStateMock as Memento ) ;
760
+
761
+ // Test execution
762
+ const panel = new GuidedAnswersPanel ( ) ;
763
+ panel . show ( ) ;
764
+ await onDidReceiveMessageMock ( {
765
+ type : UPDATE_LAST_VISITED_GUIDES ,
766
+ payload : lastVisitedMock
767
+ } ) ;
768
+
769
+ // Result check
770
+ expect ( globalStateMock . update ) . toBeCalledWith ( 'lastVisitedGuides' , lastVisitedMock ) ;
771
+ } ) ;
772
+
731
773
test ( 'GuidedAnswersPanel communication unhandled action' , async ( ) => {
732
774
// Mock setup
733
775
let onDidReceiveMessageMock : WebviewMessageCallback = ( ) => { } ;
0 commit comments