/** * Created by jimsugg on 9/24/16. */ import * as tsUnit from 'tsunit.external/tsUnit' import { createStore, Store, applyMiddleware } from 'redux' import thunk from 'redux-thunk' import baDmReducer from '../libbadm/main' import * as actions from '../libbadm/baDmActions' //import * as interfaces from '../libbadm/baDmInterfaces' import { BaDmIdNone, VideoMode, ZoneType, MediaStateContainerType, EventType } from '../libbadm/baDmDataTypes' import {MediaType} from '../libbadm/baDmMediaObject'; import {DmInternal} from '../libbadm/baDmClasses' import {getZoneById, getZoneByName, getZoneCount} from '../libbadm/reducers/reducerZone'; import {getMediaStateById, getMediaStateByName, getMediaStatesForZone} from '../libbadm/reducers/reducerMediaState'; import {inspect} from 'util' type DmState = DmInternal.DmState; export class SignTests extends tsUnit.TestClass { store: Store = createStore(baDmReducer, applyMiddleware(thunk)); contentItem1 = new DmInternal.MediaContentItem('Item1', '/testFiles/image1.jpg', MediaType.Image); contentItem2 = new DmInternal.MediaContentItem('Item2', '/testFiles/image2.jpg', MediaType.Image); testSignCreation() { //console.log("Before:/n", inspect(this.store.getState(), {depth: null, colors: true})); this.store.dispatch(actions.baNewSign('TestSign', VideoMode.v1920x1080x60p)); let state = this.store.getState(); this.areIdentical('TestSign', state.sign.name); this.areIdentical(VideoMode.v1920x1080x60p, state.sign.videoMode); //console.log("New Sign:/n", inspect(this.store.getState(), {depth: null, colors: true})); let zoneAction = this.store.dispatch(actions.baAddZone('Zone1', ZoneType.Images)); let zone1Id = zoneAction.id; //console.log("Sign with Zone:/n", inspect(this.store.getState(), {depth: null, colors: true})); let zone1 = getZoneById(this.store.getState(), {id: zone1Id}); let zone1Container = zone1.containerObject; this.isTruthy(zone1, "Failed: getZoneById"); this.areIdentical(ZoneType.Images, zone1.type); this.areIdentical(BaDmIdNone, zone1.initialMediaStateId); let msAction = this.store.dispatch(actions.baAddMediaState('State1', zone1Container, this.contentItem1)); let mediaState1Id = msAction.id; state = this.store.getState(); this.isTrue(getZoneCount(state) === 1); let mediaState1 = getMediaStateById(state, {id: mediaState1Id}); this.isTruthy(mediaState1); zone1 = getZoneById(state, {id: zone1Id}); // Adding first event this.areIdentical(mediaState1.id, zone1.initialMediaStateId, "Adding first state should set it as the initial state"); this.areIdentical(this.contentItem1.type, mediaState1.contentItem.type); this.areIdentical(this.contentItem1.media.path, ((mediaState1.contentItem)).media.path); let zone1States = getMediaStatesForZone(state, {id: zone1Id}); this.isTrue(zone1States.length === 1, "Zone should have one media state"); this.areIdentical(mediaState1.id, zone1States[0]); // console.log("Sign with one Media State:/n", inspect(this.store.getState(), {depth: null, colors: true})); this.store.dispatch(actions.baUpdateZone(zone1Id,{name:"Zone1x"})); zone1 = getZoneById(this.store.getState(), {id: zone1Id}); this.areIdentical("Zone1x", zone1.name); msAction = this.store.dispatch(actions.baAddMediaState('State2', zone1Container, this.contentItem2)); let mediaState2Id = msAction.id; state = this.store.getState(); this.isTrue(getZoneCount(state) === 1, "There should still only be one zone after adding second media state"); let mediaState2 = getMediaStateById(state, {id: mediaState2Id}); this.isTruthy(mediaState2); this.areIdentical(this.contentItem2.type, mediaState2.contentItem.type); this.areIdentical(this.contentItem2.media.path, ((mediaState2.contentItem)).media.path); zone1States = getMediaStatesForZone(state, {id: zone1Id}); this.isTrue(zone1States.length === 2, "Zone should have two media states"); // Make State 2 the initial state this.store.dispatch(actions.baUpdateZone(zone1Id,{initialMediaStateId:mediaState2.id})); zone1 = getZoneById(this.store.getState(), {id: zone1Id}); this.areIdentical(mediaState2.id, zone1.initialMediaStateId); // Event added to State 2 (now the initial event) let evAction = this.store.dispatch(actions.baAddEvent('Timeout1',EventType.Timer,mediaState2.id,{interval: 5})); let eventId = evAction.id; // Transition to State 1 this.store.dispatch(actions.baAddTransition('Transition1',eventId,mediaState1.id)); console.log("Sign with two Media States:\n", inspect(this.store.getState(), {depth: null, colors: true})); } } var tap = new tsUnit.Test([SignTests]).run().getTapResults(); console.log(tap);