• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {createEmptyState} from './empty_state';
16import {getContainingTrackId, PrimaryTrackSortKey, State} from './state';
17import {deserializeStateObject, serializeStateObject} from './upload_utils';
18
19test('createEmptyState', () => {
20  const state: State = createEmptyState();
21  expect(state.engine).toEqual(undefined);
22});
23
24test('getContainingTrackId', () => {
25  const state: State = createEmptyState();
26  state.tracks['a'] = {
27    id: 'a',
28    engineId: 'engine',
29    kind: 'Foo',
30    name: 'a track',
31    trackSortKey: PrimaryTrackSortKey.ORDINARY_TRACK,
32    config: {},
33  };
34
35  state.tracks['b'] = {
36    id: 'b',
37    engineId: 'engine',
38    kind: 'Foo',
39    name: 'b track',
40    trackSortKey: PrimaryTrackSortKey.ORDINARY_TRACK,
41    config: {},
42    trackGroup: 'containsB',
43  };
44
45  expect(getContainingTrackId(state, 'z')).toEqual(null);
46  expect(getContainingTrackId(state, 'a')).toEqual(null);
47  expect(getContainingTrackId(state, 'b')).toEqual('containsB');
48});
49
50test('state is serializable', () => {
51  const state: State = createEmptyState();
52  const json = serializeStateObject(state);
53  const restored: State = deserializeStateObject(json);
54
55  // Remove nonSerializableState from original
56  const serializableState: any = state as any;
57  delete serializableState['nonSerializableState'];
58
59  // Remove any undefined values from original as JSON doesn't serialize them
60  for (const key in serializableState) {
61    if (serializableState[key] === undefined) {
62      delete serializableState[key];
63    }
64  }
65
66  expect(serializableState).toEqual(restored);
67});
68