@@ -9,7 +9,7 @@ const SectionOperator = require('./../../../src/parser/lufile/sectionOperator');
99const LUSectionTypes = require ( './../../../src/parser/utils/enums/lusectiontypes' ) ;
1010const NEWLINE = require ( 'os' ) . EOL ;
1111
12- describe ( 'Section CRUD test ' , ( ) => {
12+ describe ( 'Section CRUD tests for intent ' , ( ) => {
1313 let luresource = undefined ;
1414
1515 it ( 'init section test' , ( ) => {
@@ -211,4 +211,62 @@ describe('Section CRUD test', () => {
211211 assert . equal ( luresource . Sections [ 4 ] . SimpleIntentSections [ 1 ] . Body , simpleIntentBody2 ) ;
212212 assert . equal ( luresource . Sections [ 4 ] . Body , nestedIntentBody ) ;
213213 } ) ;
214+ } ) ;
215+
216+ describe ( 'Section CRUD tests for entity' , ( ) => {
217+ let luresource = undefined ;
218+
219+ it ( 'init section test' , ( ) => {
220+ let fileContent =
221+ `@ list BreadEntity =
222+ - multiGrainWheat:
223+ - multi
224+ - rye:
225+ - rye
226+
227+ # Greeting
228+ - hi` ;
229+
230+ luresource = luparser . parse ( fileContent ) ;
231+
232+ assert . equal ( luresource . Errors . length , 0 ) ;
233+ assert . equal ( luresource . Sections . length , 2 ) ;
234+ assert . equal ( luresource . Sections [ 0 ] . SectionType , LUSectionTypes . NEWENTITYSECTION ) ;
235+ assert . equal ( luresource . Sections [ 0 ] . Name , 'BreadEntity' ) ;
236+ assert . equal ( luresource . Sections [ 0 ] . Type , 'list' ) ;
237+ assert . equal ( luresource . Sections [ 0 ] . ListBody . length , 4 ) ;
238+ assert . equal ( luresource . Sections [ 0 ] . ListBody [ 0 ] , ' - multiGrainWheat:' ) ;
239+ assert . equal ( luresource . Sections [ 0 ] . ListBody [ 1 ] , ' - multi' ) ;
240+ assert . equal ( luresource . Sections [ 0 ] . ListBody [ 2 ] , ' - rye:' ) ;
241+ assert . equal ( luresource . Sections [ 0 ] . ListBody [ 3 ] , ' - rye' ) ;
242+ assert . equal ( luresource . Sections [ 1 ] . SectionType , LUSectionTypes . SIMPLEINTENTSECTION ) ;
243+ assert . equal ( luresource . Sections [ 1 ] . Name , 'Greeting' ) ;
244+ assert . equal ( luresource . Sections [ 1 ] . UtteranceAndEntitiesMap . length , 1 ) ;
245+ assert . equal ( luresource . Sections [ 1 ] . UtteranceAndEntitiesMap [ 0 ] . utterance , 'hi' ) ;
246+ } ) ;
247+
248+ it ( 'update entity section test' , ( ) => {
249+ let newFileConent =
250+ ` - multiGrainWheat:
251+ - multi grain
252+ - white:
253+ - white` ;
254+
255+ luresource = new SectionOperator ( luresource ) . updateSection ( luresource . Sections [ 0 ] . Id , newFileConent ) ;
256+
257+ assert . equal ( luresource . Errors . length , 0 ) ;
258+ assert . equal ( luresource . Sections . length , 2 ) ;
259+ assert . equal ( luresource . Sections [ 0 ] . SectionType , LUSectionTypes . NEWENTITYSECTION ) ;
260+ assert . equal ( luresource . Sections [ 0 ] . Name , 'BreadEntity' ) ;
261+ assert . equal ( luresource . Sections [ 0 ] . Type , 'list' ) ;
262+ assert . equal ( luresource . Sections [ 0 ] . ListBody . length , 4 ) ;
263+ assert . equal ( luresource . Sections [ 0 ] . ListBody [ 0 ] , ' - multiGrainWheat:' ) ;
264+ assert . equal ( luresource . Sections [ 0 ] . ListBody [ 1 ] , ' - multi grain' ) ;
265+ assert . equal ( luresource . Sections [ 0 ] . ListBody [ 2 ] , ' - white:' ) ;
266+ assert . equal ( luresource . Sections [ 0 ] . ListBody [ 3 ] , ' - white' ) ;
267+ assert . equal ( luresource . Sections [ 1 ] . SectionType , LUSectionTypes . SIMPLEINTENTSECTION ) ;
268+ assert . equal ( luresource . Sections [ 1 ] . Name , 'Greeting' ) ;
269+ assert . equal ( luresource . Sections [ 1 ] . UtteranceAndEntitiesMap . length , 1 ) ;
270+ assert . equal ( luresource . Sections [ 1 ] . UtteranceAndEntitiesMap [ 0 ] . utterance , 'hi' ) ;
271+ } ) ;
214272} ) ;
0 commit comments