import { observable , action , IObservableValue } from 'mobx' ; import { lightTheme , ITheme , darkTheme } from '../config/themes' ; import { TestGroup } from './test_group_model' ; import { ViewState } from './state_view_model' ; import { AppConfig } from '../config/app_config' ; import { TestItem } from './test_item_model' ; import { ProxyConfig } from './proxy_store' ; declare global { namespace Luis { export type State = StateModel ; } } export function mapBridgeToState ( setup ) { setup ( initState ( ) ) ; } export type RenderOptions = { root ? : string ; extraUpdateProps ? : string ; updateUrl ? : string ; loadTests ? : ( ) => any ; report ? : any ; snapshots ? : any ; proxies ? : ProxyConfig [ ] ; } ; let id = 0 ; export class StateModel { @ observable theme : ITheme = localStorage . getItem ( 'luisTheme' ) === 'light' ? lightTheme : localStorage . getItem ( 'luisTheme' ) === 'dark' ? darkTheme : lightTheme ; @ observable autoUpdateSnapshots = false ; @ observable showPassing = true ; @ observable showFailing = true ; @ observable wrapperStyle = '' ; @ observable running = false ; @ observable hideTestMenus = false ; expanded : { [ index ] : IObservableValue < boolean > ; } = { } ; liveRoot : TestGroup ; currentGroup : TestGroup ; viewState : ViewState ; testResults : any ; renderOptions : RenderOptions ; timer : any ; config : AppConfig ; uid : number ; constructor ( ) { this . uid = id ++ ; this . liveRoot = new TestGroup ( null , 'root' ) ; this . currentGroup = this . liveRoot ; this . viewState = new ViewState ( this ) ; this . config = new AppConfig ( this ) ; } findStoryByFileName ( fileName ) { return this . liveRoot . findGroup ( g => g . fileName === fileName ) ; } findStoryById ( id ) { return this . liveRoot . findGroup ( g => g . id === id ) ; } createStory ( name , props ) { return new TestGroup ( this . currentGroup , name , props ) ; } hideMenus ( value ? ) { this . hideTestMenus = value ; localStorage . setItem ( 'LUIS.showTestMenus' , this . hideTestMenus ? 'true' : 'false' ) ; } @ action isExpanded ( group ) { const path = group . id ; if ( this . expanded [ path ] == null ) { this . expanded [ path ] = observable . box ( false ) ; } return this . expanded [ path ] ; } @ action toggleExpanded ( e , item ) { const path = item . id ; if ( e . target && e . target . nodeName . toLowerCase ( ) === 'a' ) { this . expanded [ path ] . set ( true ) ; } else { this . expanded [ path ] . set ( ! this . expanded [ path ] . get ( ) ) ; } } } let state ; export function initState ( ) { if ( ! state ) { state = new StateModel ( ) ; ( global as any ) . __state = state ; } else { state . liveRoot . groups = [ ] ; state . currentGroup = state . liveRoot ; } return state ; } export function getState ( ) { return state ; }