@@ -5,21 +5,22 @@ import fs from 'fs';
55import tmp from 'tmp' ;
66import ReactGenerator from './ReactGenerator' ;
77
8-
98test ( 'Generate a React app' , ( ) => {
109 const generator = new ReactGenerator ( { hydraPrefix : 'hydra:' , templateDirectory : `${ __dirname } /../../templates` } ) ;
1110 const tmpobj = tmp . dirSync ( { unsafeCleanup : true } ) ;
1211
13- const fields = [ new Field ( 'bar' , {
14- id : 'http://schema.org/url' ,
15- range : 'http://www.w3.org/2001/XMLSchema#string' ,
16- reference : null ,
17- required : true ,
18- description : 'An URL'
19- } ) ] ;
12+ const fields = [
13+ new Field ( 'bar' , {
14+ id : 'http://schema.org/url' ,
15+ range : 'http://www.w3.org/2001/XMLSchema#string' ,
16+ reference : null ,
17+ required : true ,
18+ description : 'An URL'
19+ } ) ,
20+ ] ;
2021 const resource = new Resource ( 'abc' , 'http://example.com/foos' , {
21- id : 'foo ' ,
22- title : 'Foo ' ,
22+ id : 'abc ' ,
23+ title : 'abc ' ,
2324 readableFields : fields ,
2425 writableFields : fields
2526 } ) ;
@@ -30,26 +31,39 @@ test('Generate a React app', () => {
3031 } ) ;
3132 generator . generate ( api , resource , tmpobj . name ) ;
3233
33- expect ( fs . existsSync ( tmpobj . name + '/utils/fetch.js' ) , true ) ;
34- expect ( fs . existsSync ( tmpobj . name + '/utils/helpers.js' ) , true ) ;
34+ [
35+ '/utils/fetch.js' ,
36+ '/utils/helpers.js' ,
37+ '/config/_entrypoint.js' ,
38+
39+ '/actions/abc/create.js' ,
40+ '/actions/abc/delete.js' ,
41+ '/actions/abc/list.js' ,
42+ '/actions/abc/show.js' ,
43+ '/actions/abc/update.js' ,
3544
36- expect ( fs . existsSync ( tmpobj . name + '/config/_entrypoint.js' ) , true ) ;
45+ '/components/abc/index.js' ,
46+ '/components/abc/Create.js' ,
47+ '/components/abc/Update.js' ,
3748
38- expect ( fs . existsSync ( tmpobj . name + '/actions/abc/create.js' ) , true ) ;
39- expect ( fs . existsSync ( tmpobj . name + '/actions/abc/delete.js' ) , true ) ;
40- expect ( fs . existsSync ( tmpobj . name + '/actions/abc/list.js' ) , true ) ;
41- expect ( fs . existsSync ( tmpobj . name + '/actions/abc/update.js' ) , true ) ;
49+ '/routes/abc.js' ,
4250
43- expect ( fs . existsSync ( tmpobj . name + '/components/abc/Create.js' ) , true ) ;
44- expect ( fs . existsSync ( tmpobj . name + '/components/abc/Form.js' ) , true ) ;
45- expect ( fs . existsSync ( tmpobj . name + '/components/abc/List.js' ) , true ) ;
46- expect ( fs . existsSync ( tmpobj . name + '/components/abc/Update.js' ) , true ) ;
51+ '/reducers/abc/create.js' ,
52+ '/reducers/abc/delete.js' ,
53+ '/reducers/abc/index.js' ,
54+ '/reducers/abc/list.js' ,
55+ '/reducers/abc/show.js' ,
56+ '/reducers/abc/update.js' ,
57+ ] . forEach ( file => expect ( fs . existsSync ( tmpobj . name + file ) ) . toBe ( true ) ) ;
4758
48- expect ( fs . existsSync ( tmpobj . name + '/reducers/abc/create.js' ) , true ) ;
49- expect ( fs . existsSync ( tmpobj . name + '/reducers/abc/delete.js' ) , true ) ;
50- expect ( fs . existsSync ( tmpobj . name + '/reducers/abc/index.js' ) , true ) ;
51- expect ( fs . existsSync ( tmpobj . name + '/reducers/abc/list.js' ) , true ) ;
52- expect ( fs . existsSync ( tmpobj . name + '/reducers/abc/update.js' ) , true ) ;
59+ [
60+ '/components/abc/Form.js' ,
61+ '/components/abc/List.js' ,
62+ '/components/abc/Show.js' ,
63+ ] . forEach ( file => {
64+ expect ( fs . existsSync ( tmpobj . name + file ) ) . toBe ( true ) ;
65+ expect ( fs . readFileSync ( tmpobj . name + file , 'utf8' ) ) . toMatch ( / b a r / ) ;
66+ } ) ;
5367
5468 tmpobj . removeCallback ( ) ;
5569} ) ;
0 commit comments