| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import {nextTick} from 'shared/testUtils'; |
| b69ab31 | | | 9 | import clientToServerAPI from '../ClientToServerAPI'; |
| b69ab31 | | | 10 | import {resetTestMessages, simulateMessageFromServer} from '../testUtils'; |
| b69ab31 | | | 11 | |
| b69ab31 | | | 12 | describe('ClientToServer', () => { |
| b69ab31 | | | 13 | beforeEach(() => { |
| b69ab31 | | | 14 | resetTestMessages(); |
| b69ab31 | | | 15 | }); |
| b69ab31 | | | 16 | |
| b69ab31 | | | 17 | describe('nextMessageMatching', () => { |
| b69ab31 | | | 18 | it('resolves when it sees a matching message', async () => { |
| b69ab31 | | | 19 | let isResolved = false; |
| b69ab31 | | | 20 | const matchingPromise = clientToServerAPI.nextMessageMatching( |
| b69ab31 | | | 21 | 'uploadFileResult', |
| b69ab31 | | | 22 | message => message.id === '1234', |
| b69ab31 | | | 23 | ); |
| b69ab31 | | | 24 | |
| b69ab31 | | | 25 | matchingPromise.then(() => { |
| b69ab31 | | | 26 | isResolved = true; |
| b69ab31 | | | 27 | }); |
| b69ab31 | | | 28 | |
| b69ab31 | | | 29 | simulateMessageFromServer({type: 'beganLoadingMoreCommits'}); // doesn't match type |
| b69ab31 | | | 30 | simulateMessageFromServer({type: 'uploadFileResult', result: {value: 'hi'}, id: '9999'}); // doesn't match predicate |
| b69ab31 | | | 31 | await nextTick(); |
| b69ab31 | | | 32 | expect(isResolved).toEqual(false); |
| b69ab31 | | | 33 | |
| b69ab31 | | | 34 | simulateMessageFromServer({type: 'uploadFileResult', result: {value: 'hi'}, id: '1234'}); // matches |
| b69ab31 | | | 35 | expect(matchingPromise).resolves.toEqual({ |
| b69ab31 | | | 36 | type: 'uploadFileResult', |
| b69ab31 | | | 37 | result: {value: 'hi'}, |
| b69ab31 | | | 38 | id: '1234', |
| b69ab31 | | | 39 | }); |
| b69ab31 | | | 40 | |
| b69ab31 | | | 41 | simulateMessageFromServer({type: 'uploadFileResult', result: {value: 'hi'}, id: '1234'}); // doesn't crash or anything if another message would match |
| b69ab31 | | | 42 | }); |
| b69ab31 | | | 43 | }); |
| b69ab31 | | | 44 | }); |