From 2a973cebc85878f689ed9b67b43ceb68ca58da03 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Thu, 17 Mar 2022 17:31:03 -0700 Subject: [PATCH] Fixed a bug that was preventing the configured schedule from displaying when editing a monitor that was created through backend commands. Added cypress tests to verify fix. Signed-off-by: AWSHurneyt --- ...e_cron_expression_query_level_monitor.json | 25 ++++++++ ...ple_days_interval_query_level_monitor.json | 25 ++++++++ .../integration/query_level_monitor_spec.js | 61 +++++++++++++++++++ .../Schedule/Frequencies/CustomCron.js | 1 + .../Schedule/Frequencies/Frequency.js | 1 + .../Schedule/Frequencies/Interval.js | 11 +++- .../__snapshots__/Frequencies.test.js.snap | 6 ++ .../containers/CreateMonitor/CreateMonitor.js | 19 ++++++ .../CreateTrigger/utils/formikToTrigger.js | 2 +- 9 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 cypress/fixtures/sample_cron_expression_query_level_monitor.json create mode 100644 cypress/fixtures/sample_days_interval_query_level_monitor.json diff --git a/cypress/fixtures/sample_cron_expression_query_level_monitor.json b/cypress/fixtures/sample_cron_expression_query_level_monitor.json new file mode 100644 index 000000000..ed87475fb --- /dev/null +++ b/cypress/fixtures/sample_cron_expression_query_level_monitor.json @@ -0,0 +1,25 @@ +{ + "name": "sample_cron_expression_query_level_monitor", + "enabled": true, + "schedule": { + "cron": { + "expression": "30 11 * * 1-5", + "timezone": "US/Pacific" + } + }, + "inputs": [ + { + "search": { + "indices": ["*"], + "query": { + "query": { + "match_all": {} + } + } + } + } + ], + "ui_metadata": { + "schedule": {} + } +} diff --git a/cypress/fixtures/sample_days_interval_query_level_monitor.json b/cypress/fixtures/sample_days_interval_query_level_monitor.json new file mode 100644 index 000000000..088cbf052 --- /dev/null +++ b/cypress/fixtures/sample_days_interval_query_level_monitor.json @@ -0,0 +1,25 @@ +{ + "name": "sample_days_interval_query_level_monitor", + "enabled": true, + "schedule": { + "period": { + "interval": "7", + "unit": "DAYS" + } + }, + "inputs": [ + { + "search": { + "indices": ["*"], + "query": { + "query": { + "match_all": {} + } + } + } + } + ], + "ui_metadata": { + "schedule": {} + } +} diff --git a/cypress/integration/query_level_monitor_spec.js b/cypress/integration/query_level_monitor_spec.js index bcd5d2e72..e3cbeba86 100644 --- a/cypress/integration/query_level_monitor_spec.js +++ b/cypress/integration/query_level_monitor_spec.js @@ -7,10 +7,14 @@ import { PLUGIN_NAME } from '../support/constants'; import sampleQueryLevelMonitor from '../fixtures/sample_query_level_monitor'; import sampleQueryLevelMonitorWithAlwaysTrueTrigger from '../fixtures/sample_query_level_monitor_with_always_true_trigger'; import sampleDestination from '../fixtures/sample_destination_custom_webhook.json'; +import sampleDaysIntervalQueryLevelMonitor from '../fixtures/sample_days_interval_query_level_monitor.json'; +import sampleCronExpressionQueryLevelMonitor from '../fixtures/sample_cron_expression_query_level_monitor.json'; const SAMPLE_MONITOR = 'sample_query_level_monitor'; const UPDATED_MONITOR = 'updated_query_level_monitor'; const SAMPLE_MONITOR_WITH_ANOTHER_NAME = 'sample_query_level_monitor_with_always_true_trigger'; +const SAMPLE_DAYS_INTERVAL_MONITOR = 'sample_days_interval_query_level_monitor'; +const SAMPLE_CRON_EXPRESSION_MONITOR = 'sample_cron_expression_query_level_monitor'; const SAMPLE_TRIGGER = 'sample_trigger'; const SAMPLE_ACTION = 'sample_action'; @@ -173,6 +177,63 @@ describe('Query-Level Monitors', () => { }); }); + describe('schedule component displays as intended', () => { + before(() => { + cy.deleteAllMonitors(); + }); + + it('for an interval schedule', () => { + // Create the test monitor + cy.createMonitor(sampleDaysIntervalQueryLevelMonitor); + + // Confirm we can see the created monitors in the list + cy.get(`input[type="search"]`).focus().type(SAMPLE_DAYS_INTERVAL_MONITOR); + cy.contains(SAMPLE_DAYS_INTERVAL_MONITOR, { timeout: 20000 }); + + // Select the existing monitor + cy.get('a').contains(SAMPLE_DAYS_INTERVAL_MONITOR).click({ force: true }); + + // Click Edit button + cy.contains('Edit').click({ force: true }); + + // Wait for input to load and then check the Schedule component + cy.get('[data-test-subj="frequency_field"]', { timeout: 20000 }).contains('By interval'); + + cy.get('[data-test-subj="interval_interval_field"]', { timeout: 20000 }).should( + 'have.value', + 7 + ); + + cy.get('[data-test-subj="interval_unit_field"]', { timeout: 20000 }).contains('Days'); + }); + + it('for a cron expression schedule', () => { + // Create the test monitor + cy.createMonitor(sampleCronExpressionQueryLevelMonitor); + + // Confirm we can see the created monitors in the list + cy.get(`input[type="search"]`).focus().type(SAMPLE_CRON_EXPRESSION_MONITOR); + cy.contains(SAMPLE_CRON_EXPRESSION_MONITOR, { timeout: 20000 }); + + // Select the existing monitor + cy.get('a').contains(SAMPLE_CRON_EXPRESSION_MONITOR).click({ force: true }); + + // Click Edit button + cy.contains('Edit').click({ force: true }); + + // Wait for input to load and then check the Schedule component + cy.get('[data-test-subj="frequency_field"]', { timeout: 20000 }).contains( + 'Custom cron expression' + ); + + cy.get('[data-test-subj="customCron_cronExpression_field"]', { timeout: 20000 }).contains( + '30 11 * * 1-5' + ); + + cy.get('[data-test-subj="timezoneComboBox"]', { timeout: 20000 }).contains('US/Pacific'); + }); + }); + after(() => { // Delete all existing monitors and destinations cy.deleteAllMonitors(); diff --git a/public/pages/CreateMonitor/components/Schedule/Frequencies/CustomCron.js b/public/pages/CreateMonitor/components/Schedule/Frequencies/CustomCron.js index 164ab7e67..bdcd6c66a 100644 --- a/public/pages/CreateMonitor/components/Schedule/Frequencies/CustomCron.js +++ b/public/pages/CreateMonitor/components/Schedule/Frequencies/CustomCron.js @@ -32,6 +32,7 @@ const CustomCron = () => ( error: hasError, style: { marginTop: '0px' }, }} + inputProps={{ 'data-test-subj': 'customCron_cronExpression_field' }} /> diff --git a/public/pages/CreateMonitor/components/Schedule/Frequencies/Frequency.js b/public/pages/CreateMonitor/components/Schedule/Frequencies/Frequency.js index c4d967339..5b02bc71b 100644 --- a/public/pages/CreateMonitor/components/Schedule/Frequencies/Frequency.js +++ b/public/pages/CreateMonitor/components/Schedule/Frequencies/Frequency.js @@ -27,6 +27,7 @@ const Frequency = () => ( inputProps={{ options: frequencies, isInvalid, + 'data-test-subj': 'frequency_field', }} /> ); diff --git a/public/pages/CreateMonitor/components/Schedule/Frequencies/Interval.js b/public/pages/CreateMonitor/components/Schedule/Frequencies/Interval.js index d513aed0d..afb9287a4 100644 --- a/public/pages/CreateMonitor/components/Schedule/Frequencies/Interval.js +++ b/public/pages/CreateMonitor/components/Schedule/Frequencies/Interval.js @@ -32,7 +32,11 @@ const Interval = () => ( isInvalid, error: hasError, }} - inputProps={{ icon: 'clock', min: 1 }} + inputProps={{ + icon: 'clock', + min: 1, + 'data-test-subj': 'interval_interval_field', + }} /> @@ -45,7 +49,10 @@ const Interval = () => ( isInvalid, error: hasError, }} - inputProps={{ options: unitOptions }} + inputProps={{ + options: unitOptions, + 'data-test-subj': 'interval_unit_field', + }} /> diff --git a/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap b/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap index 4e44c245b..bf3e8d059 100644 --- a/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap +++ b/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap @@ -30,6 +30,7 @@ exports[`Frequencies renders CustomCron 1`] = ` >