| // Copyright 2018 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| suite('app state', function() { |
| let apps; |
| let action; |
| |
| function createApp(id, config) { |
| return app_management.FakePageHandler.createApp(id, config); |
| } |
| |
| setup(function() { |
| // Create an initial AppMap. |
| apps = { |
| '1': createApp('1'), |
| '2': createApp('2'), |
| }; |
| }); |
| |
| test('updates when apps are added', function() { |
| appsToAdd = [ |
| createApp('3', {type: 1, title: 'a'}), |
| createApp('4'), |
| ]; |
| |
| action = app_management.actions.addApps(appsToAdd); |
| apps = app_management.AppState.updateApps(apps, action); |
| |
| // Check that apps contains a key for each app id. |
| assertTrue(!!apps['1']); |
| assertTrue(!!apps['2']); |
| assertTrue(!!apps['3']); |
| assertTrue(!!apps['4']); |
| |
| // Check that id corresponds to the right app. |
| const app = apps['3']; |
| assertEquals('3', app.id); |
| assertEquals(1, app.type); |
| assertEquals('a', app.title); |
| }); |
| |
| test('updates when an app is changed', function() { |
| const changedApp = createApp('2', {type: 1, title: 'a'}); |
| action = app_management.actions.changeApp(changedApp); |
| apps = app_management.AppState.updateApps(apps, action); |
| |
| // Check that app has changed |
| const app = apps['2']; |
| assertEquals(1, app.type); |
| assertEquals('a', app.title); |
| |
| // Check that number of apps hasn't changed |
| assertEquals(Object.keys(apps).length, 2); |
| }); |
| |
| test('updates when an app is removed', function() { |
| action = app_management.actions.removeApp('1'); |
| apps = app_management.AppState.updateApps(apps, action); |
| |
| // Check that app is removed |
| assertFalse(!!apps['1']); |
| |
| // Check that other app is unaffected |
| assertTrue(!!apps['2']); |
| }); |
| }); |