addons/isl/src/__tests__/ClientToServer.test.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import {nextTick} from 'shared/testUtils';
b69ab319import clientToServerAPI from '../ClientToServerAPI';
b69ab3110import {resetTestMessages, simulateMessageFromServer} from '../testUtils';
b69ab3111
b69ab3112describe('ClientToServer', () => {
b69ab3113 beforeEach(() => {
b69ab3114 resetTestMessages();
b69ab3115 });
b69ab3116
b69ab3117 describe('nextMessageMatching', () => {
b69ab3118 it('resolves when it sees a matching message', async () => {
b69ab3119 let isResolved = false;
b69ab3120 const matchingPromise = clientToServerAPI.nextMessageMatching(
b69ab3121 'uploadFileResult',
b69ab3122 message => message.id === '1234',
b69ab3123 );
b69ab3124
b69ab3125 matchingPromise.then(() => {
b69ab3126 isResolved = true;
b69ab3127 });
b69ab3128
b69ab3129 simulateMessageFromServer({type: 'beganLoadingMoreCommits'}); // doesn't match type
b69ab3130 simulateMessageFromServer({type: 'uploadFileResult', result: {value: 'hi'}, id: '9999'}); // doesn't match predicate
b69ab3131 await nextTick();
b69ab3132 expect(isResolved).toEqual(false);
b69ab3133
b69ab3134 simulateMessageFromServer({type: 'uploadFileResult', result: {value: 'hi'}, id: '1234'}); // matches
b69ab3135 expect(matchingPromise).resolves.toEqual({
b69ab3136 type: 'uploadFileResult',
b69ab3137 result: {value: 'hi'},
b69ab3138 id: '1234',
b69ab3139 });
b69ab3140
b69ab3141 simulateMessageFromServer({type: 'uploadFileResult', result: {value: 'hi'}, id: '1234'}); // doesn't crash or anything if another message would match
b69ab3142 });
b69ab3143 });
b69ab3144});