Skip to content

Commit

Permalink
rework logic for getiing anf compare extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
musienko-maxim committed May 23, 2024
1 parent e5f92f9 commit 4f79e3a
Showing 1 changed file with 89 additions and 76 deletions.
165 changes: 89 additions & 76 deletions tests/e2e/specs/dashboard-samples/RecommendedExtensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import {
ActivityBar,
ContextMenu,
ContextMenuItem,
EditorView,
ExtensionsViewItem,
ExtensionsViewSection,
Expand Down Expand Up @@ -39,6 +37,49 @@ import { Dashboard } from '../../pageobjects/dashboard/Dashboard';

const samples: string[] = PLUGIN_TEST_CONSTANTS.TS_SAMPLE_LIST.split(',');

// get visible items from Extension view, transform this from array to sorted string and compares it with existed recommended extensions
async function getVisibleFilteredItemsAndCompareWithRecommended(recommendations: string[]): Promise<boolean> {
const extensionsView: SideBarView | undefined = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
const [marketplaceSection]: ExtensionsViewSection[] = (await extensionsView?.getContent().getSections()) as ExtensionsViewSection[];
const sections: ViewSection[] | undefined = await extensionsView?.getContent().getSections();

// if we have a big recommender extension list it can be overlapped by other recommendations panel,
// in this case we need to collapse it for instance: it is actual for Quarkus example
if (sections !== undefined) {
for (let i: number = 0; i < sections.length; i++) {
const currentSection: ViewSection = sections[i];
const isOtherRecommendedSectionPresent: boolean = (await currentSection.getTitle()) === 'Other Recommendations';
const isOtherRecommendationExpanded: boolean = await sections[i].isExpanded();
if (isOtherRecommendedSectionPresent && isOtherRecommendationExpanded) {
await currentSection.collapse();
}
}
}
Logger.debug('marketplaceSection.getVisibleItems()');
const allFoundRecommendedItems: ExtensionsViewItem[] = await marketplaceSection.getVisibleItems();
const allFoundRecommendedAuthors: string[] = await Promise.all(
allFoundRecommendedItems.map(async (item: ExtensionsViewItem): Promise<string> => await item.getAuthor())
);

const allFoundAuthorsAsSortedString: string = allFoundRecommendedAuthors.sort().toString();
const allPublisherNamesAsSorString: string = recommendations.sort().toString();
return allFoundAuthorsAsSortedString === allPublisherNamesAsSorString;
}
// get visible items from Extension view, transform this from array to sorted string and compares it with existed installed extensions
async function getVisibleFilteredItemsAndCompareWithInstalled(recommendations: string[]): Promise<boolean> {
const extensionsView: SideBarView | undefined = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
const [marketplaceSection]: ExtensionsViewSection[] = (await extensionsView?.getContent().getSections()) as ExtensionsViewSection[];
Logger.debug('marketplaceSection.getVisibleItems()');
const allFoundRecommendedItems: ExtensionsViewItem[] = await marketplaceSection.getVisibleItems();
const allFoundRecommendedAuthors: string[] = await Promise.all(
allFoundRecommendedItems.map(async (item: ExtensionsViewItem): Promise<string> => await item.getAuthor())
);

const allFoundAuthorsAsSortedString: string = allFoundRecommendedAuthors.sort().toString();
const allPublisherNamesAsSortString: string = recommendations.sort().toString();
// in some cases we can have installed not only recommended extensions with some samples (for example .Net)
return allFoundAuthorsAsSortedString.includes(allPublisherNamesAsSortString);
}
for (const sample of samples) {
suite(`Check if recommended extensions installed for ${sample} ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests);
Expand All @@ -50,15 +91,17 @@ for (const sample of samples) {
const webCheCodeLocators: Locators = cheCodeLocatorLoader.webCheCodeLocators;
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);

let projectSection: ViewSection;
let extensionSection: ExtensionsViewSection;
let extensionsView: SideBarView | undefined;
let publisherNames: string[];

const [pathToExtensionsListFileName, extensionsListFileName]: string[] = ['.vscode', 'extensions.json'];

let recommendedExtensions: any = {
recommendations: []
};

let parsedRecommendations: Array<{ name: string; publisher: string }>;
suiteSetup('Login', async function (): Promise<void> {
await loginTests.loginIntoChe();
Expand Down Expand Up @@ -113,6 +156,8 @@ for (const sample of samples) {
return { publisher, name };
});
Logger.debug(`Recommended extension for this workspace:\n${JSON.stringify(parsedRecommendations)}.`);

publisherNames = parsedRecommendations.map((rec: { name: string; publisher: string }): string => rec.publisher);
expect(parsedRecommendations, 'Recommendations not found').not.empty;
});

Expand Down Expand Up @@ -150,83 +195,51 @@ for (const sample of samples) {
TIMEOUT_CONSTANTS.TS_EDITOR_TAB_INTERACTION_TIMEOUT
);

Logger.debug('extensionSection.findItem by @recommended filter');
try {
await extensionSection.findItem('@recommended');
} catch (err) {
await driverHelper.wait(TIMEOUT_CONSTANTS.TS_EXPAND_PROJECT_TREE_ITEM_TIMEOUT);
await extensionSection.findItem('@recommended');
}
const isReloadRequired: boolean = await driverHelper.isVisible(
(webCheCodeLocators.ExtensionsViewSection as any).requireReloadButton
);
Logger.debug(`Is extensions require reload the editor: ${isReloadRequired}`);

for (const extension of parsedRecommendations) {
Logger.debug(`extensionSection.findItem(${extension.name}).`);
try {
await extensionSection.findItem('@recommended');
} catch (err) {
await driverHelper.wait(TIMEOUT_CONSTANTS.TS_EXPAND_PROJECT_TREE_ITEM_TIMEOUT);
await extensionSection.findItem('@recommended');
}
const isReloadRequired: boolean = await driverHelper.isVisible(
(webCheCodeLocators.ExtensionsViewSection as any).requireReloadButton
if (isReloadRequired) {
Logger.debug('Refreshing the page..');
await browserTabsUtil.refreshPage();
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
await driverHelper.waitVisibility(
webCheCodeLocators.ActivityBar.viewContainer,
TIMEOUT_CONSTANTS.TS_EDITOR_TAB_INTERACTION_TIMEOUT
);
Logger.debug(`Is extensions require reload the editor: ${isReloadRequired}`);

if (isReloadRequired) {
Logger.debug('Refreshing the page..');
await browserTabsUtil.refreshPage();
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
await driverHelper.waitVisibility(
webCheCodeLocators.ActivityBar.viewContainer,
TIMEOUT_CONSTANTS.TS_EDITOR_TAB_INTERACTION_TIMEOUT
);
Logger.debug('ActivityBar().getViewControl("Extensions"))?.openView(): reopen Extensions view.');
extensionsView = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
await driverHelper.waitVisibility(
webCheCodeLocators.ExtensionsViewSection.itemTitle,
TIMEOUT_CONSTANTS.TS_EDITOR_TAB_INTERACTION_TIMEOUT
);
expect(extensionsView, 'Can`t find Extension View section').not.undefined;
[extensionSection] = (await extensionsView?.getContent().getSections()) as ExtensionsViewSection[];
expect(extensionSection, 'Can`t find Extension section').not.undefined;
Logger.debug(`extensionSection.findItem(${extension.name}).`);
await extensionSection.findItem(extension.name);
}

Logger.debug('extensionsView.getContent().getSections(): switch to marketplace section.');
const [marketplaceSection]: ExtensionsViewSection[] = (await extensionsView
?.getContent()
.getSections()) as ExtensionsViewSection[];

Logger.debug('marketplaceSection.getVisibleItems()');
const allFoundItems: ExtensionsViewItem[] = await marketplaceSection.getVisibleItems();
const allFoundAuthors: string[] = await Promise.all(
allFoundItems.map(async (item: ExtensionsViewItem): Promise<string> => await item.getAuthor())
Logger.debug('ActivityBar().getViewControl("Extensions"))?.openView(): reopen Extensions view.');
extensionsView = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
await driverHelper.waitVisibility(
webCheCodeLocators.ExtensionsViewSection.itemTitle,
TIMEOUT_CONSTANTS.TS_EDITOR_TAB_INTERACTION_TIMEOUT
);
expect(allFoundItems, 'Extensions not found').not.empty;
let itemWithRightNameAndPublisher: ExtensionsViewItem | undefined = undefined;
for (const foundItem of allFoundItems) {
Logger.debug(`Try to find extension published by ${extension.publisher}.`);
if (allFoundAuthors.includes(extension.publisher)) {
itemWithRightNameAndPublisher = foundItem;
Logger.debug(`Extension was found: ${await itemWithRightNameAndPublisher?.getTitle()}`);
break;
}
expect(itemWithRightNameAndPublisher, `Extension ${extension.name} not found`).not.undefined;
}

Logger.debug('itemWithRightNameAndPublisher?.isInstalled()');
const isInstalled: boolean = (await itemWithRightNameAndPublisher?.isInstalled()) as boolean;

Logger.debug(`itemWithRightNameAndPublisher?.isInstalled(): ${isInstalled}.`);
expect(isInstalled, `Extension ${extension.name} not installed`).to.be.true;

Logger.debug('itemWithRightNameAndPublisher.manage(): get context menu.');
const extensionManageMenu: ContextMenu = await (itemWithRightNameAndPublisher as ExtensionsViewItem).manage();

Logger.debug('extensionManageMenu.getItems(): get menu items.');
const extensionMenuItems: ContextMenuItem[] = await extensionManageMenu.getItems();
let extensionMenuItemLabels: string = '';
Logger.trace('extensionMenuItems -> item.getLabel(): get menu items names.');
for (const item of extensionMenuItems) {
extensionMenuItemLabels += (await item.getLabel()) + ' ';
}

Logger.debug(`extensionMenuItemLabels: ${extensionMenuItemLabels}.`);
expect(extensionMenuItemLabels, `Extension ${extension.name} not enabled`).contains('Disable').and.not.contains('Enable');
expect(extensionsView, 'Can`t find Extension View section').not.undefined;
[extensionSection] = (await extensionsView?.getContent().getSections()) as ExtensionsViewSection[];
expect(extensionSection, 'Can`t find Extension section').not.undefined;
await extensionSection.findItem('@recommended ');
}

Logger.debug('extensionSection.findItem by @recommended filter');
expect(await getVisibleFilteredItemsAndCompareWithRecommended(publisherNames)).to.be.true;
Logger.debug(`All recommended extensions were found by @recommended filter: ---- ${publisherNames} ----`);

Logger.debug('extensionSection.findItem by @installed filter');
try {
await extensionSection.findItem('@installed ');
} catch (err) {
await driverHelper.wait(TIMEOUT_CONSTANTS.TS_EXPAND_PROJECT_TREE_ITEM_TIMEOUT);
await extensionSection.findItem('@installed ');
}
expect(await getVisibleFilteredItemsAndCompareWithInstalled(publisherNames)).to.be.true;
Logger.debug(`All recommended extensions were found by @installed filter: ---- ${publisherNames} ----`);
});

suiteTeardown('Open dashboard and close all other tabs', async function (): Promise<void> {
Expand Down

0 comments on commit 4f79e3a

Please sign in to comment.