Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cypress Test] Add and Refactor TESTID-140 sidebar spec and TESTID-46,47,49 sharing spec #9154

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/9154.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
- [Cypress Test] Add and Refactor TESTID-140 sidebar spec and clean up ([#9154](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9154))

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
INDEX_WITH_TIME_1,
INDEX_PATTERN_WITH_TIME_1,
SECONDARY_ENGINE,
} from '../../../../../utils/constants';
import {
getRandomizedWorkspaceName,
getRandomizedDatasourceName,
generateAllTestConfigurations,
setDatePickerDatesAndSearchIfRelevant,
setHistogramIntervalIfRelevant,
} from '../../../../../utils/apps/query_enhancements/shared';
import { QueryLanguages } from '../../../../../utils/apps/query_enhancements/constants';
import { selectFieldFromSidebar } from '../../../../../utils/apps/query_enhancements/sidebar';
import { verifyShareUrl } from '../../../../../utils/apps/query_enhancements/shared_links';
import { setSort } from '../../../../../utils/apps/query_enhancements/table';

const workspaceName = getRandomizedWorkspaceName();
const datasourceName = getRandomizedDatasourceName();

const generateShareUrlsTestConfiguration = (dataset, datasetType, language) => {
const baseConfig = {
dataset,
datasetType,
language: language.name,
apiLanguage: language.apiName,
hasDocLinks: [QueryLanguages.DQL.name, QueryLanguages.Lucene.name].includes(language.name),
testName: `${language.name}-${datasetType}`,
saveName: `${language.name}-${datasetType}`,
};

return {
...baseConfig,
};
};

const getQueryString = (config) => {
if (config.language === QueryLanguages.DQL.name) {
return 'bytes_transferred > 9950';
}
if (config.language === QueryLanguages.Lucene.name) {
return 'bytes_transferred: {9950 TO *}';
}
if (config.language === QueryLanguages.SQL.name) {
return `SELECT * FROM ${config.dataset} WHERE bytes_transferred > 9950`;
}
return `source = ${config.dataset} | where bytes_transferred > 9950`;
};

export const runSharedLinksTests = () => {
describe('discover sharing tests', () => {
const testData = {
fields: ['service_endpoint'],
sort: ['asc'],
interval: 'w',
filter: ['category', 'Network'],
};
beforeEach(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems really inefficient! Why do we need to do this for every test? Our test suite will blow up!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for @AMoo-Miki 's future test plan design to isolate each test cases and run parallelly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this level? I dont think thats a good idea. Can we run it by a few more people? I dont know when that framework to parallelize is going to be built now, and until then we will have to deal with this bottleneck

cy.setupTestData(
SECONDARY_ENGINE.url,
[`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_1}.mapping.json`],
[`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_1}.data.ndjson`]
);
cy.addDataSource({
name: datasourceName,
url: SECONDARY_ENGINE.url,
authType: 'no_auth',
});
cy.deleteWorkspaceByName(workspaceName);
cy.visit('/app/home');
cy.osd.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
});

afterEach(() => {
cy.deleteWorkspaceByName(workspaceName);
cy.deleteDataSourceByName(datasourceName);
cy.deleteIndex(INDEX_WITH_TIME_1);
});

generateAllTestConfigurations(generateShareUrlsTestConfiguration, {
indexPattern: INDEX_PATTERN_WITH_TIME_1,
index: INDEX_WITH_TIME_1,
}).forEach((config) => {
describe(`${config.testName}`, () => {
beforeEach(() => {
if (config.datasetType === 'INDEX_PATTERN') {
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_WITH_TIME_1,
timefieldName: 'timestamp',
dataSource: datasourceName,
isEnhancement: true,
});
}
cy.navigateToWorkSpaceSpecificPage({
workspaceName: workspaceName,
page: 'discover',
isEnhancement: true,
});
});

const queryString = getQueryString(config);

it(`should handle shared document links correctly for ${config.testName}`, () => {
// Setup
cy.setDataset(config.dataset, datasourceName, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);

if (config.hasDocLinks) {
// Test surrounding documents link
cy.get('tbody tr')
.first()
.find('[data-test-subj="docTableExpandToggleColumn"] button')
.click();

cy.getElementByTestId('docTableRowAction-0')
.should('exist')
.and('contain.text', 'View surrounding documents')
.invoke('removeAttr', 'target')
.click();
cy.url().should('include', '/context/');
cy.go('back');

// Test single document link
cy.get('tbody tr')
.first()
.find('[data-test-subj="docTableExpandToggleColumn"] button')
.click();

cy.getElementByTestId('docTableRowAction-1')
.should('exist')
.and('contain.text', 'View single document')
.invoke('removeAttr', 'target')
.click();
cy.url().should('include', '/doc/');
cy.go('back');
} else {
// Verify no document links for SQL/PPL
cy.get('tbody tr')
.first()
.find('[data-test-subj="docTableExpandToggleColumn"] button')
.click();
cy.getElementByTestId('docTableRowAction-0').should('not.exist');
cy.getElementByTestId('docTableRowAction-1').should('not.exist');
}
});

it(`should persist state in shared links for ${config.testName}`, () => {
// Set dataset and language
cy.setDataset(config.dataset, datasourceName, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);

// Set interval
setHistogramIntervalIfRelevant(config.language, testData.interval);

// Set query
cy.setQueryEditor(queryString, { parseSpecialCharSequences: false });

// Set filter for DQL/Lucene
if (config.hasDocLinks) {
cy.submitFilterFromDropDown(testData.filter[0], 'is', testData.filter[1], true);
}

// Add fields from side panel
testData.fields.forEach((field, i) => {
selectFieldFromSidebar(field);
if (config.hasDocLinks) {
setSort(field, testData.sort[i]);
}
});

// Test snapshot url
cy.getElementByTestId('shareTopNavButton').click();
cy.getElementByTestId('copyShareUrlButton')
.invoke('attr', 'data-share-url')
.then((url) => {
verifyShareUrl(url, config, testData, datasourceName, queryString);
});

// Test short url
cy.getElementByTestId('useShortUrl').click();
// Need to wait for short url to generate
cy.wait(2000);
cy.getElementByTestId('copyShareUrlButton')
.invoke('attr', 'data-share-url')
.then((shareUrl) => {
return cy.request({
url: shareUrl,
followRedirect: false,
});
})
.then((response) => {
const redirectUrl = response.headers.location;
verifyShareUrl(redirectUrl, config, testData, datasourceName, queryString);
});

// Test saved object url
// Before save, export as saved object is disabled
cy.getElementByTestId('exportAsSavedObject').find('input').should('be.disabled');
cy.saveSearch(config.saveName);
cy.waitForLoader(true);
cy.getElementByTestId('shareTopNavButton').click();
cy.getElementByTestId('exportAsSavedObject').find('input').should('not.be.disabled');
cy.getElementByTestId('exportAsSavedObject').click();
// Get saved search ID
cy.url().then((url) => {
const viewMatch = url.match(/\/view\/([^?#]+)/);
const savedSearchId = viewMatch ? viewMatch[1] : '';

// Verify ID exists and is properly formatted
expect(savedSearchId).to.not.be.empty;

cy.getElementByTestId('copyShareUrlButton')
.invoke('attr', 'data-share-url')
.then((shareUrl) => {
expect(shareUrl).to.include(`/view/${savedSearchId}`);
});
});
});
});
});
});
};

runSharedLinksTests();
Loading
Loading