Skip to content

Commit d17ec69

Browse files
authored
[Enhancement/Fix] Refactor datasources cypress tests (opensearch-project#1323)
* Fix the datasources cypress tests Signed-off-by: Ryan Liang <[email protected]> * Clean up test setup and setup constants Signed-off-by: Ryan Liang <[email protected]> * Refactor datasources test and disable security config Signed-off-by: Ryan Liang <[email protected]> * Fix some lint Signed-off-by: Ryan Liang <[email protected]> * Switch to capitalized naming Signed-off-by: Ryan Liang <[email protected]> * Fix lint Signed-off-by: Ryan Liang <[email protected]> * debugging Signed-off-by: Ryan Liang <[email protected]> * List out all the changed files Signed-off-by: Ryan Liang <[email protected]> * Add output for file changes Signed-off-by: Ryan Liang <[email protected]> * Switch to use env var Signed-off-by: Ryan Liang <[email protected]> * Add echo Signed-off-by: Ryan Liang <[email protected]> * Remove github env setup Signed-off-by: Ryan Liang <[email protected]> * Add msg to check which file is being linted Signed-off-by: Ryan Liang <[email protected]> * Use jq for parsing Signed-off-by: Ryan Liang <[email protected]> * Lint both modified and added Signed-off-by: Ryan Liang <[email protected]> --------- Signed-off-by: Ryan Liang <[email protected]>
1 parent 9a0fb3d commit d17ec69

File tree

6 files changed

+108
-58
lines changed

6 files changed

+108
-58
lines changed

.cypress/integration/datasources_test/datasources.spec.js

-42
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { FONTEND_BASE_PATH, DATASOURCES_API_PREFIX, DATASOURCES_PATH } from '../../utils/constants';
7+
8+
const MANAGE_DATASOURCES_TAG = 'button[data-test-subj="manage"]';
9+
const NEW_DATASOURCES_TAG = 'button[data-test-subj="new"]';
10+
const CREATE_S3_BUTTON = '[data-test-subj="datasource_card_s3glue"]';
11+
const CREATE_PROMETHEUS_BUTTON = '[data-test-subj="datasource_card_prometheus"]';
12+
13+
const visitDatasourcesHomePage = () => {
14+
cy.visit(FONTEND_BASE_PATH + DATASOURCES_API_PREFIX);
15+
};
16+
17+
const visitDatasourcesCreationPage = () => {
18+
cy.visit(FONTEND_BASE_PATH + DATASOURCES_PATH.DATASOURCES_CREATION_BASE);
19+
};
20+
21+
describe('Integration tests for datasources plugin', () => {
22+
it('Navigates to datasources plugin and expects the correct header', () => {
23+
visitDatasourcesHomePage();
24+
cy.get('[data-test-subj="dataconnections-header"]').should('exist');
25+
});
26+
27+
it('Tests navigation between tabs', () => {
28+
visitDatasourcesHomePage();
29+
30+
cy.get(MANAGE_DATASOURCES_TAG)
31+
.should('have.class', 'euiTab-isSelected')
32+
.and('have.attr', 'aria-selected', 'true');
33+
cy.get(MANAGE_DATASOURCES_TAG).click();
34+
cy.url().should('include', '/manage');
35+
36+
cy.get(NEW_DATASOURCES_TAG).click();
37+
cy.get(NEW_DATASOURCES_TAG)
38+
.should('have.class', 'euiTab-isSelected')
39+
.and('have.attr', 'aria-selected', 'true');
40+
cy.url().should('include', '/new');
41+
42+
cy.get(CREATE_S3_BUTTON).should('be.visible');
43+
cy.get(CREATE_PROMETHEUS_BUTTON).should('be.visible');
44+
});
45+
46+
it('Tests navigation of S3 datasources creation page with hash', () => {
47+
visitDatasourcesCreationPage();
48+
49+
cy.get(CREATE_S3_BUTTON).should('be.visible').click();
50+
cy.url().should('include', DATASOURCES_PATH.DATASOURCES_CONFIG_BASE + '/AmazonS3AWSGlue');
51+
52+
cy.get('h1.euiTitle.euiTitle--medium')
53+
.should('be.visible')
54+
.and('contain', 'Configure Amazon S3 data source');
55+
});
56+
57+
it('Tests navigation of Prometheus datasources creation page with hash', () => {
58+
visitDatasourcesCreationPage();
59+
60+
cy.get(CREATE_PROMETHEUS_BUTTON).should('be.visible').click();
61+
cy.url().should('include', DATASOURCES_PATH.DATASOURCES_CONFIG_BASE + '/Prometheus');
62+
63+
cy.get('h4.euiTitle.euiTitle--medium')
64+
.should('be.visible')
65+
.and('contain', 'Configure Prometheus data source');
66+
});
67+
});

.cypress/utils/constants.js

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
export const delay = 1500;
77
export const COMMAND_TIMEOUT_LONG = 10000;
88

9+
//BASE Constants
10+
export const BACKEND_BASE_PATH = Cypress.env('opensearch');
11+
export const FONTEND_BASE_PATH = Cypress.env('opensearchDashboards');
12+
13+
//Datasources API Constants
14+
export const DATASOURCES_API_PREFIX = '/app/datasources';
15+
export const DATASOURCES_PATH = {
16+
DATASOURCES_CREATION_BASE: `${DATASOURCES_API_PREFIX}#/new`,
17+
DATASOURCES_CONFIG_BASE: `${DATASOURCES_API_PREFIX}#/configure`
18+
};
19+
920
// trace analytics
1021
export const TRACE_ID = '8832ed6abbb2a83516461960c89af49d';
1122
export const SPAN_ID = 'a673bc074b438374';

.github/workflows/integration-tests-workflow.yml

+9
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ jobs:
109109
node-version: ${{ steps.versions_step.outputs.node_version }}
110110
registry-url: 'https://registry.npmjs.org'
111111

112+
- name: Configure OpenSearch Dashboards
113+
run: |
114+
rm -rf ./config/opensearch_dashboards.yml
115+
cat << 'EOT' > ./config/opensearch_dashboards.yml
116+
server.host: "0.0.0.0"
117+
home.disableWelcomeScreen: true
118+
EOT
119+
working-directory: OpenSearch-Dashboards
120+
112121
- name: Install correct yarn version for OpenSearch Dashboards
113122
run: |
114123
npm uninstall -g yarn

.github/workflows/lint.yml

+20-13
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,32 @@ jobs:
4848
working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
4949
run: yarn osd bootstrap
5050

51-
- name: Get list of changed files
52-
id: files
51+
- name: Get list of changed files using GitHub Action
52+
uses: lots0logs/[email protected]
53+
with:
54+
token: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Check Changes of Files
5357
run: |
54-
BASE_SHA="${{ github.event.pull_request.base.sha }}"
55-
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
56-
git fetch origin $BASE_SHA
57-
git diff --name-only $BASE_SHA...$HEAD_SHA > changed_files.txt
58-
CHANGED_FILES=$(cat changed_files.txt | grep -E '\.(js|ts|tsx)$' || true)
59-
echo "::set-output name=changed::${CHANGED_FILES}"
60-
working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
58+
echo "FILES_MODIFIED=$(cat ${HOME}/files_modified.json)"
59+
echo "FILES_ADDED=$(cat ${HOME}/files_added.json)"
60+
echo "FILES_RENAMED=$(cat ${HOME}/files_renamed.json)"
61+
echo "FILES_DELETED=$(cat ${HOME}/files_deleted.json)"
6162
6263
- name: Lint Changed Files
6364
run: |
64-
CHANGED_FILES="${{ steps.files.outputs.changed }}"
65+
jq -r '.[]' ${HOME}/files_modified.json ${HOME}/files_added.json | sort | uniq > /tmp/changed_files.txt
66+
CHANGED_FILES=$(cat /tmp/changed_files.txt)
67+
echo "These are the changed files: $CHANGED_FILES"
6568
if [[ -n "$CHANGED_FILES" ]]; then
6669
echo "Linting changed files..."
67-
IFS=$'\n' read -r -a FILES_TO_LINT <<< "$CHANGED_FILES"
68-
yarn lint "${FILES_TO_LINT[@]}"
70+
while IFS= read -r file; do
71+
if [[ $file == *.js || $file == *.ts || $file == *.tsx ]]; then
72+
echo "linting file $file"
73+
yarn lint "$file"
74+
fi
75+
done < /tmp/changed_files.txt
6976
else
7077
echo "No matched files to lint."
7178
fi
72-
working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
79+
working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}

cypress.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ module.exports = defineConfig({
1818
env: {
1919
opensearch: 'localhost:9200',
2020
opensearchDashboards: 'localhost:5601',
21-
security_enabled: true,
21+
security_enabled: false,
2222
},
2323
'cypress-watch-and-reload': {
2424
watch: ['common/**', 'public/**', 'server/**'],
2525
},
2626
e2e: {
27-
// We've imported your old cypress plugins here.
28-
// You may want to clean this up later by importing these.
2927
setupNodeEvents(on, config) {
3028
return require('./.cypress/plugins/index.js')(on, config);
3129
},

0 commit comments

Comments
 (0)