|
| 1 | +/* |
| 2 | + * Copyright (c) 2002-2017 "Neo Technology," |
| 3 | + * Network Engine for Objects in Lund AB [http://neotechnology.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Neo4j is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +/* global describe, test, expect */ |
| 22 | +import reducer, { add, SET_MAX_FRAMES, initialState } from './streamDuck' |
| 23 | + |
| 24 | +describe('streamDuck', () => { |
| 25 | + test('limits the number of frames in the reducer', () => { |
| 26 | + // Given |
| 27 | + const init = {...initialState, maxFrames: 1} |
| 28 | + const action = add({cmd: 'xxx', id: 1}) |
| 29 | + const action2 = add({cmd: 'yyy', id: 2}) |
| 30 | + |
| 31 | + // When |
| 32 | + const newState = reducer(init, action) |
| 33 | + |
| 34 | + // Then |
| 35 | + expect(newState.allIds.length).toBe(1) |
| 36 | + |
| 37 | + // When |
| 38 | + const newState2 = reducer(newState, action2) |
| 39 | + |
| 40 | + // Then |
| 41 | + expect(newState2.allIds.length).toBe(1) |
| 42 | + }) |
| 43 | + test('cuts the number of frames when config is set', () => { |
| 44 | + // Given |
| 45 | + const init = {...initialState, maxFrames: 2, allIds: [1, 2], byId: {'1': {id: 1}, '2': {id: 2}}} |
| 46 | + const action = { type: SET_MAX_FRAMES, maxFrames: 1 } |
| 47 | + |
| 48 | + // When |
| 49 | + const newState = reducer(init, action) |
| 50 | + |
| 51 | + // Then |
| 52 | + expect(newState.allIds.length).toBe(1) |
| 53 | + expect(newState.allIds).toMatchSnapshot() |
| 54 | + expect(newState.byId).toMatchSnapshot() |
| 55 | + }) |
| 56 | + test('dont remove pinned frames when cutting frames', () => { |
| 57 | + // Given |
| 58 | + const byId = {'1': {isPinned: 1}, '2': {isPinned: 1}} |
| 59 | + const init = {...initialState, maxFrames: 2, allIds: [1, 2], byId} |
| 60 | + const action = { type: SET_MAX_FRAMES, maxFrames: 1 } |
| 61 | + |
| 62 | + // When |
| 63 | + const newState = reducer(init, action) |
| 64 | + |
| 65 | + // Then |
| 66 | + expect(newState.allIds.length).toBe(2) |
| 67 | + expect(newState.allIds).toMatchSnapshot() |
| 68 | + expect(newState.byId).toMatchSnapshot() |
| 69 | + }) |
| 70 | +}) |
0 commit comments