1 import type { WithOptimisticHistory } from '../types';
2 import { isOptimisticHistoryItem } from './assertions';
3 import { splitHistoryOnFirstOptimisticItem } from './split-history';
4 import { createTestDeterministicAction, createTestOptimisticHistoryItem } from './testing.utils';
6 describe('splitHistoryOnFirstOptimisticItem', () => {
7 test('should return empty right side if no optimistic actions in history', () => {
8 const history = [createTestDeterministicAction()];
9 const [left, right] = splitHistoryOnFirstOptimisticItem(history);
11 expect(right.length).toEqual(0);
12 expect(left).toEqual(history);
15 test('left side should only contain redux actions and no optimistic actions', () => {
16 const history: WithOptimisticHistory = [
17 createTestDeterministicAction(),
18 createTestOptimisticHistoryItem(),
19 createTestDeterministicAction(),
20 createTestOptimisticHistoryItem(),
23 const [left, right] = splitHistoryOnFirstOptimisticItem(history);
25 expect(left.some(isOptimisticHistoryItem)).toBe(false);
26 expect(left).toEqual(history.slice(0, 1));
27 expect(right).toEqual(history.slice(1));