1+ import React from 'react' ;
2+ import { render } from 'ink-testing-library' ;
3+ import { ListContexts , ShowCurrentContext , AddContext , SetCurrent } from './Context' ;
4+ import { ContextTestingHelper } from '../../constants' ;
5+
6+ let testing = new ContextTestingHelper ( ) ;
7+
8+ describe ( 'listing contexts' , ( ) => {
9+ test ( "should render error when no context file found" , ( ) => {
10+ testing . deleteDummyContextFile ( ) ;
11+ let { lastFrame } = render ( < ListContexts /> ) ;
12+ expect ( lastFrame ( ) ) . toMatch ( "No contexts saved yet." ) ;
13+ } )
14+
15+ test ( "Should render the context list" , ( ) => {
16+ testing . createDummyContextFile ( )
17+ let { lastFrame } = render ( < ListContexts /> ) ;
18+ expect ( lastFrame ( ) ) . toMatch (
19+ `home : ${ testing . context . store [ "home" ] } \n` +
20+ `code : ${ testing . context . store [ "code" ] } `
21+ ) ;
22+ } )
23+ } )
24+
25+ describe ( 'rendering current context' , ( ) => {
26+ test ( 'showing error if now current context is found' , ( ) => {
27+ testing . deleteDummyContextFile ( ) ;
28+ let { lastFrame } = render ( < ShowCurrentContext /> ) ;
29+ expect ( lastFrame ( ) ) . toMatch ( 'No contexts saved yet.' ) ;
30+ } )
31+
32+ test ( 'showing current context ' , ( ) => {
33+ testing . createDummyContextFile ( ) ;
34+ let { lastFrame } = render ( < ShowCurrentContext /> ) ;
35+ expect ( lastFrame ( ) ) . toMatch ( `home : ${ testing . context . store [ "home" ] } ` ) ;
36+ } )
37+ } )
38+
39+ describe ( 'AddContext ' , ( ) => {
40+ test ( "should return message" , ( ) => {
41+ testing . createDummyContextFile ( ) ;
42+ let { lastFrame } = render ( < AddContext options = { { } } args = { [ 'home' , './test/specification.yml' ] } /> ) ;
43+ expect ( lastFrame ( ) ) . toMatch ( 'New context added' ) ;
44+ } )
45+ } )
46+
47+ describe ( 'SetContext ' , ( ) => {
48+
49+ test ( 'Should render error message is key is not in store' , ( ) => {
50+ testing . createDummyContextFile ( ) ;
51+ let { lastFrame } = render ( < SetCurrent args = { [ 'name' ] } options = { { } } /> )
52+ expect ( lastFrame ( ) ) . toMatch ( 'The context you are trying to use is not present' ) ;
53+ } ) ;
54+
55+ test ( 'Should render the update context' , ( ) => {
56+ testing . createDummyContextFile ( ) ;
57+ let { lastFrame } = render ( < SetCurrent args = { [ 'code' ] } options = { { } } /> )
58+ expect ( lastFrame ( ) ) . toMatch ( `code : ${ testing . context . store [ 'code' ] } ` ) ;
59+ } ) ;
60+ } )
0 commit comments