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

Commite10e386

Browse files
committed
add alert tests
1 parenta48f5e9 commite10e386

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

‎src/modules/alert/index.ts

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

33
// alert styles
4-
constcolors={
4+
exportconstcolors={
55
PASS:'#73C990',// green
66
FAIL:'#FF4081',// red
77
NOTE:'#9DA5B4',// blue
@@ -23,7 +23,11 @@ const open = {
2323
};
2424

2525
letcurrent:CR.Alert=_alert;
26-
26+
/**
27+
* sets alert color on snackbar DOM element
28+
*@param {CR.Alert} a alert
29+
*@returns CR.Alert alert
30+
*/
2731
functionsetAlert(a:CR.Alert):CR.Alert{
2832
a.color=colors[a.action]||colors.NOTE;
2933
letstatusBarAlert=<HTMLElement>document.getElementsByClassName('cr-alert-replay')[0];
@@ -35,8 +39,8 @@ function setAlert(a: CR.Alert): CR.Alert {
3539
/**
3640
* snackbar Alert reducer
3741
*@param {} alert=_alert
38-
*@param {Action} action
39-
*@returns CR
42+
*@param {Action} action { type: string, payload: { alert }}
43+
*@returns CR.Alert alert
4044
*/
4145
exportdefaultfunctionalert(
4246
alert=_alert,action:Action

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

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/// <reference path="../../typings/globals/jest/index.d.ts" />
22
/// <reference path="../../typings/common/global.d.ts" />
33

4-
importreducer,{_alert}from'./index';
4+
importreducer,{_alert,colors}from'./index';
5+
import{ALERT_OPEN,ALERT_REPLAY,ALERT_CLOSE}from'./types';
56

67
describe('alert reducer',()=>{
78

@@ -31,18 +32,70 @@ describe('alert reducer', () => {
3132

3233
it('should open the alert on ALERT_OPEN',()=>{
3334
constalert={};
34-
constaction={type:'ALERT_OPEN',payload:{ alert}};
35+
constaction={type:ALERT_OPEN,payload:{ alert}};
3536
expect(reducer({open:false},action).open).toBe(true);
3637
});
3738

39+
it('should set the NOTE alert on ALERT_OPEN',()=>{
40+
constalert={
41+
message:'a message',
42+
action:'NOTE',
43+
duration:1500,
44+
};
45+
constaction={type:ALERT_OPEN,payload:{ alert}};
46+
constexpected={
47+
message:'a message',
48+
action:'NOTE',
49+
duration:1500,
50+
open:true,
51+
color:colors.NOTE
52+
};
53+
expect(reducer({open:false},action)).toEqual(expected);
54+
});
55+
56+
it('should set the FAIL alert on ALERT_OPEN',()=>{
57+
constalert={
58+
message:'a message',
59+
action:'FAIL',
60+
duration:1500,
61+
};
62+
constaction={type:ALERT_OPEN,payload:{ alert}};
63+
constexpected={
64+
message:'a message',
65+
action:'FAIL',
66+
duration:1500,
67+
open:true,
68+
color:colors.FAIL
69+
};
70+
expect(reducer({open:false},action)).toEqual(expected);
71+
});
72+
73+
it('should set the PASS alert on ALERT_OPEN',()=>{
74+
constalert={
75+
message:'a message',
76+
action:'PASS',
77+
duration:1500,
78+
};
79+
constaction={type:ALERT_OPEN,payload:{ alert}};
80+
constexpected={
81+
message:'a message',
82+
action:'PASS',
83+
duration:1500,
84+
open:true,
85+
color:colors.PASS
86+
};
87+
expect(reducer({open:false},action)).toEqual(expected);
88+
});
89+
90+
3891
it('should open the alert on ALERT_REPLAY',()=>{
3992
constalert={};
40-
constaction={type:'ALERT_REPLAY',payload:{ alert}};
93+
constaction={type:ALERT_REPLAY,payload:{ alert}};
4194
expect(reducer({open:false},action).open).toBe(true);
4295
});
4396

4497
it('should close the alert on ALERT_CLOSE',()=>{
45-
constaction={type:'ALERT_CLOSE'};
98+
constaction={type:ALERT_CLOSE};
4699
constalert={open:true};
47100
expect(reducer(alert,action).open).toBe(false);
48101
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp