Make "Text Assertion" form field optional for Single Page monitors (#154795) (#153929)

Makes the "Text Assertion" field optional in Monitor Add/Edit form.
This commit is contained in:
Abdul Wahab Zahid 2023-04-17 17:42:22 +02:00 committed by GitHub
parent 41cd8cb96a
commit 1b7830775e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -1090,12 +1090,12 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({
label: i18n.translate('xpack.synthetics.monitorConfig.textAssertion.label', {
defaultMessage: 'Text assertion',
}),
required: true,
required: false,
helpText: i18n.translate('xpack.synthetics.monitorConfig.textAssertion.helpText', {
defaultMessage: 'Consider the page loaded when the specified text is rendered.',
}),
validation: () => ({
required: true,
required: false,
}),
props: (): EuiFieldTextProps => ({
readOnly,

View file

@ -24,14 +24,15 @@ export const ALLOWED_FIELDS = [ConfigKey.ENABLED, ConfigKey.ALERT_CONFIG];
export const format = (fields: Record<string, unknown>, readOnly: boolean = false) => {
const formattedFields = formatter(fields) as MonitorFields;
const textAssertion = formattedFields[ConfigKey.TEXT_ASSERTION]
? `
await page.getByText('${formattedFields[ConfigKey.TEXT_ASSERTION]}').first().waitFor();`
: ``;
const formattedMap = {
[FormMonitorType.SINGLE]: {
...formattedFields,
[ConfigKey.SOURCE_INLINE]: `step('Go to ${formattedFields[ConfigKey.URLS]}', async () => {
await page.goto('${formattedFields[ConfigKey.URLS]}');
expect(await page.isVisible('text=${
formattedFields[ConfigKey.TEXT_ASSERTION]
}')).toBeTruthy();
await page.goto('${formattedFields[ConfigKey.URLS]}');${textAssertion}
});`,
[ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.SINGLE,
},