Skip to content

Commit

Permalink
Add functional test for UI Metric
Browse files Browse the repository at this point in the history
Signed-off-by: Suchit Sahoo <[email protected]>
  • Loading branch information
LDrago27 committed Apr 24, 2024
1 parent 6e3cc01 commit f5a464a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cypress-workflow-bundle-snapshot-based.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
test-name: Core Dashboards using Bundle Snapshot
test-command: env CYPRESS_NO_COMMAND_LOG=1 CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_VISBUILDER_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js'
osd-serve-args: --data_source.enabled=true --vis_builder.enabled=true --ml_commons_dashboards.enabled=true
osd-serve-args: --data_source.enabled=true --vis_builder.enabled=true --ml_commons_dashboards.enabled=true --usageCollection.uiMetric.enabled=true

tests-without-security:
needs: changes
Expand All @@ -35,5 +35,5 @@ jobs:
with:
test-name: Core Dashboards using Bundle Snapshot
test-command: env CYPRESS_NO_COMMAND_LOG=1 CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_VISBUILDER_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js'
osd-serve-args: --data_source.enabled=true --vis_builder.enabled=true --ml_commons_dashboards.enabled=true
osd-serve-args: --data_source.enabled=true --vis_builder.enabled=true --ml_commons_dashboards.enabled=true --usageCollection.uiMetric.enabled=true
security-enabled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { CURRENT_TENANT } from '../../../../../utils/commands';

const miscUtils = new MiscUtils(cy);

describe('dev_console_ui_metric', () => {
before(() => {
CURRENT_TENANT.newTenant = 'global';
miscUtils.visitPage('app/dev_tools#/console');

cy.get('[data-test-subj="help-close-button"]', { timeout: 30000 }).then(
($btn) => {
if ($btn.is(':visible')) {
cy.wrap($btn).click({ force: true });
} else {
cy.get('[type="button"]').contains('Console').click({ force: true });
}
}
);

cy.intercept('POST', 'api/ui_metric/report').as('reportreq');

cy.wait(5000); // Intentional wait
});

it('check UI Metric are being recorded', function () {
miscUtils.visitPage('app/home#/');

cy.wait('@reportreq', { timeout: 100000 })
.its('response.statusCode')
.should('equal', 200);

// Now verify the response of api/stat

cy.request(
'GET',
`${
Cypress.config().baseUrl
}/api/stats?extended=true&legacy=true&exclude_usage=false`
).then((res) => {
expect(res.status).to.eq(200);
expect(res.body)
.to.have.property('usage')
.that.has.property('application_usage')
.that.has.property('dev_tools');
expect(res.body)
.to.have.property('usage')
.that.has.property('ui_metric')
.that.has.property('console')
.that.has.property('length')
.that.is.gt(0);
});
});
});

0 comments on commit f5a464a

Please sign in to comment.