Skip to content

Commit

Permalink
Merge pull request #32 from macohen/2.4
Browse files Browse the repository at this point in the history
Merging integration test and 2.4 config from main
  • Loading branch information
macohen authored Nov 1, 2022
2 parents 5bc7863 + 17f2aa2 commit 3b52d03
Show file tree
Hide file tree
Showing 11 changed files with 1,938 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .cypress/integration/1_query_compare.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

/// <reference types="cypress" />
import {
landOnSearchRelevance,
} from '../utils/event_constants';

describe('Search a query', () => {
it('Should get search bar', () => {
landOnSearchRelevance();
cy.get('input[type="search"]').should('exist')
});
});
26 changes: 26 additions & 0 deletions .cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
71 changes: 71 additions & 0 deletions .cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

const { ADMIN_AUTH } = require('./constants');

Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
// Add the basic auth header when security enabled in the OpenSearch cluster
// https://github.com/cypress-io/cypress/issues/1288
if (Cypress.env('security_enabled')) {
if (options) {
options.auth = ADMIN_AUTH;
} else {
options = { auth: ADMIN_AUTH };
}
// Add query parameters - select the default OpenSearch Dashboards tenant
options.qs = { security_tenant: 'private' };
return originalFn(url, options);
} else {
return originalFn(url, options);
}
});

// Be able to add default options to cy.request(), https://github.com/cypress-io/cypress/issues/726
Cypress.Commands.overwrite('request', (originalFn, ...args) => {
let defaults = {};
// Add the basic authentication header when security enabled in the OpenSearch cluster
if (Cypress.env('security_enabled')) {
defaults.auth = ADMIN_AUTH;
}

let options = {};
if (typeof args[0] === 'object' && args[0] !== null) {
options = Object.assign({}, args[0]);
} else if (args.length === 1) {
[options.url] = args;
} else if (args.length === 2) {
[options.method, options.url] = args;
} else if (args.length === 3) {
[options.method, options.url, options.body] = args;
}

return originalFn(Object.assign({}, defaults, options));
});
9 changes: 9 additions & 0 deletions .cypress/support/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export const ADMIN_AUTH = {
username: 'admin',
password: 'admin',
};
30 changes: 30 additions & 0 deletions .cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')

// Switch the base URL of OpenSearch when security enabled in the cluster
if (Cypress.env('security_enabled')) {
Cypress.env('opensearch', 'https://localhost:9200');
}
8 changes: 8 additions & 0 deletions .cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"allowJs": true,
"baseUrl": "../node_modules",
"types": ["cypress"]
},
"include": ["**/*.*"]
}
8 changes: 8 additions & 0 deletions .cypress/utils/event_constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const delay = 1000;

export const landOnSearchRelevance = () => {
cy.visit(
`${Cypress.env('opensearchDashboards')}/app/searchRelevance#/`
);
cy.wait(delay);
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build/
coverage/
.cypress/screenshots
.cypress/videos
yarn-error.log
22 changes: 22 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"baseUrl": "http://localhost:5601",
"video": true,
"chromeWebSecurity": false,
"fixturesFolder": ".cypress/fixtures",
"integrationFolder": ".cypress/integration",
"pluginsFile": ".cypress/plugins/index.js",
"screenshotsFolder": ".cypress/screenshots",
"supportFile": ".cypress/support/index.js",
"videosFolder": ".cypress/videos",
"viewportWidth": 2000,
"viewportHeight": 1320,
"requestTimeout": 60000,
"responseTimeout": 60000,
"defaultCommandTimeout": 60000,
"experimentalNetworkStubbing": true,
"env": {
"opensearch": "localhost:9200",
"opensearchDashboards": "localhost:5601",
"security_enabled": true
}
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"cypress:open": "TZ=America/Los_Angeles cypress open",
"plugin_helpers": "node ../../scripts/plugin_helpers"
},
"dependencies": {
"yarn": "^1.22.19"
},
"devDependencies": {}
"dependencies": {},
"devDependencies": {
"cypress": "9.5.4",
"eslint": "^6.8.0"
}
}
Loading

0 comments on commit 3b52d03

Please sign in to comment.