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

Commit3a899a7

Browse files
committed
setup alert reducer tests
1 parentd80ccc2 commit3a899a7

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

‎src/modules/alert/actions.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import{ALERT_CLOSE,ALERT_OPEN,ALERT_REPLAY}from'./types';
22

3-
exportfunctionalertOpen(alert:Object):Redux.ThunkAction<any,{},{}>{
4-
return(dispatch):void=>{
5-
dispatch({type:ALERT_OPEN,payload:{ alert}});
6-
};
3+
/**
4+
* opens the alert
5+
*@param {Object} alert
6+
*@returns alert
7+
*/
8+
exportfunctionalertOpen(alert:Object):Action{
9+
return{type:ALERT_OPEN,payload:{ alert}};
710
}
811

12+
/**
13+
* re-opens the alert
14+
*@returns ALERT_REPLAY
15+
*/
916
exportfunctionalertReplay():Action{
1017
return{type:ALERT_REPLAY};
1118
}
12-
19+
/**
20+
* closes the alert
21+
*@returns ALERT_CLOSE
22+
*/
1323
exportfunctionalertClose():Action{
1424
return{type:ALERT_CLOSE};
1525
}

‎src/modules/alert/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import{ALERT_CLOSE,ALERT_OPEN,ALERT_REPLAY}from'./types';
22

3+
// alert styles
34
constcolors={
45
PASS:'#73C990',// green
56
FAIL:'#FF4081',// red
67
NOTE:'#9DA5B4',// blue
78
};
89

9-
const_alert:CR.Alert={
10+
// default alert
11+
exportconst_alert:CR.Alert={
1012
message:'',
1113
open:false,
1214
action:'NOTE',
@@ -30,6 +32,12 @@ function setAlert(a: CR.Alert): CR.Alert {
3032
returnObject.assign({},open,a);
3133
}
3234

35+
/**
36+
* snackbar Alert reducer
37+
*@param {} alert=_alert
38+
*@param {Action} action
39+
*@returns CR
40+
*/
3341
exportdefaultfunctionalert(
3442
alert=_alert,action:Action
3543
):CR.Alert{

‎src/modules/alert/reducer.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
importreducer,{_alert}from'./index';
2+
3+
describe('alert reducer',()=>{
4+
5+
// mock document.getElementsByClassName
6+
// as it used in styling the alert pop-up
7+
8+
constoriginalDocument=global.document;
9+
10+
beforeEach(()=>{
11+
global.document=Object.assign(document,{
12+
getElementsByClassName:(selector)=>[{
13+
style:{
14+
color:'blue'
15+
}
16+
}]
17+
});
18+
});
19+
20+
afterEach(()=>{
21+
global.document=originalDocument;
22+
});
23+
24+
it('should initialize the default alert',()=>{
25+
constaction={type:'unknown'};
26+
expect(reducer(undefined,action)).toEqual(_alert);
27+
});
28+
29+
it('should open the alert on ALERT_OPEN',()=>{
30+
constalert={};
31+
constaction={type:'ALERT_OPEN',payload:{ alert}};
32+
expect(reducer({open:false},action).open).toBe(true);
33+
});
34+
35+
it('should open the alert on ALERT_REPLAY',()=>{
36+
constalert={};
37+
constaction={type:'ALERT_REPLAY',payload:{ alert}};
38+
expect(reducer({open:false},action).open).toBe(true);
39+
});
40+
41+
it('should close the alert on ALERT_CLOSE',()=>{
42+
constaction={type:'ALERT_CLOSE'};
43+
constalert={open:true};
44+
expect(reducer(alert,action).open).toBe(false);
45+
});
46+
47+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp