|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | import React from 'react'; |
9 | | -import { Observable } from 'rxjs'; |
| 9 | +import { Observable, Subject } from 'rxjs'; |
10 | 10 | import { ReactWrapper } from 'enzyme'; |
11 | 11 | import { act } from 'react-dom/test-utils'; |
12 | 12 | import { App } from './app'; |
@@ -77,13 +77,16 @@ function createMockFrame(): jest.Mocked<EditorFrameInstance> { |
77 | 77 | }; |
78 | 78 | } |
79 | 79 |
|
| 80 | +const sessionIdSubject = new Subject<string>(); |
| 81 | + |
80 | 82 | function createMockSearchService() { |
81 | 83 | let sessionIdCounter = 1; |
82 | 84 | return { |
83 | 85 | session: { |
84 | 86 | start: jest.fn(() => `sessionId-${sessionIdCounter++}`), |
85 | 87 | clear: jest.fn(), |
86 | 88 | getSessionId: jest.fn(() => `sessionId-${sessionIdCounter}`), |
| 89 | + getSession$: jest.fn(() => sessionIdSubject.asObservable()), |
87 | 90 | }, |
88 | 91 | }; |
89 | 92 | } |
@@ -1328,6 +1331,24 @@ describe('Lens App', () => { |
1328 | 1331 | ); |
1329 | 1332 | }); |
1330 | 1333 |
|
| 1334 | + it('re-renders the frame if session id changes from the outside', async () => { |
| 1335 | + const services = makeDefaultServices(); |
| 1336 | + const { frame } = mountWith({ props: undefined, services }); |
| 1337 | + |
| 1338 | + act(() => { |
| 1339 | + sessionIdSubject.next('new-session-id'); |
| 1340 | + }); |
| 1341 | + await act(async () => { |
| 1342 | + await new Promise((r) => setTimeout(r, 0)); |
| 1343 | + }); |
| 1344 | + expect(frame.mount).toHaveBeenCalledWith( |
| 1345 | + expect.any(Element), |
| 1346 | + expect.objectContaining({ |
| 1347 | + searchSessionId: `new-session-id`, |
| 1348 | + }) |
| 1349 | + ); |
| 1350 | + }); |
| 1351 | + |
1331 | 1352 | it('updates the searchSessionId when the active saved query is cleared', () => { |
1332 | 1353 | const { component, frame, services } = mountWith({}); |
1333 | 1354 | act(() => |
|
0 commit comments