This repository has been archived by the owner on Dec 13, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6361a13
commit a56785e
Showing
7 changed files
with
154 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ test/e2e/generated | |
src/test/generated | ||
lib | ||
node_modules | ||
./coverage | ||
./.nyc_output | ||
coverage | ||
.nyc_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {fromStudioProperty, ObjectChoice} from "../../common/questions"; | ||
import * as projectModel from '../fixtures/mpg-projectModel.json'; | ||
import {StudioTemplatePropertyType} from '../../common/studio/studio-model'; | ||
import { expect } from "chai"; | ||
|
||
describe('interactive CLI question helpers', () => { | ||
it('correctly creates choices for an Entity', () => { | ||
const prop = { | ||
code: 'test', | ||
caption: 'test', | ||
propertyType: StudioTemplatePropertyType.ENTITY, | ||
}; | ||
|
||
// @ts-ignore TODO VP Replace enums with string union types in ProjectModel https://github.com/cuba-platform/front-generator/issues/46 | ||
const question = fromStudioProperty(prop, projectModel); | ||
|
||
expect(question.choices).to.exist; | ||
expect(question.choices).to.be.an('Array'); | ||
|
||
const expectedEntityNames = ["MpgUserInfo", "mpg$SparePart", "mpg$Car", "mpg$FavoriteCar", "mpg$TechnicalCertificate", | ||
"mpg$Garage", "mpg$CarRent"]; | ||
const actualEntityNames = (question.choices! as ObjectChoice[]).map((choice: ObjectChoice) => choice.name); | ||
expect(actualEntityNames).to.deep.equal(expectedEntityNames); | ||
}); | ||
|
||
it('correctly creates choices for a View', () => { | ||
const prop = { | ||
code: 'test', | ||
caption: 'test', | ||
propertyType: StudioTemplatePropertyType.VIEW, | ||
}; | ||
|
||
const previousAnswers = { | ||
entity: { | ||
name: 'mpg$FavoriteCar' | ||
} | ||
}; | ||
|
||
// @ts-ignore TODO VP Replace enums with string union types in ProjectModel https://github.com/cuba-platform/front-generator/issues/46 | ||
const question = fromStudioProperty(prop, projectModel); | ||
|
||
expect(question.choices).to.exist; | ||
expect(question.choices).to.be.a('Function'); | ||
|
||
const expectedViewNames = ["_minimal", "_local", "_base", "favoriteCar-view", "favoriteCar-edit"]; | ||
const actualViewNames = (question.choices as Function)(previousAnswers).map((choice: ObjectChoice) => choice.name); | ||
expect(actualViewNames).to.deep.equal(expectedViewNames); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {mergeI18nMessages} from '../../../../generators/react-typescript/common/i18n'; | ||
import { expect } from 'chai'; | ||
|
||
describe('react generator helpers', () => { | ||
const enExisting = { | ||
'key1': 'predefined value 1', | ||
'key3': 'predefined value 3', | ||
'keyNotInTemplate': 'key not in template' | ||
}; | ||
|
||
const enTemplate = { | ||
'key1': 'template value 1', | ||
'key2': 'template value 2', | ||
'key3': 'template value 3', | ||
'key4': 'template value 4', | ||
'key5': 'template value 5', | ||
}; | ||
|
||
const ruExisting = { | ||
'key1': 'заранее заданное значение 1', | ||
'key3': 'заранее заданное значение 3', | ||
'key4': 'заранее заданное значение 4', | ||
'keyNotInTemplate': 'ключ, отсутствующий в шаблоне' | ||
}; | ||
|
||
const ruTemplate = { | ||
'key1': 'значение из шаблона 1', | ||
'key2': 'значение из шаблона 2', | ||
'key3': 'значение из шаблона 3', | ||
'key4': 'значение из шаблона 4', | ||
'key5': 'значение из шаблона 5', | ||
}; | ||
|
||
const enExpected = { | ||
'key1': 'predefined value 1', | ||
'key2': 'template value 2', | ||
'key3': 'predefined value 3', | ||
'key4': 'template value 4', | ||
'key5': 'template value 5', | ||
'router.testClass': 'testClass', | ||
'keyNotInTemplate': 'key not in template' | ||
}; | ||
|
||
const ruExpected = { | ||
'key1': 'заранее заданное значение 1', | ||
'key2': 'значение из шаблона 2', | ||
'key3': 'заранее заданное значение 3', | ||
'key4': 'заранее заданное значение 4', | ||
'key5': 'значение из шаблона 5', | ||
'keyNotInTemplate': 'ключ, отсутствующий в шаблоне' | ||
}; | ||
|
||
it('should add i18n keys without overwriting', () => { | ||
const {enOut, ruOut} = mergeI18nMessages(enExisting, enTemplate, ruExisting, ruTemplate, 'testClass'); | ||
|
||
expect(enOut).to.deep.equal(enExpected); | ||
expect(ruOut).to.deep.equal(ruExpected); | ||
}); | ||
}); |