Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit323433b

Browse files
committed
update parser tests
1 parent5d34a94 commit323433b

File tree

11 files changed

+140
-42
lines changed

11 files changed

+140
-42
lines changed

‎CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to[Semantic Versioning](http://semver.org/).
44

5+
##[0.12.3] - WIP
6+
- improved page open. uses`onDidOpen` callback
7+
- improved documentation, tests
8+
59
##[0.12.2] - 2016-08-25
610
- drop "core-coderoad" dependency
711
- remove additional dependencies for a smaller footprint

‎src/modules/page/actions.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
import{hintPositionSet,routeSet,testLoad}from'../../actions';
22
import{PAGE_SET}from'./types';
33

4+
/**
5+
* calls PAGE_SET with next page
6+
*@param {} any
7+
*@returns thunk
8+
*/
49
exportfunctionpageNext():Redux.ThunkAction<any,any,{}>{
510
return(dispatch,getState):void=>{
611
let{pagePosition}=getState();
712
dispatch(pageSet(pagePosition+1));
813
};
914
}
1015

16+
/**
17+
* PAGE_SET action creator
18+
*
19+
* opens new page, sets hintPosition to 0, resets tasks
20+
* loads tests
21+
*
22+
* if final page, routes to final
23+
*
24+
*@param {} pagePosition=0
25+
*@returns thunk
26+
*/
1127
exportfunctionpageSet(pagePosition=0):Redux.ThunkAction<any,any,{}>{
1228
return(dispatch,getState):void=>{
1329
conststate=getState();

‎src/modules/page/task-actions/handle-action-string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Type = {
1414
// parse task string for command/params
1515
exportdefaultfunctionhandleActionString(
1616
actionString:string
17-
):Promise<void>{
17+
):Promise<any>{
1818
returnnewPromise((resolve,reject)=>{
1919
if(typeofactionString!=='string'){
2020
reject(actionString);

‎src/modules/page/task-actions/handle-actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
importhandleActionStringfrom'./handle-action-string';
22

3+
/**
4+
* call each task action in sequential order
5+
*@param {string[][]} actions
6+
*@returns void
7+
*/
38
exportdefaultfunctionhandleTaskActions(actions:string[][]):void{
49
constnext=actions.shift();
510
if(next&&next.length){

‎src/modules/page/task-actions/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import handleTaskActions from './handle-actions';
33

44
// trigger actions only once, moving fowards
55
lettaskPositionTracker=0;
6-
6+
/**
7+
* task action reducer
8+
*@param {} t=[]
9+
*@param {Action} action
10+
*@returns string[][] array of array of actions
11+
*/
712
exportdefaultfunctiontaskActionsReducer(
813
t=[],action:Action
914
):string[][]{

‎src/modules/page/task-actions/parser.spec.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/// <reference path="../../../typings/globals/jest/index.d.ts" />
2+
3+
importparseParamsfrom'./parse-params';
4+
5+
describe('parseBreaks',function(){
6+
7+
describe('getParams',function(){
8+
it('should return the same string in an array if only one param',function(){
9+
letparams='first';
10+
letparser=newparseParams();
11+
letbreaks=parser.getParams(params);
12+
expect(breaks).toEqual(['first']);
13+
});
14+
15+
it('should return params in a simple string',function(){
16+
letparams='first, second, third';
17+
letparser=newparseParams();
18+
letbreaks=parser.getParams(params);
19+
expect(breaks).toEqual(['first','second','third']);
20+
});
21+
22+
it('should ignore breaks within an object',function(){
23+
letparams='{ a: 1, b: 2 }, second, third';
24+
letparser=newparseParams();
25+
letbreaks=parser.getParams(params);
26+
expect(breaks).toEqual(['{ a: 1, b: 2 }','second','third']);
27+
});
28+
29+
it('should ignore breaks within an array',function(){
30+
letparams='[ a: 1, b: 2 ], second, third';
31+
letparser=newparseParams();
32+
letbreaks=parser.getParams(params);
33+
expect(breaks).toEqual(['[ a: 1, b: 2 ]','second','third']);
34+
});
35+
36+
it('should ignore breaks within brackets',function(){
37+
letparams='function (a, b) {}, second, third';
38+
letparser=newparseParams();
39+
letbreaks=parser.getParams(params);
40+
expect(breaks).toEqual(['function (a, b) {}','second','third']);
41+
});
42+
});
43+
44+
});

‎src/modules/page/task-actions/parser.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
importParseParamsfrom'./parse-params';
22

3+
/**
4+
* gets the command from the front of an action
5+
* example: open('file.js') -> open
6+
*@param {string} actionString
7+
*@returns string action command
8+
*/
39
exportfunctiongetCommand(actionString:string):string{
410
// content before bracket
511
letcommand=actionString.substring(0,actionString.indexOf('('));
@@ -10,6 +16,12 @@ export function getCommand(actionString: string): string {
1016
returncommand;
1117
}
1218

19+
/**
20+
* gets the params from an action
21+
* example: open('file.js') -> file.js
22+
*@param {string} actionString
23+
*@returns string action params
24+
*/
1325
exportfunctiongetParams(actionString:string):string[]{
1426
// content in brackets, split by comma
1527
letparser=newParseParams();
@@ -23,6 +35,11 @@ export function getParams(actionString: string): string[] {
2335
returnparamsList;
2436
}
2537

38+
/**
39+
*
40+
*@param {string} text
41+
*@returns Object
42+
*/
2643
functioncreateObjectFromKeyValString(text:string):Object{
2744
letkeyValList:string[]=text.split(/[:,]/);
2845
letobj={};
@@ -41,6 +58,11 @@ function createObjectFromKeyValString(text: string): Object {
4158
returnobj;
4259
}
4360

61+
/**
62+
* get options from an action string
63+
*@param {string} paramString
64+
*@returns Object
65+
*/
4466
exportfunctiongetOptions(paramString:string):{param:string,options:Object}{
4567
lethasOptions=paramString.match(/\{(.+)?\}/);
4668
letoptions={};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="../../../typings/globals/jest/index.d.ts" />
2+
3+
importreducerfrom'./index';
4+
5+
describe('task-action reducer',()=>{
6+
7+
// it('does nothing if no known action is called', () => {
8+
// const action = { type: 'unknown' };
9+
// expect(reducer([], action)).toEqual([]);
10+
// });
11+
12+
it('demo',()=>{
13+
expect(true).toBe(true);
14+
});
15+
16+
});

‎src/modules/page/task-tests/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ import {readFileSync} from 'fs';
22

33
import{PAGE_SET}from'../types';
44

5+
/**
6+
* task test reducer
7+
*@param {} taskTests=''
8+
*@param {Action} action
9+
*@returns string
10+
*/
511
exportdefaultfunctiontaskTestsReducer(
612
taskTests='',action:Action
713
):string{
814
switch(action.type){
915

1016
casePAGE_SET:
11-
const{tutorial, tasks}=action.payload;
17+
const{tasks}=action.payload;
18+
1219
// map over task tests from coderoad.json
1320
return[].concat.apply([],tasks.map(
1421
task=>task.tests||[]
@@ -20,7 +27,7 @@ export default function taskTestsReducer(
2027
}catch(e){
2128
console.log('Error reading test file',e);
2229
}
23-
// returnconcatted test files
30+
// returnconcatenated test files
2431
returnoutput;
2532
},'');
2633

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path="../../../typings/globals/jest/index.d.ts" />
2+
3+
importreducerfrom'./index';
4+
5+
describe('task tests reducer',()=>{
6+
7+
it('does nothing if no known action',()=>{
8+
constaction={type:'unknown'};
9+
expect(reducer(undefined,action)).toBe('');
10+
});
11+
12+
// it('handles PAGE_SET', () => {
13+
// const tutorial = {};
14+
// const tasks = [];
15+
// });
16+
17+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp