Skip to content

Commit

Permalink
improve e2e tests
Browse files Browse the repository at this point in the history
add comments delimiting fields. for blob fields, use return key
instead of scrolling to content type fields. add flicker2 JDL for test
dont add onSubmitEditing that throws error - can't focus on enums
  • Loading branch information
ruddell committed Nov 25, 2021
1 parent 0f5fbb1 commit 2898857
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 40 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ jobs:
jhipster_version: [7.3.1, 6]
node_version: [14.x]
app_type:
- OauthDtoApp
- JwtWebsocketsApp
- JwtDtoWebsocketsApp
- OauthFlickrApp
- OauthHealthPointsApp
include:
- app_type: JwtWebsocketsApp
- app_type: JwtDtoWebsocketsApp
auth_type: jwt
dto: false
dto: true
websockets: true
- app_type: OauthDtoApp
- app_type: OauthFlickrApp
auth_type: oauth2
dto: true
dto: false
entity_jdl: entities-flickr2.jdl
- app_type: OauthHealthPointsApp
auth_type: oauth2
dto: false
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,27 @@ jobs:
jhipster_version: [7.3.1]
node_version: [14.x]
app_type:
- JwtApp
- JwtDtoApp
- JwtWebsocketsApp
- JwtHealthPoints
- JwtHealthPointsApp
- JwtFlickrApp
- OauthApp
include:
- app_type: JwtApp
auth_type: jwt
dto: false
- app_type: JwtDtoApp
auth_type: jwt
dto: true
- app_type: JwtWebsocketsApp
auth_type: jwt
dto: false
websockets: true
- app_type: JwtHealthPoints
- app_type: JwtHealthPointsApp
auth_type: jwt
dto: false
entity_jdl: entities-21points.jdl
- app_type: JwtFlickrApp
auth_type: jwt
dto: false
entity_jdl: entities-flickr2.jdl
- app_type: OauthApp
auth_type: oauth2
dto: false
Expand Down
46 changes: 36 additions & 10 deletions generators/entity/templates/entity-e2e-test.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,36 @@ describe('<%= context.entityNameCapitalized %> Screen Tests', () => {
it('should allow you to create, update, and delete the <%= context.entityNameCapitalized %> entity', async () => {
await expect(element(by.id('<%= context.entityInstance %>Screen'))).toBeVisible()

// create
/*
* Create <%= context.entityNameCapitalized %>
*/
await tapFirstElementByLabel(' New ')
await waitForElementToBeVisibleById('<%= context.entityInstance %>EditScrollView');
<%_ context.fields.filter(field => !field.id).forEach((field, index) => { _%>
<%_ let formFieldType = context.getEntityFormFieldType(field); _%>
// <%= field.fieldName %>
await scrollTo('<%= field.fieldName %>Input', '<%= context.entityInstance %>EditScrollView')
<%_ if (formFieldType === 'text') { _%>
<%_ if (field.fieldType === 'byte[]') { _%>
<%_ if (field.fieldTypeBlobContent !== 'text') { _%>
await element(by.id('<%= field.fieldName %>Input')).replaceText('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7')
await scrollTo('<%= field.fieldName %>ContentTypeInput', '<%= context.entityInstance %>EditScrollView')
await element(by.id('<%= field.fieldName %>Input')).tapReturnKey()
await element(by.id('<%= field.fieldName %>ContentTypeInput')).replaceText('image/gif')
await element(by.id('<%= field.fieldName %>ContentTypeInput')).tapReturnKey()
<%_ } else { _%>
await element(by.id('<%= field.fieldName %>Input')).replaceText('long-text-blob-content')
await element(by.id('<%= field.fieldName %>Input')).tapReturnKey()
<%_ } _%>
<%_ } else if (field.fieldType !== 'Duration') { _%>
await element(by.id('<%= field.fieldName %>Input')).replaceText('<%= createFakeData[field.fieldName] %>')
await element(by.id('<%= field.fieldName %>Input')).tapReturnKey()
<%_ } else { _%>
await element(by.id('<%= field.fieldName %>Input')).replaceText('PT12S')
await element(by.id('<%= field.fieldName %>Input')).tapReturnKey()
<%_ } _%>
<%_ } else if (formFieldType === 'number') { _%>
await element(by.id('<%= field.fieldName %>Input')).replaceText('<%= createFakeData[field.fieldName] %>')
await element(by.id('<%= field.fieldName %>Input')).tapReturnKey()
<%_ } else if (formFieldType === 'date') { _%>
await setDateTimePickerValue('<%= field.fieldName %>Input', '<%= new Date(createFakeData[field.fieldName]).toCustomLocalDate() %>', 'MM/dd/yy');
<%_ } else if (formFieldType === 'datetime') { _%>
Expand All @@ -101,14 +109,17 @@ describe('<%= context.entityNameCapitalized %> Screen Tests', () => {
await setPickerValue('<%= field.fieldName %>Input', '<%= createFakeData[field.fieldName] %>');
<%_ } _%>
<%_ }) _%>
await element(by.id('<%= context.entityInstance %>EditScrollView')).swipe('down', 'slow');
// save
await scrollTo('submitButton', '<%= context.entityInstance %>EditScrollView')
await waitThenTapButton('submitButton')

// view - validate the creation
/*
* View <%= context.entityNameCapitalized %> - validate the creation
*/
await waitForElementToBeVisibleById('<%= context.entityInstance %>DetailScrollView');
<%_ context.fields.filter(field => !field.id).forEach((field, index) => { _%>
<%_ let formFieldType = context.getEntityFormFieldType(field); _%>
// <%= field.fieldName %>
await scrollTo('<%= field.fieldName %>', '<%= context.entityInstance %>DetailScrollView')
<%_ if (formFieldType === 'text') { _%>
<%_ if (field.fieldType === 'byte[]') { _%>
Expand Down Expand Up @@ -137,29 +148,37 @@ describe('<%= context.entityNameCapitalized %> Screen Tests', () => {
<%_ } _%>
<%_ }) _%>

// update
/*
* Update <%= context.entityNameCapitalized %>
*/
await scrollTo('<%= context.entityInstance %>EditButton', '<%= context.entityInstance %>DetailScrollView')
await tapFirstElementByLabel('<%= context.entityNameCapitalized %> Edit Button');
await waitForElementToBeVisibleById('<%= context.entityInstance %>EditScrollView');
<%_ context.fields.filter(field => !field.id).forEach((field, index) => { _%>
<%_ let formFieldType = context.getEntityFormFieldType(field); _%>
// <%= field.fieldName %>
await scrollTo('<%= field.fieldName %>Input', '<%= context.entityInstance %>EditScrollView')
<%_ if (formFieldType === 'text') { _%>
<%_ if (field.fieldType === 'byte[]') { _%>
<%_ if (field.fieldTypeBlobContent !== 'text') { _%>
await element(by.id('<%= field.fieldName %>Input')).replaceText('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7')
await scrollTo('<%= field.fieldName %>ContentTypeInput', '<%= context.entityInstance %>EditScrollView')
await element(by.id('<%= field.fieldName %>Input')).tapReturnKey()
await element(by.id('<%= field.fieldName %>ContentTypeInput')).replaceText('image/gif')
await element(by.id('<%= field.fieldName %>ContentTypeInput')).tapReturnKey()
<%_ } else { _%>
await element(by.id('<%= field.fieldName %>Input')).replaceText('long-text-blob-content-2')
await element(by.id('<%= field.fieldName %>Input')).tapReturnKey()
<%_ } _%>
<%_ } else if (field.fieldType !== 'Duration') { _%>
await element(by.id('<%= field.fieldName %>Input')).replaceText('<%= createFakeData[field.fieldName] %>')
await element(by.id('<%= field.fieldName %>Input')).tapReturnKey()
<%_ } else { _%>
await element(by.id('<%= field.fieldName %>Input')).replaceText('PT13S')
await element(by.id('<%= field.fieldName %>Input')).tapReturnKey()
<%_ } _%>
<%_ } else if (formFieldType === 'number') { _%>
await element(by.id('<%= field.fieldName %>Input')).replaceText('<%= updateFakeData[field.fieldName] %>')
await element(by.id('<%= field.fieldName %>Input')).tapReturnKey()
<%_ } else if (formFieldType === 'date') { _%>
await setDateTimePickerValue('<%= field.fieldName %>Input', '<%= new Date(updateFakeData[field.fieldName]).toCustomLocalDate() %>', 'MM/dd/yy');
<%_ } else if (formFieldType === 'datetime') { _%>
Expand All @@ -170,14 +189,17 @@ describe('<%= context.entityNameCapitalized %> Screen Tests', () => {
await setPickerValue('<%= field.fieldName %>Input', '<%= updateFakeData[field.fieldName] %>');
<%_ } _%>
<%_ }) _%>
await element(by.id('<%= context.entityInstance %>EditScrollView')).swipe('down', 'slow');
// save
await scrollTo('submitButton', '<%= context.entityInstance %>EditScrollView')
await waitThenTapButton('submitButton')

// view - validate the update
/*
* View <%= context.entityNameCapitalized %> - validate the update
*/
await waitForElementToBeVisibleById('<%= context.entityInstance %>DetailScrollView');
<%_ context.fields.filter(field => !field.id).forEach((field, index) => { _%>
<%_ let formFieldType = context.getEntityFormFieldType(field); _%>
// <%= field.fieldName %>
await scrollTo('<%= field.fieldName %>', '<%= context.entityInstance %>DetailScrollView')
<%_ if (formFieldType === 'text') { _%>
<%_ if (field.fieldType === 'byte[]') { _%>
Expand Down Expand Up @@ -206,14 +228,18 @@ describe('<%= context.entityNameCapitalized %> Screen Tests', () => {
<%_ } _%>
<%_ }) _%>

// delete
/*
* Delete
*/
await scrollTo('<%= context.entityInstance %>DeleteButton', '<%= context.entityInstance %>DetailScrollView')
await waitThenTapButton('<%= context.entityInstance %>DeleteButton');
await waitForElementToBeVisibleById('<%= context.entityInstance %>DeleteModal');
await waitThenTapButton('deleteButton')
await waitForElementToBeVisibleById('<%= context.entityInstance %>Screen');

// logout
/*
* Logout
*/
await goBack()
await waitForElementToBeVisibleById('entityScreenScrollList');
await logout()
Expand Down
6 changes: 3 additions & 3 deletions generators/entity/templates/entity-edit-screen.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ const onSubmit = (data) => update<%= context.entityNameCapitalized %>(formValueT
<Form initialValues={formValue} <%_ if (context.validation) { _%>validationSchema={validationSchema} <%_ } _%>onSubmit={onSubmit} ref={formRef}>
<%_ context.fields.filter(field => !field.id).forEach((field, index) => { _%>
<%_
let nextFieldName = null
let nextField = null;
if (index !== context.fields.filter(field => !field.id).length - 1) {
nextFieldName = context.fields.filter(field => !field.id)[index + 1].fieldName
nextField = context.fields.filter(field => !field.id)[index + 1];
}
const formField = context.getEntityFormField(field, nextFieldName, context.relationships.filter(relation => relation.ownerSide).length);
const formField = context.getEntityFormField(field, nextField, context.relationships.filter(relation => relation.ownerSide).length);
_%>
<%- formField %>
<%_ }) _%>
Expand Down
54 changes: 45 additions & 9 deletions lib/entity-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ const getEntityFormFieldType = field => {
return 'text';
};

const getEntityFormFieldAttributes = (fieldType, fieldName, fieldIsEnum, nextFieldName, numRelationships) => {
const getEntityFormFieldAttributes = (
fieldType,
fieldName,
fieldIsEnum,
nextFieldName,
nextFieldType,
nextFieldIsEnum,
numRelationships
) => {
const fieldNameHumanized = _.startCase(fieldName);
let attributes = `
name='${fieldName}'
Expand Down Expand Up @@ -76,31 +84,59 @@ const getEntityFormFieldAttributes = (fieldType, fieldName, fieldIsEnum, nextFie
`;
}

if (nextFieldName) {
if (nextFieldName && !nextFieldIsEnum) {
attributes += `
onSubmitEditing={() => ${nextFieldName}Ref.current?.focus()}
`;
} else if (numRelationships === 0) {
attributes += `
onSubmitEditing={() => formRef.current?.submitForm()}
`;
// todo: commented out to help with e2e tests scrolling issues
// attributes += `
// onSubmitEditing={() => formRef.current?.submitForm()}
// `;
}
return attributes;
};

const getEntityFormField = (field, nextFieldName, numRelationships) => {
const getEntityFormField = (field, nextField, numRelationships) => {
const fieldType = field.fieldType;
const fieldName = field.fieldName;
const fieldIsEnum = field.fieldIsEnum;
const nextFieldName = nextField ? nextField.fieldName : null;
const nextFieldType = nextField ? nextField.fieldType : null;
const nextFieldIsEnum = nextField ? nextField.fieldIsEnum : null;

if (field.fieldType === 'byte[]' && field.fieldTypeBlobContent !== 'text') {
// need to add a contentType input for blobs
const attributes = getEntityFormFieldAttributes(fieldType, fieldName, fieldIsEnum, `${fieldName}ContentType`, numRelationships);
const attributesContentType = getEntityFormFieldAttributes('String', `${fieldName}ContentType`, false, nextFieldName, numRelationships);
const attributes = getEntityFormFieldAttributes(
fieldType,
fieldName,
fieldIsEnum,
`${fieldName}ContentType`,
'String',
false,
numRelationships
);
const attributesContentType = getEntityFormFieldAttributes(
'String',
`${fieldName}ContentType`,
false,
nextFieldName,
nextFieldType,
false,
numRelationships
);
return `<FormField ${attributes} />
<FormField ${attributesContentType} />`;
}
const attributes = getEntityFormFieldAttributes(fieldType, fieldName, fieldIsEnum, nextFieldName, numRelationships);
const attributes = getEntityFormFieldAttributes(
fieldType,
fieldName,
fieldIsEnum,
nextFieldName,
nextFieldType,
nextFieldIsEnum,
numRelationships
);
return `<FormField ${attributes} />`;
};

Expand Down
35 changes: 35 additions & 0 deletions test/jdl/entities-flickr2.jdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This is the application and entity model for the Flickr app (https://github.com/mraible/mobile-jhipster/) application from Matt Raible
*/

entity Album {
title String required
description TextBlob
created Instant
}

entity Photo {
title String required
description TextBlob
image ImageBlob required
height Integer
width Integer
taken Instant
uploaded Instant
}

entity Tag {
name String required minlength(2)
}

relationship ManyToOne {
Album{user(login)} to User
Photo{album(title)} to Album
}

relationship ManyToMany {
Photo{tag(name)} to Tag{photo}
}

paginate Album with pagination
paginate Photo, Tag with infinite-scroll
12 changes: 6 additions & 6 deletions test/scripts/generate-react-native-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ rm -rf ../${JHI_REACT_NATIVE_APP_NAME} && mkdir ../${JHI_REACT_NATIVE_APP_NAME}

echo "Using JDL for Generation"

# todo: debug fix for why --blueprints flag no longer works
# todo: debug fix for why --blueprints flag no longer works for jhipster v7.4.0+
# generate the app using the same JDL as the backend
#if [ "$JHIPSTER_VERSION" = "6" ]; then
if [ "$JHIPSTER_VERSION" = "6" ]; then
rnhipster jdl ../${JHI_REACT_NATIVE_APP_NAME}.jdl \
--defaults --no-insight --skip-git
#else
# jhipster --blueprints react-native jdl ../${JHI_REACT_NATIVE_APP_NAME}.jdl \
# --defaults --no-insight --skip-git
#fi
else
jhipster --blueprints react-native jdl ../${JHI_REACT_NATIVE_APP_NAME}.jdl \
--defaults --no-insight --skip-git
fi

# list files
ls -al

0 comments on commit 2898857

Please sign in to comment.