Skip to content

Commit

Permalink
fix PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Anan <[email protected]>
  • Loading branch information
ananzh committed Dec 18, 2024
1 parent 42f77d9 commit 6fa6cb6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = defineConfig({
WAIT_FOR_LOADER_BUFFER_MS: 0,
},
e2e: {
baseUrl: 'http://localhost:5601',
baseUrl: 'http://localhost:5602',
specPattern: 'cypress/integration/**/*.spec.{js,jsx,ts,tsx}',
testIsolation: false,
setupNodeEvents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { SECONDARY_ENGINE } from '../../../../../utils/constants';

const miscUtils = new MiscUtils(cy);

describe('Workspace Commands / API Test', () => {
describe('No Index Pattern Check Test', () => {
before(() => {
// Load test data
cy.setupTestData(
SECONDARY_ENGINE.url,
[
'cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.mapping.json',
'cypress/fixtures/query_enhancements/data-logs-2/data_logs_small_time_2.mapping.json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { BASE_ENGINE } from '../utils/constants';

export class TestFixtureHandler {
constructor(inputTestRunner, openSearchUrl = 'localhost:9200') {
constructor(inputTestRunner, openSearchUrl = BASE_ENGINE.url) {
this.testRunner = inputTestRunner;
this.openSearchUrl = openSearchUrl;
}
Expand Down
23 changes: 0 additions & 23 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,3 @@ import '../utils/commands';
import '../utils/apps/commands';
import '../utils/dashboards/workspace-plugin/commands';
import '../utils/dashboards/commands';

import { TestFixtureHandler } from '../lib/test-fixture-handler';

Cypress.Commands.add('setupTestData', (mappingFiles, dataFiles) => {
if (!Array.isArray(mappingFiles) || !Array.isArray(dataFiles)) {
throw new Error('Both mappingFiles and dataFiles must be arrays');
}

if (mappingFiles.length !== dataFiles.length) {
throw new Error('The number of mapping files must match the number of data files');
}

const handler = new TestFixtureHandler(cy, 'http://localhost:9200');

let chain = cy.wrap(null);
mappingFiles.forEach((mappingFile, index) => {
chain = chain
.then(() => handler.importMapping(mappingFile))
.then(() => handler.importData(dataFiles[index]));
});

return chain;
});
22 changes: 22 additions & 0 deletions cypress/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import { BASE_PATH } from './constants';
import { TestFixtureHandler } from '../lib/test_fixture_handler';

// This function does not delete all indices
Cypress.Commands.add('deleteAllIndices', () => {
Expand Down Expand Up @@ -332,3 +333,24 @@ Cypress.Commands.add('openWorkspaceDashboard', (workspaceName) => {
.find('a.euiLink')
.click();
});

Cypress.Commands.add('setupTestData', (endpoint, mappingFiles, dataFiles) => {
if (!Array.isArray(mappingFiles) || !Array.isArray(dataFiles)) {
throw new Error('Both mappingFiles and dataFiles must be arrays');
}

if (mappingFiles.length !== dataFiles.length) {
throw new Error('The number of mapping files must match the number of data files');
}

const handler = new TestFixtureHandler(cy, endpoint);

let chain = cy.wrap(null);
mappingFiles.forEach((mappingFile, index) => {
chain = chain
.then(() => handler.importMapping(mappingFile))
.then(() => handler.importData(dataFiles[index]));
});

return chain;
});

0 comments on commit 6fa6cb6

Please sign in to comment.