How to use getState method in storybook-root

Best JavaScript code snippet using storybook-root

unit.js

Source:unit.js Github

copy

Full Screen

...826});827////////////////////////////////////////////////////////////////////////////////828////////////////////////////////////////////////////////////////////////////////829module( 'jQuery.bbq' );830test( 'jQuery.bbq.pushState(), jQuery.bbq.getState(), jQuery.bbq.removeState(), window.onhashchange', function() {831 expect( old_jquery ? 95 : 167 );832 833 var a, b, c, d, e, f, x, y, hash, hash_actual, obj, event, msg = 'Testing window.onhashchange and history';834 835 $.bbq.pushState();836 equals( window.location.hash.replace( /^#/, ''), '', 'window.location hash should be empty' );837 838 $.bbq.pushState({ a:'1', b:'1' });839 same( $.deparam.fragment(), { a:'1', b:'1' }, 'hash should be set properly' );840 841 $(window).bind( 'hashchange', function(evt) {842 var hash_str = $.param.fragment(),843 param_obj = $.bbq.getState(),844 param_val = $.bbq.getState( 'param_name' );845 846 event = evt;847 hash = $.param.fragment();848 hash_actual = location.hash;849 obj = { str: $.bbq.getState(), coerce: $.bbq.getState( true ) };850 a = { str: $.bbq.getState( 'a' ), coerce: $.bbq.getState( 'a', true ) };851 b = { str: $.bbq.getState( 'b' ), coerce: $.bbq.getState( 'b', true ) };852 c = { str: $.bbq.getState( 'c' ), coerce: $.bbq.getState( 'c', true ) };853 d = { str: $.bbq.getState( 'd' ), coerce: $.bbq.getState( 'd', true ) };854 e = { str: $.bbq.getState( 'e' ), coerce: $.bbq.getState( 'e', true ) };855 f = { str: $.bbq.getState( 'f' ), coerce: $.bbq.getState( 'f', true ) };856 857 }).trigger( 'hashchange' );858 859 same( obj.str, { a:'1', b:'1' }, 'hashchange triggered manually: $.bbq.getState()' );860 same( obj.coerce, { a:1, b:1 }, 'hashchange triggered manually: $.bbq.getState( true )' );861 equals( a.str, '1', 'hashchange triggered manually: $.bbq.getState( "a" )' );862 equals( a.coerce, 1, 'hashchange triggered manually: $.bbq.getState( "a", true )' );863 864 if ( !old_jquery ) {865 same( event.getState(), { a:'1', b:'1' }, 'hashchange triggered manually: event.getState()' );866 same( event.getState(true), { a:1, b:1 }, 'hashchange triggered manually: event.getState( true )' );867 equals( event.getState('a'), '1', 'hashchange triggered manually: event.getState( "a" )' );868 equals( event.getState('a',true), 1, 'hashchange triggered manually: event.getState( "a", true )' );869 }870 871 run_many_tests(872 // run asynchronously873 250,874 875 // execute this for each array item876 function(){877 notice( msg += '.' );878 $.bbq.pushState.apply( this, aps.call( arguments ) );879 },880 881 // execute this at the end882 function(){883 notice();884 },885 886 // tests:887 888 [ { a:'2' } ],889 890 function(result){891 equals( hash_actual, '#' + hash, 'hash should begin with #!' );892 same( obj.str, { a:'2', b:'1' }, '$.bbq.getState()' );893 same( obj.coerce, { a:2, b:1 }, '$.bbq.getState( true )' );894 equals( a.str, '2', '$.bbq.getState( "a" )' );895 equals( a.coerce, 2, '$.bbq.getState( "a", true )' );896 if ( !old_jquery ) {897 same( event.getState(), { a:'2', b:'1' }, 'event.getState()' );898 same( event.getState(true), { a:2, b:1 }, 'event.getState( true )' );899 equals( event.getState('a'), '2', 'event.getState( "a" )' );900 equals( event.getState('a',true), 2, 'event.getState( "a", true )' );901 }902 },903 904 [ { b:'2' } ],905 906 function(result){907 equals( hash_actual, '#' + hash, 'hash should begin with #!' );908 same( obj.str, { a:'2', b:'2' }, '$.bbq.getState()' );909 same( obj.coerce, { a:2, b:2 }, '$.bbq.getState( true )' );910 equals( b.str, '2', '$.bbq.getState( "b" )' );911 equals( b.coerce, 2, '$.bbq.getState( "b", true )' );912 if ( !old_jquery ) {913 same( event.getState(), { a:'2', b:'2' }, 'event.getState()' );914 same( event.getState(true), { a:2, b:2 }, 'event.getState( true )' );915 equals( event.getState('b'), '2', 'event.getState( "b" )' );916 equals( event.getState('b',true), 2, 'event.getState( "b", true )' );917 }918 },919 920 [ { c:true, d:false, e:'undefined', f:'' } ],921 922 function(result){923 equals( hash_actual, '#' + hash, 'hash should begin with #!' );924 same( obj.str, { a:'2', b:'2', c:'true', d:'false', e:'undefined', f:'' }, '$.bbq.getState()' );925 same( obj.coerce, { a:2, b:2, c:true, d:false, e:undefined, f:'' }, '$.bbq.getState( true )' );926 equals( c.str, 'true', '$.bbq.getState( "c" )' );927 equals( c.coerce, true, '$.bbq.getState( "c", true )' );928 equals( d.str, 'false', '$.bbq.getState( "d" )' );929 equals( d.coerce, false, '$.bbq.getState( "d", true )' );930 equals( e.str, 'undefined', '$.bbq.getState( "e" )' );931 equals( e.coerce, undefined, '$.bbq.getState( "e", true )' );932 equals( f.str, '', '$.bbq.getState( "f" )' );933 equals( f.coerce, '', '$.bbq.getState( "f", true )' );934 if ( !old_jquery ) {935 same( event.getState(), { a:'2', b:'2', c:'true', d:'false', e:'undefined', f:'' }, 'event.getState()' );936 same( event.getState(true), { a:2, b:2, c:true, d:false, e:undefined, f:'' }, 'event.getState( true )' );937 equals( event.getState('c'), 'true', 'event.getState( "c" )' );938 equals( event.getState('c',true), true, 'event.getState( "c", true )' );939 equals( event.getState('d'), 'false', 'event.getState( "d" )' );940 equals( event.getState('d',true), false, 'event.getState( "d", true )' );941 equals( event.getState('e'), 'undefined', 'event.getState( "e" )' );942 equals( event.getState('e',true), undefined, 'event.getState( "e", true )' );943 equals( event.getState('f'), '', 'event.getState( "f" )' );944 equals( event.getState('f',true), '', 'event.getState( "f", true )' );945 }946 },947 948 function(result){949 $.param.fragment.ajaxCrawlable( true );950 },951 952 function(result){953 $.bbq.removeState( 'c' );954 },955 956 function(result){957 equals( hash_actual, '#!' + hash, 'hash should begin with #!' );958 same( obj.str, { a:'2', b:'2', d:'false', e:'undefined', f:'' }, '$.bbq.getState()' );959 same( obj.coerce, { a:2, b:2, d:false, e:undefined, f:'' }, '$.bbq.getState( true )' );960 equals( a.str, '2', '$.bbq.getState( "a" )' );961 equals( a.coerce, 2, '$.bbq.getState( "a", true )' );962 equals( b.str, '2', '$.bbq.getState( "b" )' );963 equals( b.coerce, 2, '$.bbq.getState( "b", true )' );964 equals( c.str, undefined, '$.bbq.getState( "c" )' );965 equals( c.coerce, undefined, '$.bbq.getState( "c", true )' );966 equals( d.str, 'false', '$.bbq.getState( "d" )' );967 equals( d.coerce, false, '$.bbq.getState( "d", true )' );968 equals( e.str, 'undefined', '$.bbq.getState( "e" )' );969 equals( e.coerce, undefined, '$.bbq.getState( "e", true )' );970 equals( f.str, '', '$.bbq.getState( "f" )' );971 equals( f.coerce, '', '$.bbq.getState( "f", true )' );972 if ( !old_jquery ) {973 same( event.getState(), { a:'2', b:'2', d:'false', e:'undefined', f:'' }, 'event.getState()' );974 same( event.getState(true), { a:2, b:2, d:false, e:undefined, f:'' }, 'event.getState( true )' );975 equals( event.getState('a'), '2', 'event.getState( "a" )' );976 equals( event.getState('a',true), 2, 'event.getState( "a", true )' );977 equals( event.getState('b'), '2', 'event.getState( "b" )' );978 equals( event.getState('b',true), 2, 'event.getState( "b", true )' );979 equals( event.getState('c'), undefined, 'event.getState( "c" )' );980 equals( event.getState('c',true), undefined, 'event.getState( "c", true )' );981 equals( event.getState('d'), 'false', 'event.getState( "d" )' );982 equals( event.getState('d',true), false, 'event.getState( "d", true )' );983 equals( event.getState('e'), 'undefined', 'event.getState( "e" )' );984 equals( event.getState('e',true), undefined, 'event.getState( "e", true )' );985 equals( event.getState('f'), '', 'event.getState( "f" )' );986 equals( event.getState('f',true), '', 'event.getState( "f", true )' );987 }988 },989 990 function(result){991 $.bbq.removeState( [ 'd', 'e', 'f', 'nonexistent' ] );992 },993 994 function(result){995 equals( hash_actual, '#!' + hash, 'hash should begin with #!' );996 same( obj.str, { a:'2', b:'2' }, '$.bbq.getState()' );997 same( obj.coerce, { a:2, b:2 }, '$.bbq.getState( true )' );998 equals( a.str, '2', '$.bbq.getState( "a" )' );999 equals( a.coerce, 2, '$.bbq.getState( "a", true )' );1000 equals( b.str, '2', '$.bbq.getState( "b" )' );1001 equals( b.coerce, 2, '$.bbq.getState( "b", true )' );1002 equals( c.str, undefined, '$.bbq.getState( "c" )' );1003 equals( c.coerce, undefined, '$.bbq.getState( "c", true )' );1004 equals( d.str, undefined, '$.bbq.getState( "d" )' );1005 equals( d.coerce, undefined, '$.bbq.getState( "d", true )' );1006 equals( e.str, undefined, '$.bbq.getState( "e" )' );1007 equals( e.coerce, undefined, '$.bbq.getState( "e", true )' );1008 equals( f.str, undefined, '$.bbq.getState( "f" )' );1009 equals( f.coerce, undefined, '$.bbq.getState( "f", true )' );1010 if ( !old_jquery ) {1011 same( event.getState(), { a:'2', b:'2' }, 'event.getState()' );1012 same( event.getState(true), { a:2, b:2 }, 'event.getState( true )' );1013 equals( event.getState('a'), '2', 'event.getState( "a" )' );1014 equals( event.getState('a',true), 2, 'event.getState( "a", true )' );1015 equals( event.getState('b'), '2', 'event.getState( "b" )' );1016 equals( event.getState('b',true), 2, 'event.getState( "b", true )' );1017 equals( event.getState('c'), undefined, 'event.getState( "c" )' );1018 equals( event.getState('c',true), undefined, 'event.getState( "c", true )' );1019 equals( event.getState('d'), undefined, 'event.getState( "d" )' );1020 equals( event.getState('d',true), undefined, 'event.getState( "d", true )' );1021 equals( event.getState('e'), undefined, 'event.getState( "e" )' );1022 equals( event.getState('e',true), undefined, 'event.getState( "e", true )' );1023 equals( event.getState('f'), undefined, 'event.getState( "f" )' );1024 equals( event.getState('f',true), undefined, 'event.getState( "f", true )' );1025 }1026 },1027 1028 function(result){1029 $.bbq.removeState();1030 },1031 1032 function(result){1033 equals( hash_actual, '#!', 'hash should just be #!' );1034 same( obj.str, {}, '$.bbq.getState()' );1035 same( obj.coerce, {}, '$.bbq.getState( true )' );1036 equals( a.str, undefined, '$.bbq.getState( "a" )' );1037 equals( a.coerce, undefined, '$.bbq.getState( "a", true )' );1038 equals( b.str, undefined, '$.bbq.getState( "b" )' );1039 equals( b.coerce, undefined, '$.bbq.getState( "b", true )' );1040 equals( c.str, undefined, '$.bbq.getState( "c" )' );1041 equals( c.coerce, undefined, '$.bbq.getState( "c", true )' );1042 equals( d.str, undefined, '$.bbq.getState( "d" )' );1043 equals( d.coerce, undefined, '$.bbq.getState( "d", true )' );1044 equals( e.str, undefined, '$.bbq.getState( "e" )' );1045 equals( e.coerce, undefined, '$.bbq.getState( "e", true )' );1046 equals( f.str, undefined, '$.bbq.getState( "f" )' );1047 equals( f.coerce, undefined, '$.bbq.getState( "f", true )' );1048 if ( !old_jquery ) {1049 same( event.getState(), {}, 'event.getState()' );1050 same( event.getState(true), {}, 'event.getState( true )' );1051 equals( event.getState('a'), undefined, 'event.getState( "a" )' );1052 equals( event.getState('a',true), undefined, 'event.getState( "a", true )' );1053 equals( event.getState('b'), undefined, 'event.getState( "b" )' );1054 equals( event.getState('b',true), undefined, 'event.getState( "b", true )' );1055 equals( event.getState('c'), undefined, 'event.getState( "c" )' );1056 equals( event.getState('c',true), undefined, 'event.getState( "c", true )' );1057 equals( event.getState('d'), undefined, 'event.getState( "d" )' );1058 equals( event.getState('d',true), undefined, 'event.getState( "d", true )' );1059 equals( event.getState('e'), undefined, 'event.getState( "e" )' );1060 equals( event.getState('e',true), undefined, 'event.getState( "e", true )' );1061 equals( event.getState('f'), undefined, 'event.getState( "f" )' );1062 equals( event.getState('f',true), undefined, 'event.getState( "f", true )' );1063 }1064 },1065 1066 [ { a:'2', b:'2', c:true, d:false, e:'undefined', f:'' } ],1067 1068 [ { a:[4,5,6], b:{x:[7], y:8, z:[9,0,'true','false','undefined','']} }, 2 ],1069 1070 function(result){1071 var b_str = old_jquery1072 ? '[object Object]'1073 : {x:['7'], y:'8', z:['9','0','true','false','undefined','']},1074 b_coerce = old_jquery1075 ? '[object Object]'1076 : {x:[7], y:8, z:[9,0,true,false,undefined,'']};1077 1078 equals( hash_actual, '#!' + hash, 'hash should begin with #!' );1079 same( obj.str, { a:['4','5','6'], b:b_str }, '$.bbq.getState()' );1080 same( obj.coerce, { a:[4,5,6], b:b_coerce }, '$.bbq.getState( true )' );1081 same( a.str, ['4','5','6'], '$.bbq.getState( "a" )' );1082 same( a.coerce, [4,5,6], '$.bbq.getState( "a", true )' );1083 if ( !old_jquery ) {1084 same( event.getState(), { a:['4','5','6'], b:b_str }, 'event.getState()' );1085 same( event.getState(true), { a:[4,5,6], b:b_coerce }, 'event.getState( true )' );1086 same( event.getState('a'), ['4','5','6'], 'event.getState( "a" )' );1087 same( event.getState('a',true), [4,5,6], 'event.getState( "a", true )' );1088 }1089 },1090 1091 [ { a:'1', c:'2' }, 1 ],1092 1093 function(result){1094 var b_str = old_jquery1095 ? '[object Object]'1096 : {x:['7'], y:'8', z:['9','0','true','false','undefined','']},1097 b_coerce = old_jquery1098 ? '[object Object]'1099 : {x:[7], y:8, z:[9,0,true,false,undefined,'']};1100 1101 equals( hash_actual, '#!' + hash, 'hash should begin with #!' );1102 same( obj.str, { a:['4','5','6'], b:b_str, c:'2' }, '$.bbq.getState()' );1103 same( obj.coerce, { a:[4,5,6], b:b_coerce, c:2 }, '$.bbq.getState( true )' );1104 if ( !old_jquery ) {1105 same( event.getState(), { a:['4','5','6'], b:b_str, c:'2' }, 'event.getState()' );1106 same( event.getState(true), { a:[4,5,6], b:b_coerce, c:2 }, 'event.getState( true )' );1107 }1108 },1109 1110 [ '#/path/to/file.php', 2 ],1111 1112 function(result){1113 equals( hash_actual, '#!' + hash, 'hash should begin with #!' );1114 equals( hash, '/path/to/file.php', '$.param.fragment()' );1115 if ( !old_jquery ) {1116 equals( event.fragment, '/path/to/file.php', 'event.fragment' );1117 }1118 },1119 1120 [],...

Full Screen

Full Screen

playback.js

Source:playback.js Github

copy

Full Screen

...65 * @param {function} getState return the state66 * @param {object} paginationOptions additional options to send to the service. (e.g. `fromValue`)67 */68const domainArgs = (getState, paginationOptions = {}) => {69 const id = selectedLayerSelector(getState());70 const layerName = selectedLayerName(getState());71 const layerUrl = selectedLayerUrl(getState());72 const { startPlaybackTime, endPlaybackTime } = playbackRangeSelector(getState()) || {};73 const shouldFilter = statusSelector(getState()) === STATUS.PLAY || statusSelector(getState()) === STATUS.PAUSE;74 return [layerUrl, layerName, "time", {75 limit: BUFFER_SIZE, // default, can be overridden by pagination options76 time: startPlaybackTime && endPlaybackTime && shouldFilter ? toAbsoluteInterval(startPlaybackTime, endPlaybackTime) : undefined,77 ...paginationOptions78 },79 multidimOptionsSelectorCreator(id)(getState())80 ];81};82/**83 * Emulates the getDomainValues when user wants to animate with fixed step (e.g. 1 hour)84 * Returns the stream that emits an array containing the animation steps.85 *86 * @param {function} getState returns the state87 * @param {objects} param1 the options to use. May contain `fromValue`88 */89const createAnimationValues = (getState, { fromValue, limit = BUFFER_SIZE, sort = "asc" } = {}) => {90 const {91 timeStep,92 stepUnit93 } = playbackSettingsSelector(getState());94 const interval = moment.duration(timeStep, stepUnit);95 const playbackRange = playbackRangeSelector(getState()) || {};96 const startPlaybackTime = playbackRange.startPlaybackTime;97 const endPlaybackTime = playbackRange.endPlaybackTime;98 let currentTime = fromValue !== undefined ? fromValue : startPlaybackTime || currentTimeSelector(getState()) || (new Date()).toString();99 const values = [];100 if (currentTime !== fromValue) {101 values.push(moment(currentTime).toISOString());102 }103 for (let i = 0; i < limit; i++) {104 currentTime = moment(currentTime).add(sort === "asc" ? interval : -1 * interval);105 if (!endPlaybackTime || currentTime.isBefore(endPlaybackTime)) {106 values.push(currentTime.toISOString());107 } else {108 break;109 }110 }111 return Rx.Observable.of(values);112};113/**114 * Gets the static list of times to animate115 */116const filterAnimationValues = (values, getState, {fromValue, limit = BUFFER_SIZE} = {}) => {117 const playbackRange = playbackRangeSelector(getState()) || {};118 const startPlaybackTime = playbackRange.startPlaybackTime;119 const endPlaybackTime = playbackRange.endPlaybackTime;120 return Rx.Observable.of(values121 // remove times before out of playback range122 .filter(v => startPlaybackTime && endPlaybackTime ? moment(v).isSameOrAfter(startPlaybackTime) && moment(v).isSameOrBefore(endPlaybackTime) : true)123 // Remove values before fromValue124 .filter(v => fromValue ? moment(v).isAfter(fromValue) : true)125 // limit size to BUFFER_SIZE126 .slice(0, limit));127};128/**129 * Returns an observable that emit an array of time frames, based of the current configuration:130 * - If configured as fixed steps, it returns the list of next animation frame calculating them131 * - If there is a selected layer and there is the Multidim extension, then use it (in favour of static values configured)132 * - If there are values in the dimension configuration, and the Multidim extension is not present, use them to animate133 * @param {function} getState returns the application state134 * @param {object} options the options that normally match the getDomainValues options135 */136const getAnimationFrames = (getState, options) => {137 if (selectedLayerName(getState())) {138 const values = layerTimeSequenceSelectorCreator(selectedLayerData(getState()))(getState());139 const timeDimConfig = selectedLayerTimeDimensionConfiguration(getState());140 // check if multidim extension is available. It has priority to local values141 if (get(timeDimConfig, "source.type") !== "multidim-extension" && values && values.length > 0) {142 return filterAnimationValues(values, getState, options);143 }144 return getDomainValues(...domainArgs(getState, options))145 .map(res => res.DomainValues.Domain.split(","));146 }147 return createAnimationValues(getState, options);148};149/**150 * Setup animation adding some action before and after the animationEventsStream$151 * Function returns a a function that operates on the stream (aka pipe-able aka let-table operator)152 * @param {function} getState returns the current state153 */154const setupAnimation = (getState = () => ({})) => animationEventsStream$ => {155 const layers = layersWithTimeDataSelector(getState());156 return Rx.Observable.from(157 layers.map(l => changeLayerProperties(l.id, {singleTile: true}))158 ).concat(animationEventsStream$)159 // restore original singleTile configuration160 .concat(Rx.Observable.from(161 layers.map(l => changeLayerProperties(l.id, { singleTile: l.singleTile }))162 ));163};164/**165 * Check if a time is in out of the defined range. If range start or end are not defined, returns false.166 * @param {string|Date} time the time to check167 * @param {Object} interval the interval where the time should stay `{start: ISODate|Date, end: ISODate|Date}168 */169const isOutOfRange = (time, { start, end } = {}) =>170 start && end && ( moment(time).isBefore(start) || moment(time).isAfter(end));171/**172 * When animation start, triggers the flow to retrieve the frames, buffering them:173 * The first setFrames will trigger the animation.174 * On any new animation frame, if the buffer is near to finish, this epic triggers175 * the retrieval of the next frames, until the animation ends.176 */177export const retrieveFramesForPlayback = (action$, { getState = () => { } } = {}) =>178 action$.ofType(PLAY).exhaustMap(() =>179 getAnimationFrames(getState, {180 fromValue:181 // if animation range is set, don't set from value on startup...182 (playbackRangeSelector(getState())183 && playbackRangeSelector(getState()).startPlaybackTime184 && playbackRangeSelector(getState()).endPlaybackTime)185 ? undefined186 // ...otherwise, start from the current time (start animation from cursor position)187 : currentTimeSelector(getState())188 })189 .map((frames) => setFrames(frames))190 .let(wrapStartStop(framesLoading(true), framesLoading(false)), () => Rx.Observable.of(191 error({192 title: "There was an error retrieving animation", // TODO: localize193 message: "Please contact the administrator" // TODO: localize194 }),195 stop()196 ))197 // show loading mask198 .let(wrapStartStop(timeDataLoading(false, true), timeDataLoading(false, false)))199 .concat(200 action$201 .ofType(SET_CURRENT_FRAME)202 .filter(({ frame }) => frame % BUFFER_SIZE === ((BUFFER_SIZE - PRELOAD_BEFORE)))203 .switchMap(() =>204 getAnimationFrames(getState, {205 fromValue: lastFrameSelector(getState())206 })207 .map(appendFrames)208 .let(wrapStartStop(framesLoading(true), framesLoading(false)))209 )210 )211 .takeUntil(action$.ofType(STOP, LOCATION_CHANGE))212 // this removes loading mask even if the STOP action is triggered before frame end (empty result)213 .concat(Rx.Observable.of(timeDataLoading(false, false)))214 .let(setupAnimation(getState))215 );216/**217 * When the new animation frame is triggered, changes the current time, if the next frame is available. Otherwise stops.218 * NOTE: we don't have a count of next animation steps, so we suppose that the selector has already pre-loaded next animation steps.219 */220export const updateCurrentTimeFromAnimation = (action$, { getState = () => { } } = {}) =>221 action$.ofType(SET_CURRENT_FRAME)222 .map(() => currentFrameValueSelector(getState()))223 .map(t => t ? moveTime(t) : stop());224/**225 * When a new frame sequence is set, the animation starts.226 */227export const timeDimensionPlayback = (action$, { getState = () => { } } = {}) =>228 action$.ofType(SET_FRAMES)229 .exhaustMap(() =>230 Rx.Observable.interval(frameDurationSelector(getState()) * 1000)231 .startWith(0) // start immediately232 .let(pausable(233 action$234 .ofType(PLAY, PAUSE)235 .map(a => a.type === PLAY)236 ))237 // pause is with loss, so the count of timer is not correct.238 // the following scan emit a for every event emitted effectively, with correct count239 // TODO: in case of loop, we can reset to 0 on load end.240 .map(() => setCurrentFrame(currentFrameSelector(getState()) + 1))241 .merge( action$.ofType(ANIMATION_STEP_MOVE)242 .map(({direction}) =>243 setCurrentFrame(244 Math.max(0, currentFrameSelector(getState()) + direction)))245 )246 .concat(Rx.Observable.of(stop()))247 .takeUntil(action$.ofType(STOP, LOCATION_CHANGE))248 );249/**250 * Synchronizes the fixed animation step toggle with guide layer on timeline251 */252export const playbackToggleGuideLayerToFixedStep = (action$, { getState = () => { } } = {}) =>253 action$254 .ofType(TOGGLE_ANIMATION_MODE)255 .exhaustMap(() =>256 selectedLayerName(getState())257 // need to deselect258 ? Rx.Observable.of(selectLayer(undefined))259 // need to select first260 : Rx.Observable.of(261 selectLayer(262 get(timelineLayersSelector(getState()), "[0].id")263 )264 )265 );266/**267 * Allow to move time 1 single step. TODO: evaluate to move this in timeline controls268 */269export const playbackMoveStep = (action$, { getState = () => { } } = {}) =>270 action$271 .ofType(ANIMATION_STEP_MOVE)272 .filter(() => statusSelector(getState()) !== STATUS.PLAY /* && statusSelector(getState()) !== STATUS.PAUSE*/) // if is playing, the animation manages this event273 .switchMap(({ direction = 1 }) => {274 const md = playbackMetadataSelector(getState()) || {};275 const currentTime = currentTimeSelector(getState());276 // check if the next/prev value is present in the state (by `playbackCacheNextPreviousTimes`)277 if (currentTime && md.forTime === currentTime) {278 return Rx.Observable.of(direction > 0 ? md.next : md.previous);279 }280 // if not downloaded yet, download it281 return getAnimationFrames(getState, { limit: 1, sort: direction > 0 ? "asc" : "desc", fromValue: currentTimeSelector(getState()) })282 .map(([t] = []) => t);283 }).filter(t => !!t)284 .map(t => moveTime(t));285/**286 * Pre-loads next and previous values for the current time, when change.287 * This is useful to enable/disable playback buttons in guide-layer mode. The state updated by this288 * epic is also used as a cache to load next/previous button (only when the animation is not active)289 */290export const playbackCacheNextPreviousTimes = (action$, { getState = () => { } } = {}) =>291 action$292 .ofType(SET_CURRENT_TIME, MOVE_TIME, SELECT_LAYER, STOP, SET_MAP_SYNC )293 .filter(() => statusSelector(getState()) !== STATUS.PLAY && statusSelector(getState()) !== STATUS.PAUSE)294 .filter(() => selectedLayerSelector(getState()))295 .filter( t => !!t )296 .switchMap(({time: actionTime}) => {297 // get current time in case of SELECT_LAYER298 const time = actionTime || currentTimeSelector(getState());299 return Rx.Observable.forkJoin(300 // TODO: find out a way to optimize and do only one request301 // TODO: support for local list of values (in case of missing multidim-extension)302 getDomainValues(...domainArgs(getState, { sort: "asc", limit: 1, fromValue: time }))303 .map(res => res.DomainValues.Domain.split(","))304 .map(([tt]) => tt).catch(err => err && Rx.Observable.of(null)),305 getDomainValues(...domainArgs(getState, { sort: "desc", limit: 1, fromValue: time }))306 .map(res => res.DomainValues.Domain.split(","))307 .map(([tt]) => tt).catch(err => err && Rx.Observable.of(null))308 ).map(([next, previous]) =>309 updateMetadata({310 forTime: time,311 next,312 previous313 })314 );315 });316/**317 * During animation, on every current time change event, if the current time is out of the current range window, the timeline will shift to318 * current start-end values319 */320export const playbackFollowCursor = (action$, { getState = () => { } } = {}) =>321 action$322 .ofType(MOVE_TIME)323 .filter(({type}) =>324 (type === MOVE_TIME || statusSelector(getState()) === STATUS.PLAY )325 && isOutOfRange(currentTimeSelector(getState()), rangeSelector(getState())))326 .filter(() => get(playbackSettingsSelector(getState()), "following") )327 .switchMap(() => Rx.Observable.of(328 onRangeChanged(329 (() => {330 const currentTime = currentTimeSelector(getState());331 const {start, end} = rangeSelector(getState());332 const difference = moment(end).diff(moment(start));333 const nextEnd = moment(currentTime).add(difference).toISOString();334 return {335 start: currentTime,336 end: nextEnd337 };338 })()339 )340 ));341export const playbackStopWhenDeleteLayer = (action$, { getState = () => {} } = {}) =>342 action$343 .ofType(REMOVE_NODE)344 .filter( () =>345 !selectedLayerSelector(getState())346 && statusSelector(getState()) === "PLAY"347 )348 .switchMap( () => Rx.Observable.of(stop()));349export default {350 retrieveFramesForPlayback,351 updateCurrentTimeFromAnimation,352 timeDimensionPlayback,353 playbackToggleGuideLayerToFixedStep,354 playbackMoveStep,355 playbackCacheNextPreviousTimes,356 playbackFollowCursor,357 playbackStopWhenDeleteLayer...

Full Screen

Full Screen

CourseActions.js

Source:CourseActions.js Github

copy

Full Screen

2export function getCourseDefs(query) {3 return (dispatch, getState) => {4 // 暫時的查詢條件.5 query = {organizationId:'0', rootCategoryId:'0'};6 return new api(getState().auth).getCourceDefs(query).then((courseDefs)=> dispatch(receiveCourseDefs(courseDefs)));7 }8}9export function receiveCourseDefs(courseDefs) {10 return {11 type: 'MASTER_RECEIVE_COURSEDEFS',12 courseDefs: courseDefs13 }14}15export function getCourseDef(courseDefId) {16 return (dispatch, getState) => {17 return new api(getState().auth).getCourseDef(courseDefId).then((courseDef)=> dispatch(receiveCourseDef(courseDef)));18 }19}20export function receiveCourseDef(courseDef) {21 return {22 type: 'RECEIVE_COURSE_DETAIL',23 courseDef: courseDef24 }25}26export function createCourseDef(courseDef){27 return (dispatch, getState) => {28 return new api(getState().auth).createCourseDef(courseDef).then((success)=> dispatch(getCourseDefs()));29 }30}31export function updateCourseDef(courseDef){32 return (dispatch, getState) => {33 return new api(getState().auth).updateCourseDef(courseDef).then((success)=> dispatch(getCourseDefs()));34 }35}36/** 設定 course,有值時 Course.jsx 會在有值時進入編輯模式,在沒值(null)時,進入新增模式 **/37export function setCourse(course){38 return {39 type: 'MASTER_SET_COURSE',40 course41 };42}43export function setExamQuestion(examQuestion) {44 return {45 type: 'MASTER_SET_EXAMQUESTION',46 examQuestion47 } ;48}49export function setActivity(activity) {50 return {51 type: 'MASTER_SET_ACTIVITY',52 activity53 } ;54}55export function createCourse(course){56 return (dispatch, getState) => {57 return new api(getState().auth).createCourse(course).then((success)=> dispatch(getCourses(course.courseDefId)));58 }59}60export function updateCourse(course){61 return (dispatch, getState) => {62 return new api(getState().auth).updateCourse(course).then((success)=> dispatch(getCourses(course.courseDefId)));63 }64}65export function getQuestions() {66 return (dispatch, getState) => {67 return new api(getState().auth).getQuestions().then((questions)=> dispatch(receiveQuestions(questions)));68 }69}70export function getExamQuestions() {71 return (dispatch, getState) => {72 return new api(getState().auth).getExamQuestions().then((examQuestions)=> dispatch(receiveExamQuestions(examQuestions)));73 }74}75export function receiveExamQuestions(examQuestions) {76 return {77 type: 'RECEIVE_EXAMQUESTIONS',78 examQuestions: examQuestions79 }80}81export function getTeachingMaterials() {82 return (dispatch, getState) => {83 return new api(getState().auth).getTeachingMaterials().then((teachingMaterials)=> dispatch(receiveTeachingMaterials(teachingMaterials)));84 }85}86export function receiveTeachingMaterials(teachingMaterials) {87 return {88 type: 'RECEIVE_TEACHING_MATERIALS',89 teachingMaterials: teachingMaterials90 }91}92export function getQuestion(questionId) {93 return (dispatch, getState) => {94 return new api(getState().auth).getQuestion(questionId).then((question)=> dispatch(receiveQuestion(question)));95 }96}97export function getExamQuestion(examQuestionId) {98 return (dispatch, getState) => {99 return new api(getState().auth).getExamQuestion(examQuestionId).then((examQuestion)=> dispatch(receiveExamQuestion(examQuestion)));100 }101}102export function receiveQuestion(question) {103 return {104 type: 'RECEIVE_QUESTION_DETAIL',105 question: question106 }107}108export function setQuestion(question) {109 return {110 type: 'RECEIVE_QUESTION_DETAIL',111 question112 } ;113}114export function receiveExamQuestion(examQuestion) {115 return {116 type: 'RECEIVE_EXAMQUESTION_DETAIL',117 examQuestion: examQuestion118 }119}120export function receiveQuestions(questions) {121 return {122 type: 'RECEIVE_QUESTIONS',123 questions: questions124 }125}126export function createQuestion(question){127 return (dispatch, getState) => {128 return new api(getState().auth).createQuestion(question).then((success)=> dispatch(getQuestions()));129 }130}131export function updateQuestion(question){132 return (dispatch, getState) => {133 return new api(getState().auth).updateQuestion(question).then((success)=> dispatch(getQuestions()));134 }135}136export function createExamQuestion(examQuestion){137 return (dispatch, getState) => {138 return new api(getState().auth).createExamQuestion(examQuestion).then((success)=> dispatch(getExamQuestions()));139 }140}141export function updateExamQuestion(examQuestion, examQuestionId){142 return (dispatch, getState) => {143 return new api(getState().auth).updateExamQuestion(examQuestion, examQuestionId).then((success)=> dispatch(getExamQuestions()));144 }145}146export function updateActivitiesOrder(activityOrder, courseId) {147 return(dispatch, getState) => {148 return new api(getState().auth).updateActivitiesOrder(activityOrder, courseId).then((success)=> dispatch(getCourseActivities(courseId)));149 }150}151export function getCourses(courseDefId) {152 return (dispatch, getState) => {153 // dispatch(cleanCourses());154 return new api(getState().auth).getCourses(courseDefId).then((courses)=> dispatch(receiveCourses(courses)));155 }156}157export function receiveCourses(courses) {158 return {159 type: 'RECEIVE_COURSES',160 courses: courses161 }162}163/* course candidates for 'CopyCoursePicker' */164export function getCopyCourses(courseDefId){165 return (dispatch, getState) => {166 // dispatch(cleanCopyCourses());167 return new api(getState().auth).getCourses(courseDefId).then((courses)=> dispatch(receiveCopyCourses(courses)));168 }169}170export function receiveCopyCourses(courses) {171 return {172 type: 'MASTER_RECEIVE_COPY_COURSES',173 courses174 }175}176export function cleanCopyCourses(){177 return {type: 'MASTER_CLEAN_COPY_COURSES'};178}179export function setCopyCourse(course){180 return {181 type: 'MASTER_SET_COPY_COURSE',182 course183 };184}185export function getCourse(courseId) {186 return (dispatch, getState) => {187 return new api(getState().auth).getCourse(courseId).then((course)=> dispatch(receiveCourse(course)));188 }189}190export function receiveCourse(course) {191 return {192 type: 'RECEIVE_COURSE',193 course: course194 }195}196export function getCourseOrderMembers(courseId,query) {197 return (dispatch, getState) => {198 return new api(getState().auth).getCourseOrderMembers(courseId,query).then((members)=> dispatch(receiveCourseOrderMembers(members)));199 }200}201export function receiveCourseOrderMembers(members) {202 return {203 type: 'RECEIVE_COURSE_ORDER_MEMBERS',204 members: members205 }206}207export function createCoursePaidUpload(courseId, members,query) {208 return (dispatch, getState) => {209 return new api(getState().auth).createCoursePaidUpload(courseId,members).then((success) => {210 dispatch(getCourseOrderMembers(courseId, query));211 dispatch(getCoursePaidUpload(courseId, members.members[0].id));212 }); 213 }214}215export function createCourseRefundUpload(courseId, members, query) {216 return (dispatch, getState) => {217 return new api(getState().auth).createCourseRefundUpload(courseId, members).then((success) => {218 dispatch(getCourseOrderMembers(courseId, query)) ;219 dispatch(getCourseRefundUpload(courseId,members.members[0].id)) ;220 });221 }222}223export function getCourseActivities(courseId) {224 return (dispatch, getState) => {225 return new api(getState().auth).getCourseActivities(courseId).then(activities=> dispatch(receiveCourseActivities(activities)));226 }227}228export function receiveCourseActivities(activities) {229 return {230 type: 'RECEIVE_COURSE_ACTIVITIES',231 activities: activities232 }233}234/**************** clean code ***************/235export function cleanCourses(){236 return {type: 'MASTER_CLEAN_COURSES'};237}238export function updateOrderPaymentStatus(orders,courseId, query) {239 return (dispatch, getState) => {240 return new api(getState().auth).updateOrderPaymentStatus(orders).then((success) => dispatch(getCourseOrderMembers(courseId,query)));241 }242}243export function createCourseActivity(courseId, activity) {244 return (dispatch, getState) => {245 return new api(getState().auth).createCourseActivity(courseId, activity).then((success) => dispatch(getCourseActivities(courseId)))246 }247}248export function updateCourseActivity(courseId, activityId, activity) {249 return (dispatch, getState) => {250 return new api(getState().auth).updateCourseActivity(courseId, activityId, activity).then((success) => dispatch(getCourseActivities(courseId)))251 }252}253export function getActivity(courseId, activityId) {254 return (dispatch, getState) => {255 return new api(getState().auth).getActivity(courseId, activityId).then((activity) => dispatch(receiveActivity(activity)))256 }257}258export function receiveActivity(activity) {259 return {260 type: 'RECEIVE_ACTIVITY',261 activity: activity262 }263}264export function getActivityStatistics(courseId) {265 return (dispatch, getState) => {266 return new api(getState().auth).getActivityStatistics(courseId).then((questionnaire) => dispatch(receiveQuestionnaire(questionnaire)))267 }268}269export function receiveQuestionnaire(questionnaire) {270 return {271 type: 'RECEIVE_ACTIVITY_STATISTICS',272 questionnaire: questionnaire273 }274}275export function getCoursePaidMembers(courseId, query) {276 return (dispatch, getState) => {277 return new api(getState().auth).getCoursePaidMembers(courseId, query).then(members=> dispatch(receiveCoursePaidMembers(members)));278 }279}280export function receiveCoursePaidMembers(members) {281 return {282 type: 'RECEIVE_COURSE_PAID_MEMBERS',283 members: members284 }285}286export function getCoursePaidUpload(courseId, memberId) {287 return (dispatch, getState) => {288 return new api(getState().auth).getCoursePaidUpload(courseId, memberId).then((memberCoursePaidUploadRecord)=> 289 dispatch(receiveCoursePaidUpload(memberCoursePaidUploadRecord)));290 }291}292export function receiveCoursePaidUpload(memberCoursePaidUploadRecord) {293 return {294 type: 'RECEIVE_MEMBER_COURSE_PAID_UPLOAD_RECORD',295 memberCoursePaidUploadRecord: memberCoursePaidUploadRecord296 }297}298export function getCourseRefundUpload(courseId, memberId) {299 return (dispatch, getState) => {300 return new api(getState().auth).getCourseRefundUpload(courseId, memberId).then((memberCourseRefundUploadRecord)=> 301 dispatch(receiveCourseRefundUpload(memberCourseRefundUploadRecord)));302 }303}304export function receiveCourseRefundUpload(memberCourseRefundUploadRecord) {305 return {306 type: 'RECEIVE_MEMBER_COURSE_REFUND_UPLOAD_RECORD',307 memberCourseRefundUploadRecord: memberCourseRefundUploadRecord308 }309}310export function setEmptyPaidUpload(memberCoursePaidUploadRecord){311 return {312 type: 'RECEIVE_MEMBER_COURSE_PAID_UPLOAD_RECORD',313 memberCoursePaidUploadRecord:memberCoursePaidUploadRecord314 }315}316export function setEmptyRefundUpload(memberCourseRefundUploadRecord){317 return {318 type: 'RECEIVE_MEMBER_COURSE_REFUND_UPLOAD_RECORD',319 memberCourseRefundUploadRecord:memberCourseRefundUploadRecord320 }321}322export function setEmptyTeachingMaterial(teachingMaterialView){323 return {324 type: 'RECEIVE_TEACHING_MATERIAL_VIEW',325 teachingMaterialView:teachingMaterialView326 }327}328export function setEmptyAttendDate(attendDateView){329 return {330 type: 'RECEIVE_ATTEND_DATE_VIEW',331 attendDateView:attendDateView332 }333}334export function setEmptyChapterScores(chapterScoresView){335 return {336 type: 'RECEIVE_CHAPTER_SCORES_VIEW',337 chapterScoresView:chapterScoresView338 }339}340export function setEmptyNotices(noticeView) {341 return {342 type: 'RECEIVE_NOTICE_VIEW',343 noticeView:noticeView344 }345}346export function getStudentTeachingMaterialView(courseId, memberId) {347 return (dispatch, getState) => {348 return new api(getState().auth).getStudentTeachingMaterialView(courseId, memberId).then((teachingMaterialView) => 349 dispatch(receiveStudentTeachingMaterialView(teachingMaterialView)))350 }351}352export function receiveStudentTeachingMaterialView(teachingMaterialView) {353 return {354 type: 'RECEIVE_TEACHING_MATERIAL_VIEW',355 teachingMaterialView: teachingMaterialView356 }357}358export function getStudentAttendDateView(courseId, memberId) {359 return (dispatch, getState) => {360 return new api(getState().auth).getStudentAttendDateView(courseId, memberId).then((attendDateView) => 361 dispatch(receiveStudentAttendDateView(attendDateView)))362 }363}364export function receiveStudentAttendDateView(attendDateView) {365 return {366 type: 'RECEIVE_ATTEND_DATE_VIEW',367 attendDateView: attendDateView368 }369}370export function getStudentChapterScoresView(courseId, memberId) {371 return (dispatch, getState) => {372 return new api(getState().auth).getStudentChapterScoresView(courseId, memberId).then((chapterScoresView) => 373 dispatch(receiveStudentChapterScoresView(chapterScoresView)))374 }375}376export function receiveStudentChapterScoresView(chapterScoresView) {377 return {378 type: 'RECEIVE_CHAPTER_SCORES_VIEW',379 chapterScoresView: chapterScoresView380 }381}382export function getStudentNoticeView(courseId, memberId) {383 return (dispatch, getState) => {384 return new api(getState().auth).getStudentNoticeView(courseId, memberId).then((noticeView) => 385 dispatch(receiveStudentNoticeView(noticeView)))386 }387}388export function receiveStudentNoticeView(noticeView) {389 return {390 type: 'RECEIVE_NOTICE_VIEW',391 noticeView: noticeView392 }393}394export function getCourseStudentScores(courseId, members, query) {395 return (dispatch, getState) => {396 return new api(getState().auth).getCourseStudentScores(courseId, members).then((success) => 397 dispatch(getCoursePaidMembers(courseId, query)))398 }399} 400export function postAttendStudents(courseId, attendStudents, query) {401 return (dispatch, getState) => {402 return new api(getState().auth).postAttendStudents(courseId, attendStudents).then((success) => 403 dispatch(getCoursePaidMembers(courseId, query)))404 }405}406export function postMemberScores(members, courseId, chapterId, query) {407 return (dispatch, getState) => {408 return new api(getState().auth).postMemberScores(members, courseId, chapterId).then((success) => 409 dispatch(getCoursePaidMembers(courseId, query)))410 }411}412export function postWebNotices(courseId, model, query) {413 return (dispatch, getState) => {414 return new api(getState().auth).postWebNotices(model).then((success) => 415 dispatch(getCoursePaidMembers(courseId, query)))416 }417}418export function getTeachingMaterial(teachingMaterialId) {419 return (dispatch, getState) => {420 return new api(getState().auth).getTeachingMaterial(teachingMaterialId).then((teachingMaterial) => dispatch(receiveTeachingMaterial(teachingMaterial)));421 }422}423export function receiveTeachingMaterial(teachingMaterial) {424 return {425 type: 'RECEIVE_TEACHING_MATERIAL',426 teachingMaterial: teachingMaterial427 }428}429export function updateTeachingMaterial(teachingMaterialId,teachingMaterial) {430 return (dispatch, getState) => {431 return new api(getState().auth).updateTeachingMaterial(teachingMaterialId,teachingMaterial).then((success) =>432 dispatch(getTeachingMaterial(teachingMaterialId)));433 }...

Full Screen

Full Screen

chain.js

Source:chain.js Github

copy

Full Screen

...10 });11 it('should automatically complete when run with no children', function() {12 var chain = new tr.Chain();13 chain.run();14 expect(chain.getState()).toBe(tr.enums.State.COMPLETED);15 });16 it('should invoke the optional completed callback on success', function() {17 var callback = jasmine.createSpy();18 19 var chain = new tr.Chain(callback).run();20 expect(chain.getState()).toBe(tr.enums.State.COMPLETED);21 expect(callback).toHaveBeenCalled();22 });23 it('should invoke the optional errorred callback on failure', function() {24 var callback = jasmine.createSpy();25 26 var chain = new tr.Chain(null, callback).first(stubTaskA).run();27 stubTaskA.error();28 expect(chain.getState()).toBe(tr.enums.State.ERRORED);29 expect(callback).toHaveBeenCalled();30 });31 it('should start with the task passed to first()', function() {32 var chain = new tr.Chain().first(stubTaskA).run();33 expect(chain.getState()).toBe(tr.enums.State.RUNNING);34 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);35 stubTaskA.complete();36 expect(chain.getState()).toBe(tr.enums.State.COMPLETED);37 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);38 });39 it('should start with the task passed to then() if none is passed to first()', function() {40 var chain = new tr.Chain().then(stubTaskA).run();41 expect(chain.getState()).toBe(tr.enums.State.RUNNING);42 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);43 stubTaskA.complete();44 expect(chain.getState()).toBe(tr.enums.State.COMPLETED);45 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);46 });47 it('should fail if first() is called after stubTasks have been added to the chain', function() {48 expect(function() {49 new tr.Chain().first(stubTaskA).first(stubTaskB).run();50 }).toThrow();51 });52 it('should continue from a completed task to the next task passed to then()', function() {53 var chain = new tr.Chain().first(stubTaskA).then(stubTaskB).run();54 expect(chain.getState()).toBe(tr.enums.State.RUNNING);55 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);56 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);57 stubTaskA.complete();58 expect(chain.getState()).toBe(tr.enums.State.RUNNING);59 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);60 expect(stubTaskB.getState()).toBe(tr.enums.State.RUNNING);61 stubTaskB.complete();62 expect(chain.getState()).toBe(tr.enums.State.COMPLETED);63 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);64 expect(stubTaskB.getState()).toBe(tr.enums.State.COMPLETED);65 });66 it('should execute multiple stubTasks in parallel if they are passed to then then()', function() {67 var chain = new tr.Chain().first(stubTaskA).then(stubTaskB, stubTaskC).run();68 expect(chain.getState()).toBe(tr.enums.State.RUNNING);69 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);70 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);71 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);72 stubTaskA.complete();73 expect(chain.getState()).toBe(tr.enums.State.RUNNING);74 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);75 expect(stubTaskB.getState()).toBe(tr.enums.State.RUNNING);76 expect(stubTaskC.getState()).toBe(tr.enums.State.RUNNING);77 stubTaskB.complete();78 expect(chain.getState()).toBe(tr.enums.State.RUNNING);79 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);80 expect(stubTaskB.getState()).toBe(tr.enums.State.COMPLETED);81 expect(stubTaskC.getState()).toBe(tr.enums.State.RUNNING);82 stubTaskC.complete();83 expect(chain.getState()).toBe(tr.enums.State.COMPLETED);84 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);85 expect(stubTaskB.getState()).toBe(tr.enums.State.COMPLETED);86 expect(stubTaskC.getState()).toBe(tr.enums.State.COMPLETED);87 });88 it('should execute all of the stubTask(s) passed to or() if the proceeding task fails', function() {89 var chain = new tr.Chain().first(stubTaskA).or(stubTaskB, stubTaskC).run();90 expect(chain.getState()).toBe(tr.enums.State.RUNNING);91 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);92 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);93 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);94 stubTaskA.error();95 expect(chain.getState()).toBe(tr.enums.State.RUNNING);96 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);97 expect(stubTaskB.getState()).toBe(tr.enums.State.RUNNING);98 expect(stubTaskC.getState()).toBe(tr.enums.State.RUNNING);99 });100 it('should continue if all tasks passed to or() complete', function() {101 var chain = new tr.Chain().first(stubTaskA).or(stubTaskB, stubTaskC).run();102 expect(chain.getState()).toBe(tr.enums.State.RUNNING);103 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);104 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);105 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);106 stubTaskA.error();107 expect(chain.getState()).toBe(tr.enums.State.RUNNING);108 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);109 expect(stubTaskB.getState()).toBe(tr.enums.State.RUNNING);110 expect(stubTaskC.getState()).toBe(tr.enums.State.RUNNING);111 stubTaskB.complete();112 stubTaskC.complete();113 expect(chain.getState()).toBe(tr.enums.State.COMPLETED);114 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);115 expect(stubTaskB.getState()).toBe(tr.enums.State.COMPLETED);116 expect(stubTaskC.getState()).toBe(tr.enums.State.COMPLETED);117 });118 it('should fail if some of the tasks passed to a single or() error', function() {119 var chain = new tr.Chain().first(stubTaskA).or(stubTaskB, stubTaskC).run();120 expect(chain.getState()).toBe(tr.enums.State.RUNNING);121 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);122 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);123 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);124 stubTaskA.error();125 expect(chain.getState()).toBe(tr.enums.State.RUNNING);126 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);127 expect(stubTaskB.getState()).toBe(tr.enums.State.RUNNING);128 expect(stubTaskC.getState()).toBe(tr.enums.State.RUNNING);129 stubTaskB.error();130 stubTaskC.complete();131 expect(chain.getState()).toBe(tr.enums.State.ERRORED);132 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);133 expect(stubTaskB.getState()).toBe(tr.enums.State.ERRORED);134 expect(stubTaskC.getState()).toBe(tr.enums.State.COMPLETED);135 });136 it('should not execute the task passed to or() if the proceeding task suceeds', function() {137 var chain = new tr.Chain().first(stubTaskA).or(stubTaskB).then(stubTaskC).run();138 expect(chain.getState()).toBe(tr.enums.State.RUNNING);139 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);140 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);141 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);142 stubTaskA.complete();143 expect(chain.getState()).toBe(tr.enums.State.RUNNING);144 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);145 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);146 expect(stubTaskC.getState()).toBe(tr.enums.State.RUNNING);147 stubTaskC.complete();148 expect(chain.getState()).toBe(tr.enums.State.COMPLETED);149 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);150 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);151 expect(stubTaskC.getState()).toBe(tr.enums.State.COMPLETED);152 });153 it('should error if no or() task follows a failed stubTask', function() {154 var chain = new tr.Chain().first(stubTaskA).then(stubTaskB).run();155 expect(chain.getState()).toBe(tr.enums.State.RUNNING);156 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);157 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);158 stubTaskA.error();159 expect(chain.getState()).toBe(tr.enums.State.ERRORED);160 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);161 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);162 });163 it('should error if none of the tasks provided to or() complete', function() {164 var chain = new tr.Chain().first(stubTaskA).or(stubTaskB, stubTaskC).run();165 expect(chain.getState()).toBe(tr.enums.State.RUNNING);166 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);167 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);168 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);169 stubTaskA.error();170 expect(chain.getState()).toBe(tr.enums.State.RUNNING);171 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);172 expect(stubTaskB.getState()).toBe(tr.enums.State.RUNNING);173 expect(stubTaskC.getState()).toBe(tr.enums.State.RUNNING);174 stubTaskB.error();175 expect(chain.getState()).toBe(tr.enums.State.RUNNING);176 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);177 expect(stubTaskB.getState()).toBe(tr.enums.State.ERRORED);178 expect(stubTaskC.getState()).toBe(tr.enums.State.RUNNING);179 stubTaskC.error();180 expect(chain.getState()).toBe(tr.enums.State.ERRORED);181 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);182 expect(stubTaskB.getState()).toBe(tr.enums.State.ERRORED);183 expect(stubTaskC.getState()).toBe(tr.enums.State.ERRORED);184 });185 it('should allow or() calls to be chained', function() {186 var chain = new tr.Chain().first(stubTaskA).or(stubTaskB).or(stubTaskC).run();187 expect(chain.getState()).toBe(tr.enums.State.RUNNING);188 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);189 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);190 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);191 stubTaskA.error();192 expect(chain.getState()).toBe(tr.enums.State.RUNNING);193 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);194 expect(stubTaskB.getState()).toBe(tr.enums.State.RUNNING);195 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);196 stubTaskB.error();197 expect(chain.getState()).toBe(tr.enums.State.RUNNING);198 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);199 expect(stubTaskB.getState()).toBe(tr.enums.State.ERRORED);200 expect(stubTaskC.getState()).toBe(tr.enums.State.RUNNING);201 stubTaskC.complete();202 expect(chain.getState()).toBe(tr.enums.State.COMPLETED);203 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);204 expect(stubTaskB.getState()).toBe(tr.enums.State.ERRORED);205 expect(stubTaskC.getState()).toBe(tr.enums.State.COMPLETED);206 });207 it('should interrupt children when interrupted', function() {208 var chain = new tr.Chain().first(stubTaskA).then(stubTaskB).run();209 expect(chain.getState()).toBe(tr.enums.State.RUNNING);210 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);211 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);212 stubTaskA.complete();213 expect(chain.getState()).toBe(tr.enums.State.RUNNING);214 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);215 expect(stubTaskB.getState()).toBe(tr.enums.State.RUNNING);216 chain.interrupt();217 expect(chain.getState()).toBe(tr.enums.State.INTERRUPTED);218 expect(stubTaskA.getState()).toBe(tr.enums.State.COMPLETED);219 expect(stubTaskB.getState()).toBe(tr.enums.State.INTERRUPTED);220 });221 it('should reset children when reset', function() {222 var chain = new tr.Chain().first(stubTaskA).then(stubTaskB).run();223 expect(chain.getState()).toBe(tr.enums.State.RUNNING);224 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);225 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);226 stubTaskA.error();227 expect(chain.getState()).toBe(tr.enums.State.ERRORED);228 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);229 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);230 chain.reset();231 expect(chain.getState()).toBe(tr.enums.State.INITIALIZED);232 expect(stubTaskA.getState()).toBe(tr.enums.State.INITIALIZED);233 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);234 });235 it('should return the correct number of children', function() {236 var chain = new tr.Chain().first(stubTaskA).then(stubTaskB, stubTaskC).then(stubTaskD).or(stubTaskE).then(stubTaskF).run();237 expect(chain.getOperationsCount()).toBe(6);238 stubTaskA.complete();239 expect(chain.getCompletedOperationsCount()).toBe(1);240 stubTaskB.complete();241 expect(chain.getCompletedOperationsCount()).toBe(2);242 stubTaskC.complete();243 expect(chain.getCompletedOperationsCount()).toBe(3);244 stubTaskD.complete();245 expect(chain.getCompletedOperationsCount()).toBe(5);246 stubTaskF.complete();247 expect(chain.getCompletedOperationsCount()).toBe(6);248 });249 it('should preserve the parallal behavior of then() when followed by or()', function() {250 var chain = new tr.Chain().first(stubTaskA, stubTaskB).or(stubTaskC).run();251 expect(chain.getState()).toBe(tr.enums.State.RUNNING);252 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);253 expect(stubTaskB.getState()).toBe(tr.enums.State.RUNNING);254 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);255 });256 it('should alias or() with else() and otherwise()', function() {257 var chain = new tr.Chain().first(stubTaskA).else(stubTaskB).otherwise(stubTaskC).run();258 expect(chain.getState()).toBe(tr.enums.State.RUNNING);259 expect(stubTaskA.getState()).toBe(tr.enums.State.RUNNING);260 expect(stubTaskB.getState()).toBe(tr.enums.State.INITIALIZED);261 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);262 stubTaskA.error();263 expect(chain.getState()).toBe(tr.enums.State.RUNNING);264 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);265 expect(stubTaskB.getState()).toBe(tr.enums.State.RUNNING);266 expect(stubTaskC.getState()).toBe(tr.enums.State.INITIALIZED);267 stubTaskB.error();268 expect(chain.getState()).toBe(tr.enums.State.RUNNING);269 expect(stubTaskA.getState()).toBe(tr.enums.State.ERRORED);270 expect(stubTaskB.getState()).toBe(tr.enums.State.ERRORED);271 expect(stubTaskC.getState()).toBe(tr.enums.State.RUNNING);272 });...

Full Screen

Full Screen

core.js

Source:core.js Github

copy

Full Screen

...63 statechart.destroy();64 }65});66test("check initial statechart history states", function() {67 equals(statechart.get('rootState').get('historyState'), statechart.getState('a'), 'root state\'s history state should be state a');68 69 equals(statechart.getState('a').get('historyState'), statechart.getState('c'), 'state a\'s history state should be state c');70 equals(statechart.getState('c').get('historyState'), statechart.getState('g'), 'state c\'s history state should be state g');71 equals(statechart.getState('g').get('historyState'), null, 'state g\'s history state should be null');72 73 equals(statechart.getState('h').get('historyState'), null, 'state h\'s history state should be null');74 equals(statechart.getState('d').get('historyState'), null, 'state d\'s history state should be null');75 equals(statechart.getState('b').get('historyState'), null, 'state b\'s history state should be null');76 equals(statechart.getState('e').get('historyState'), null, 'state e\'s history state should be null');77 equals(statechart.getState('f').get('historyState'), null, 'state f\'s history state should be null');78});79test("go to state h and check history states", function() {80 var monitor = statechart.get('monitor');81 monitor.reset();82 83 statechart.gotoState('h');84 equals(monitor.matchSequence().begin().exited('g').entered('h').end(), true, 'sequence should be exited[f], entered[h]');85 86 equals(statechart.getState('a').get('historyState'), statechart.getState('c'), 'state a\'s history state should be state c');87 equals(statechart.getState('c').get('historyState'), statechart.getState('h'), 'state c\'s history state should be state h');88 equals(statechart.getState('h').get('historyState'), null, 'state h\'s history state should be null');89 equals(statechart.getState('g').get('historyState'), null, 'state g\'s history state should be null');90 91 equals(statechart.getState('d').get('historyState'), null, 'state d\'s history state should be null');92 equals(statechart.getState('b').get('historyState'), null, 'state b\'s history state should be null');93});94test("go to state d and check history states", function() {95 var monitor = statechart.get('monitor');96 monitor.reset();97 98 statechart.gotoState('d');99 equals(monitor.matchSequence().begin().exited('g', 'c').entered('d', 'i').end(), true, 'sequence should be exited[g, c], entered[d, i]');100 101 equals(statechart.getState('a').get('historyState'), statechart.getState('d'), 'state a\'s history state should be state d');102 equals(statechart.getState('d').get('historyState'), statechart.getState('i'), 'state d\'s history state should be state i');103 equals(statechart.getState('c').get('historyState'), statechart.getState('g'), 'state c\'s history state should be state g');104 equals(statechart.getState('h').get('historyState'), null, 'state h\'s history state should be null');105 equals(statechart.getState('g').get('historyState'), null, 'state g\'s history state should be null');106 equals(statechart.getState('i').get('historyState'), null, 'state i\'s history state should be null');107 equals(statechart.getState('j').get('historyState'), null, 'state j\'s history state should be null');108 109 equals(statechart.getState('b').get('historyState'), null, 'state b\'s history state should be null');110});111test("go to state b and check history states", function() {112 var monitor = statechart.get('monitor');113 monitor.reset();114 115 statechart.gotoState('b');116 equals(monitor.matchSequence().begin().exited('g', 'c', 'a').entered('b', 'e', 'k').end(), true, 'sequence should be exited[g, c, a], entered[b, e, k]');117 118 equals(statechart.get('rootState').get('historyState'), statechart.getState('b'), 'root state\'s history state should be state b');119 equals(statechart.getState('b').get('historyState'), statechart.getState('e'), 'state b\'s history state should be e');120 equals(statechart.getState('e').get('historyState'), statechart.getState('k'), 'state e\'s history state should be k');121 equals(statechart.getState('a').get('historyState'), statechart.getState('c'), 'state a\'s history state should be state c');122 equals(statechart.getState('c').get('historyState'), statechart.getState('g'), 'state c\'s history state should be state g');123});124test("go to state j, then state m, then go to state a's history state (non-recursive)", function() {125 var monitor = statechart.get('monitor');126 127 statechart.gotoState('j');128 statechart.gotoState('m');129 monitor.reset();130 statechart.gotoHistoryState('a');131 132 equals(monitor.get('length'), 6, 'initial state sequence should be of length 6');133 equals(monitor.matchSequence().begin().exited('m', 'f', 'b').entered('a', 'd', 'i').end(), true, 'sequence should be exited[m, f, b], entered[a, d, i]');134 equals(statechart.get('currentStateCount'), 1, 'current state count should be 1');135 equals(statechart.stateIsCurrentState('i'), true, 'current state should be i');136 equals(statechart.get('rootState').get('historyState'), statechart.getState('a'), 'root state\'s history state should be state a');137 equals(statechart.getState('a').get('historyState'), statechart.getState('d'), 'state a\'s history state should be state d');138 equals(statechart.getState('d').get('historyState'), statechart.getState('i'), 'state d\'s history state should be state i');139 140});141test("go to state j, then state m, then go to state a's history state (recursive)", function() {142 var monitor = statechart.get('monitor');143 144 statechart.gotoState('j');145 statechart.gotoState('m');146 monitor.reset();147 statechart.gotoHistoryState('a', null, YES);148 149 equals(monitor.get('length'), 6, 'initial state sequence should be of length 6');150 equals(monitor.matchSequence().begin().exited('m', 'f', 'b').entered('a', 'd', 'j').end(), true, 'sequence should be exited[m, f, b], entered[a, d, j]');151 equals(statechart.get('currentStateCount'), 1, 'current state count should be 1');152 equals(statechart.stateIsCurrentState('j'), true, 'current state should be j');153 equals(statechart.get('rootState').get('historyState'), statechart.getState('a'), 'root state\'s history state should be state a');154 equals(statechart.getState('a').get('historyState'), statechart.getState('d'), 'state a\'s history state should be state d');155 equals(statechart.getState('d').get('historyState'), statechart.getState('j'), 'state d\'s history state should be state j');156});157test("go to state b's history state (non-recursive)", function() {158 var monitor = statechart.get('monitor');159 monitor.reset();160 statechart.gotoHistoryState('b');161 162 equals(monitor.get('length'), 6, 'initial state sequence should be of length 6');163 equals(monitor.matchSequence().begin().exited('g', 'c', 'a').entered('b', 'e', 'k').end(), true, 'sequence should be exited[g, c, a], entered[b, e, k]');164 equals(statechart.get('currentStateCount'), 1, 'current state count should be 1');165 equals(statechart.stateIsCurrentState('k'), true, 'current state should be k');166 equals(statechart.get('rootState').get('historyState'), statechart.getState('b'), 'root state\'s history state should be state b');167 equals(statechart.getState('b').get('historyState'), statechart.getState('e'), 'state b\'s history state should be state e');168 equals(statechart.getState('e').get('historyState'), statechart.getState('k'), 'state e\'s history state should be state k');169});170test("go to state b's history state (recursive)", function() {171 var monitor = statechart.get('monitor');172 monitor.reset();173 statechart.gotoHistoryState('b', null, YES);174 175 equals(monitor.get('length'), 6, 'initial state sequence should be of length 6');176 equals(monitor.matchSequence().begin().exited('g', 'c', 'a').entered('b', 'e', 'k').end(), true, 'sequence should be exited[g, c, a], entered[b, e, k]');177 equals(statechart.get('currentStateCount'), 1, 'current state count should be 1');178 equals(statechart.stateIsCurrentState('k'), true, 'current state should be k');179 equals(statechart.get('rootState').get('historyState'), statechart.getState('b'), 'root state\'s history state should be state b');180 equals(statechart.getState('b').get('historyState'), statechart.getState('e'), 'state b\'s history state should be state e');181 equals(statechart.getState('e').get('historyState'), statechart.getState('k'), 'state e\'s history state should be state k');...

Full Screen

Full Screen

without_concurrent_states.js

Source:without_concurrent_states.js Github

copy

Full Screen

...76});77test("check initial substate after statechart init", function() {78 var monitor = statechart.get('monitor'),79 root = statechart.get('rootState'),80 a = statechart.getState('a'),81 b = statechart.getState('b'),82 c = statechart.getState('c'),83 d = statechart.getState('d'),84 e = statechart.getState('e'),85 f = statechart.getState('f'),86 g = statechart.getState('g'),87 h = statechart.getState('h'),88 i = statechart.getState('i'),89 j = statechart.getState('j'),90 k = statechart.getState('k'),91 l = statechart.getState('l'),92 m = statechart.getState('m'),93 n = statechart.getState('n'),94 aInitSubstate = a.get('initialSubstate'),95 bInitSubstate = b.get('initialSubstate');96 97 equals(monitor.get('length'), 4, 'initial state sequence should be of length 3');98 equals(monitor.matchSequence().begin().entered(root, a, c, g).end(), true, 'initial sequence should be entered[root, a, c, g]');99 100 equals(root.get('initialSubstate'), a, "root state's initial substate should be state a");101 equals(c.get('initialSubstate'), g, "c state's initial substate should be state g");102 equals(d.get('initialSubstate'), i, "d state's initial substate should be state i");103 equals(e.get('initialSubstate'), k, "e state's initial substate should be state k");104 equals(f.get('initialSubstate'), m, "f state's initial substate should be state m");105 equals(SC.kindOf(aInitSubstate, SC.HistoryState), true, "a state's initial substate should be of type SC.HistoryState");106 equals(aInitSubstate.get('isRecursive'), false, "a's initial substate should not be recursive");107 equals(aInitSubstate.get('defaultState'), c, "a's initial substate should have default state c");108 equals(aInitSubstate.get('statechart'), statechart, "a's initial substate should have an assigned statechart");109 equals(aInitSubstate.get('parentState'), a, "a's initial substate should have parent state a");110 equals(aInitSubstate.get('state'), c, "a's initial substate state should be state c");111 equals(SC.kindOf(bInitSubstate, SC.HistoryState), true, "b state's initial substate should be of type SC.HistoryState");112 equals(bInitSubstate.get('isRecursive'), true, "b's initial substate should be recursive");113 equals(bInitSubstate.get('defaultState'), e, "b's initial substate should have default state e");114 equals(bInitSubstate.get('statechart'), statechart, "b's initial substate should have an assigned statechart");115 equals(bInitSubstate.get('parentState'), b, "b's initial substate should have parent state b");116 equals(bInitSubstate.get('state'), e, "b's initial substate state should be state e");117 118 equals(a.get('historyState'), c);119 equals(b.get('historyState'), null);120});121test("check state sequence after going to state b", function() {122 var monitor = statechart.get('monitor'),123 root = statechart.get('rootState'),124 b = statechart.getState('b'),125 e = statechart.getState('e');126 monitor.reset();127 128 statechart.gotoState('b');129 130 equals(b.get('historyState'), e); 131 equals(b.getPath('initialSubstate.state'), e);132 133 equals(monitor.get('length'), 6, 'initial state sequence should be of length 6');134 equals(monitor.matchSequence()135 .begin()136 .exited('g', 'c', 'a')137 .entered('b', 'e', 'k')138 .end(), true,139 'sequence should be exited[g, c, a], entered[b, e, k]');140});141test("check state sequence with state a's historyState assigned", function() {142 var monitor = statechart.get('monitor'),143 root = statechart.get('rootState'),144 a = statechart.getState('a'),145 b = statechart.getState('b'),146 c = statechart.getState('c'),147 d = statechart.getState('d'),148 e = statechart.getState('e'),149 f = statechart.getState('f'),150 g = statechart.getState('g'),151 h = statechart.getState('h'),152 i = statechart.getState('i'),153 j = statechart.getState('j'),154 k = statechart.getState('k'),155 l = statechart.getState('l'),156 m = statechart.getState('m'),157 n = statechart.getState('n');158 159 statechart.gotoState('j');160 161 equals(a.get('historyState'), d);162 equals(d.get('historyState'), j);163 164 equals(a.getPath('initialSubstate.state'), d);165 166 statechart.gotoState('b');167 168 monitor.reset();169 170 statechart.gotoState('a');171 172 equals(monitor.get('length'), 6, 'initial state sequence should be of length 6');173 equals(monitor.matchSequence()174 .begin()175 .exited(k, e, b)176 .entered(a, d, i)177 .end(), true,178 'sequence should be exited[k, e, b], entered[a, d, i]');179 180});181test("check state sequence with state b's historyState assigned", function() {182 var monitor = statechart.get('monitor'),183 root = statechart.get('rootState'),184 b = statechart.getState('b'),185 f = statechart.getState('f'),186 n = statechart.getState('n');187 188 statechart.gotoState('n');189 190 equals(b.get('historyState'), f);191 equals(f.get('historyState'), n);192 193 equals(b.getPath('initialSubstate.state'), f);194 195 statechart.gotoState('a');196 197 monitor.reset();198 199 statechart.gotoState('b');200 ...

Full Screen

Full Screen

store.spec.js

Source:store.spec.js Github

copy

Full Screen

...13 afterAll(() => MockDate.reset());14 it('should display results when necessary data is provided', () => {15 const store = configureStore();16 const actions = [17 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'newMpg', value: 20 },18 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'tradeMpg', value: 10 },19 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'newPpg', value: 1.50 },20 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'tradePpg', value: 1.50 },21 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'milesDriven', value: 100 },22 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'milesDrivenTimeframe', value: 'month' }23 ];24 actions.forEach(action => store.dispatch(action));25 const actual = store.getState();26 const expected = {27 newMpg: 20,28 tradeMpg: 10,29 newPpg: 1.50,30 tradePpg: 1.50,31 milesDriven: 100,32 milesDrivenTimeframe: 'month',33 displayResults: false,34 dateModified,35 necessaryDataIsProvidedToCalculateSavings: true,36 savings: calculateSavings(store.getState().fuelSavings)37 };38 expect(actual.fuelSavings).toEqual(expected);39 });40 it('should not display results when necessary data is not provided', () => {41 const store = configureStore();42 const actions = [43 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'newMpg', value: 20 },44 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'tradeMpg', value: 10 },45 // { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'newPpg', value: 1.50 },46 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'tradePpg', value: 1.50 },47 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'milesDriven', value: 100 },48 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'milesDrivenTimeframe', value: 'month' }49 ];50 actions.forEach(action => store.dispatch(action));51 const actual = store.getState();52 const expected = {53 newMpg: 20,54 tradeMpg: 10,55 newPpg: '',56 tradePpg: 1.5,57 milesDriven: 100,58 milesDrivenTimeframe: 'month',59 displayResults: false,60 dateModified,61 necessaryDataIsProvidedToCalculateSavings: false,62 savings: { annual: 0, monthly: 0, threeYear: 0 }63 };64 expect(actual.fuelSavings).toEqual(expected);65 });66 it('should handle a flurry of actions', () => {67 const store = configureStore();68 const actions = [69 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'newMpg', value: 20 },70 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'tradeMpg', value: 10 },71 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'newPpg', value: 1.50 },72 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'tradePpg', value: 1.50 },73 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'milesDriven', value: 100 },74 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'milesDrivenTimeframe', value: 'month' },75 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'newMpg', value: 20 },76 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'tradeMpg', value: 10 },77 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'newPpg', value: 1.50 },78 { type: ActionTypes.SAVE_FUEL_SAVINGS, dateModified, settings: store.getState() },79 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'tradePpg', value: 1.50 },80 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'milesDriven', value: 100 },81 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'milesDrivenTimeframe', value: 'week' },82 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'newMpg', value: 20 },83 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'tradeMpg', value: 10 },84 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'newPpg', value: 1.50 }85 ];86 actions.forEach(action => store.dispatch(action));87 calculateSavings(store.getState().fuelSavings);88 const moreActions = [89 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'tradePpg', value: 0 },90 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'milesDriven', value: 100 },91 { type: ActionTypes.CALCULATE_FUEL_SAVINGS, dateModified, settings: store.getState(), fieldName: 'milesDrivenTimeframe', value: 'year' }92 ];93 moreActions.forEach(action => store.dispatch(action));94 const actual = store.getState();95 //const expected = {96 // newMpg: 20,97 // tradeMpg: 10,98 // newPpg: 1.50,99 // tradePpg: 0,100 // milesDriven: 100,101 // milesDrivenTimeframe: 'year',102 // displayResults: false,103 // dateModified,104 // necessaryDataIsProvidedToCalculateSavings: false,105 // savings: lastGoodSavings106 //};107 //108 //expect(actual.fuelSavings).toEqual(expected);...

Full Screen

Full Screen

get_state.js

Source:get_state.js Github

copy

Full Screen

...58test("get existing, umambiguous states from state Z", function() {59 var state,60 z = root.getSubstate('z');61 62 state = z.getState('z');63 equals(state, z, "should return self for value 'z'");64 65 state = z.getState(z);66 equals(state, z, "should return self for value state Z");67 68 state = z.getState('a');69 equals(state.get('fullPath'), 'a', "should return state for value 'a'");70 equals(z.getState(state).get('fullPath'), 'a', "should return state for state A");71 72 state = z.getState('b');73 equals(state.get('fullPath'), 'b', "should return state for value 'b'");74 75 state = z.getState('c');76 equals(state.get('fullPath'), 'c', "should return state for value 'c'");77 78 state = z.getState('foo');79 equals(state.get('fullPath'), 'a.foo', "should return state for value 'foo'");80 81 state = z.getState('a.foo');82 equals(state.get('fullPath'), 'a.foo', "should return state for value 'a.foo'");83 84 state = z.getState('bar');85 equals(state.get('fullPath'), 'b.bar', "should return state for value 'bar'");86 87 state = z.getState('b.bar');88 equals(state.get('fullPath'), 'b.bar', "should return state for value 'a.bar'");89 90 state = z.getState('a.x');91 equals(state.get('fullPath'), 'a.x', "should return state for value 'a.x'");92 93 state = z.getState('a.y');94 equals(state.get('fullPath'), 'a.y', "should return state for value 'a.y'");95 96 state = z.getState('b.x');97 equals(state.get('fullPath'), 'b.x', "should return state for value 'b.x'");98 99 state = z.getState('b.y');100 equals(state.get('fullPath'), 'b.y', "should return state for value 'b.y'");101 102 state = z.getState('c.x');103 equals(state.get('fullPath'), 'c.x', "should return state for value 'c.x'");104});105test("get state x from sibling states", function() {106 var state,107 foo = root.getSubstate('a.foo'),108 bar = root.getSubstate('b.bar'),109 z = root.getSubstate('c.z');110 111 state = foo.getState('x');112 equals(state.get('fullPath'), 'a.x', "for state foo, should return state a.x for value 'x'");113 114 state = bar.getState('x');115 equals(state.get('fullPath'), 'b.x', "for state bar, should return state b.x for value 'x'");116 117 state = z.getState('x');118 equals(state.get('fullPath'), 'c.x', "for state z, should return state c.x for value 'x'");119});120test("get state x from state a", function() {121 var state,122 a = root.getSubstate('a');123 124 state = a.getState('x');125 equals(state.get('fullPath'), 'a.x', "should return state A.X");126});127test("attempty to get state y from state z", function() {128 var state,129 z = root.getSubstate('c.z');130 131 console.log('expecting to get an error...');132 state = z.getState('y');133 ok(!state, "should not get a state for 'y'");...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = document.querySelector('storybook-root');2const state = storybookRoot.getState();3console.log(state);4const storybookRoot = document.querySelector('storybook-root');5storybookRoot.setState({name: 'John Doe'});6MIT © [storybooks](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getState } = require('storybook-root');2const state = getState();3console.log(state);4const { getState } = require('storybook-root');5const state = getState();6console.log(state);7const { getState } = require('storybook-root');8const state = getState();9console.log(state);10const { getState } = require('storybook-root');11const state = getState();12console.log(state);13const { getState } = require('storybook-root');14const state = getState();15console.log(state);16const { getState } = require('storybook-root');17const state = getState();18console.log(state);19const { getState } = require('storybook-root');20const state = getState();21console.log(state);22const { getState } = require('storybook-root');23const state = getState();24console.log(state);25const { getState } = require('storybook-root');26const state = getState();27console.log(state);28const { getState } = require('storybook-root');29const state = getState();30console.log(state);31const { getState } = require('storybook-root');32const state = getState();33console.log(state);34const { getState } = require('storybook-root');35const state = getState();36console.log(state);37const { getState } = require('storybook-root');38const state = getState();39console.log(state);40const { getState } = require('storybook-root');41const state = getState();42console.log(state);43const { getState } = require('storybook-root');44const state = getState();45console.log(state);46const { getState } = require('storybook-root');47const state = getState();48console.log(state);49const { getState } = require('storybook-root');50const state = getState();51console.log(state);

Full Screen

Using AI Code Generation

copy

Full Screen

1const root = document.querySelector('storybook-root');2const state = root.getState();3console.log(state);4root.setState({count: 1});5storiesOf('test', module)6 .add('test', () => {7 <storybook-root state='{"count": 0}'>8 `;9 });10import { LitElement, html } from 'lit-element';11export class TestElement extends LitElement {12 static get properties() {13 return {14 count: { type: Number },15 };16 }17 constructor() {18 super();19 this.count = 0;20 }21 render() {22 <button @click="${this._handleClick}">${this.count}</button>23 `;24 }25 _handleClick() {26 this.count += 1;27 this.dispatchEvent(28 new CustomEvent('change', {29 })30 );31 }32}33customElements.define('test-element', TestElement);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getState } from 'storybook-root';2const state = getState();3export default state;4import { storiesOf } from '@storybook/react';5export const getState = () => {6 return storiesOf('state', module);7};8import './storybook-root';9const path = require('path');10module.exports = async ({ config }) => {11 config.resolve.alias['storybook-root'] = path.join(__dirname, '../storybook-root.js');12 return config;13};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getState } from 'storybook-addon-redux-store';2const state = getState();3console.log(state);4import { addDecorator, configure } from '@storybook/react';5import { withRedux } from 'storybook-addon-redux-store';6addDecorator(withRedux());7configure(() => require('../test.js'), module);8import { addDecorator, configure } from '@storybook/react';9import { withRedux } from 'storybook-addon-redux-store';10addDecorator(withRedux());11configure(() => require('../test.js'), module);12import 'storybook-addon-redux-store/register';

Full Screen

Using AI Code Generation

copy

Full Screen

1import React, { Component } from 'react';2import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';3import { connect } from 'react-redux';4class Counter extends Component {5 render() {6 return (7 <View style={styles.container}>8 <Text style={styles.text}>Counter: {this.props.counter}</Text>9 <TouchableOpacity style={styles.button} onPress={this.props.onIncrement}>10 <Text style={styles.buttonText}>Increment</Text>11 <TouchableOpacity style={styles.button} onPress={this.props.onDecrement}>12 <Text style={styles.buttonText}>Decrement</Text>13 );14 }15}16const styles = StyleSheet.create({17 container: {18 },19 text: {20 },21 button: {22 },23 buttonText: {24 },25});26const mapStateToProps = state => {27 return {28 };29};30const mapDispatchToProps = dispatch => {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful