11import { shallow } from 'enzyme'
22import * as React from 'react'
33
4- import { ResultOutput } from '../../../reducers/states '
4+ import { mockTypeError } from '../../../mocks/context '
55import Repl , { Output } from '../Repl'
66
7+ const mockRunningOutput = {
8+ type : 'running' ,
9+ consoleLogs : [ 'a' , 'bb' , 'cccccccccccccccccccccccccccccccc' , 'd' ]
10+ }
11+
12+ const mockCodeOutput = {
13+ type : 'code' ,
14+ value : "display('');"
15+ }
16+
17+ const mockResultOutput = {
18+ type : 'result' ,
19+ value : 42 ,
20+ consoleLogs : [ ]
21+ }
22+
23+ const mockErrorOutput = {
24+ type : 'errors' ,
25+ errors : [ mockTypeError ( ) ] ,
26+ consoleLogs : [ ]
27+ }
28+
729test ( 'Repl renders correctly' , ( ) => {
830 const props = {
9- output : [ { type : 'result' , value : 'abc' , consoleLogs : [ ] } as ResultOutput ] ,
31+ output : [ mockResultOutput , mockCodeOutput , mockErrorOutput , mockRunningOutput ] ,
1032 replValue : '' ,
1133 handleReplValueChange : ( newCode : string ) => { } ,
1234 handleReplEval : ( ) => { } ,
@@ -18,9 +40,52 @@ test('Repl renders correctly', () => {
1840 expect ( tree . debug ( ) ) . toMatchSnapshot ( )
1941} )
2042
21- test ( "Output renders correctly for InterpreterOutput.type === 'result'" , ( ) => {
22- const props : ResultOutput = { type : 'result' , value : 'def' , consoleLogs : [ ] }
43+ test ( 'Code output renders correctly' , ( ) => {
44+ const app = < Output { ...{ output : mockCodeOutput } } />
45+ const tree = shallow ( app )
46+ expect ( tree . debug ( ) ) . toMatchSnapshot ( )
47+ } )
48+
49+ test ( 'Running output renders correctly' , ( ) => {
50+ const app = < Output { ...{ output : mockRunningOutput } } />
51+ const tree = shallow ( app )
52+ expect ( tree . debug ( ) ) . toMatchSnapshot ( )
53+ } )
54+
55+ test ( 'Result output (no consoleLogs) renders correctly' , ( ) => {
56+ const app = < Output { ...{ output : mockResultOutput } } />
57+ const tree = shallow ( app )
58+ expect ( tree . debug ( ) ) . toMatchSnapshot ( )
59+ } )
60+
61+ test ( 'Result output (with consoleLogs) renders correctly' , ( ) => {
62+ const props = {
63+ ...mockResultOutput ,
64+ consoleLogs : mockRunningOutput . consoleLogs
65+ }
66+ const app = < Output { ...{ output : props } } />
67+ const tree = shallow ( app )
68+ expect ( tree . debug ( ) ) . toMatchSnapshot ( )
69+ } )
70+
71+ test ( 'Error output (no consoleLogs) renders correctly' , ( ) => {
72+ const app = < Output { ...{ output : mockErrorOutput } } />
73+ const tree = shallow ( app )
74+ expect ( tree . debug ( ) ) . toMatchSnapshot ( )
75+ } )
76+
77+ test ( 'Error output (with consoleLogs) renders correctly' , ( ) => {
78+ const props = {
79+ ...mockErrorOutput ,
80+ consoleLogs : mockRunningOutput . consoleLogs
81+ }
2382 const app = < Output { ...{ output : props } } />
2483 const tree = shallow ( app )
2584 expect ( tree . debug ( ) ) . toMatchSnapshot ( )
2685} )
86+
87+ test ( 'Empty output renders an empty card' , ( ) => {
88+ const app = < Output { ...{ output : { } } } />
89+ const tree = shallow ( app )
90+ expect ( tree . debug ( ) ) . toMatchSnapshot ( )
91+ } )
0 commit comments