Skip to content

Commit

Permalink
add validation tests to testFormPresentationAndValidation
Browse files Browse the repository at this point in the history
  • Loading branch information
RFSH committed Sep 5, 2024
1 parent e3a8c73 commit abb6c6e
Show file tree
Hide file tree
Showing 10 changed files with 520 additions and 532 deletions.
12 changes: 4 additions & 8 deletions src/components/input-switch/date-time-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const DateTimeField = (props: DateTimeFieldProps): JSX.Element => {
const datetimeFieldState = getFieldState(props.name);

// if both are missing, the input is empty
if (!dateVal && !timeVal && !props.requiredInput) {
if (!dateVal && !timeVal) {
if (datetimeFieldState.error) clearErrors(props.name);
setValue(props.name, '');
trigger(props.name);
Expand All @@ -89,18 +89,14 @@ const DateTimeField = (props: DateTimeFieldProps): JSX.Element => {
}
}

// if only time is missing, use 00:00:00 for it
// if time is missing, use 00:00:00 for it
let timeValTemp = '';
if (!timeVal && !props.requiredInput) {
if (!timeVal) {
timeValTemp = '00:00:00';
setValue(`${props.name}-time`, timeValTemp);
}
// otherwise validate the time value
else {
if (!timeVal) {
setError(props.name, { type: CUSTOM_ERROR_TYPES.INVALID_DATE_TIME, message: 'Please enter a valid time' });
setValue(props.name, 'invalid-value');
return;
}
const err = VALIDATE_VALUE_BY_TYPE['time'](timeVal);
if (typeof err === 'string') {
setError(props.name, { type: CUSTOM_ERROR_TYPES.INVALID_DATE_TIME, message: err });
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/data_setup/schema/recordedit/product-add.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"default": null,
"nullok": true,
"type": {
"typename": "int4"
"typename": "int2"
},
"annotations": {
"comment" : ["top"],
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/locators/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export default class ModalLocators {
return page.locator('.confirm-iframe-close-modal');
}

static getMarkdownPreviewModal(page: Page): Locator {
return page.locator('.chaise-preview-markdown');
}

// ------------- common modal functions -------------- //

static getModalTitle(modal: Locator) {
Expand Down Expand Up @@ -158,4 +162,9 @@ export default class ModalLocators {
static getIframeFieldModalSpinner(modal: Locator): Locator {
return modal.locator('.iframe-field-modal-spinner')
}

// --------- markdown-preview modal functions ------------ //
static getMarkdownPreviewContent(modal: Locator): Locator {
return ModalLocators.getModalText(modal).locator('.markdown-container');
}
}
4 changes: 4 additions & 0 deletions test/e2e/locators/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ export default class PageLocators {
static getFooterLink(page: Page): Locator {
return PageLocators.getFooterContainer(page).locator('a');
}

static getHelpPageMainTable(page: Page): Locator {
return page.locator('#mainTable')
}
}
47 changes: 31 additions & 16 deletions test/e2e/locators/recordedit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@ export enum RecordeditInputType {
TEXT = 'text'
}

export enum RecordeditArrayBaseType {
TIMESTAMP = 'timestamp',
DATE = 'date',
INT_2 = 'integer2',
INT_4 = 'integer4',
INT_8 = 'integer8',
NUMBER = 'number',
BOOLEAN = 'boolean',
MARKDOWN = 'markdown',
LONGTEXT = 'longtext',
TEXT = 'text'
}

export default class RecordeditLocators {

static async waitForRecordeditPageReady(container: Locator | Page, timeout?: number) {
Expand Down Expand Up @@ -194,6 +181,12 @@ export default class RecordeditLocators {
return container.locator(`.input-switch-container-${inputName}`).locator('.chaise-input-control');
}

static getInputRemoveButton(container: Locator | Page, name: string, formNumber: number): Locator {
formNumber = formNumber || 1;
const inputName = `c_${formNumber}-${name}`;
return container.locator(`.input-switch-container-${inputName}`).locator('.remove-input-btn');
}

static getErrorMessageForAColumn(container: Locator | Page, name: string, formNumber: number): Locator {
formNumber = formNumber || 1;
const inputName = `c_${formNumber}-${name}`;
Expand Down Expand Up @@ -383,6 +376,7 @@ export default class RecordeditLocators {
}

// ------------- array selectors ----------------- //

static getArrayFieldContainer(container: Locator | Page, name: string, formNumber: number) {
formNumber = formNumber || 1;
const inputName = `c_${formNumber}-${name}`;
Expand All @@ -392,17 +386,38 @@ export default class RecordeditLocators {
/**
* TODO this only supports array of texts for now and should be changed later for other types.
*/
static getArrayFieldElements(container: Locator | Page, name: string, formNumber: number, baseType: string) {
static getArrayFieldElements(container: Locator | Page, name: string, formNumber: number) {
formNumber = formNumber || 1;
const inputName = `c_${formNumber}-${name}`;
const elem = container.locator(`.array-input-field-container-${inputName}`);
return {
container: elem,
addItemContainer: elem.locator('.add-element-container'),
addItemInput: elem.locator('.add-element-container input'),
addItemButton: elem.locator('.add-button'),
removeItemButtons: elem.locator('.array-remove-button'),
inputs: elem.locator('li input')
};
}

static getArrayInputName(name: string, index: number) {
const append = index === -1 ? 'new-item' : `${index}-val`;
return `${name}-${append}`;
}


// ------------- markdown selectors ----------------- //
static getMarkdownElements(container: Locator | Page, name: string, formNumber: number) {
formNumber = formNumber || 1;
const inputName = `c_${formNumber}-${name}`;
const elem = container.locator(`.input-switch-container-${inputName}`);

return {
container: elem,
getButton: (title: string) => elem.locator(`button[title="${title}"]`),
helpButton: elem.locator('button[title="Help"]'),
previewButton: elem.locator('button[title="Preview"]'),
fullScreenButton: elem.locator('button[title="Fullscreen Preview"]'),
previewContent: elem.locator('.md-preview .markdown-container')
}

}
}
15 changes: 0 additions & 15 deletions test/e2e/specs/all-features-confirmation/recordedit/add.conf.js

This file was deleted.

Loading

0 comments on commit abb6c6e

Please sign in to comment.