Skip to content

Commit

Permalink
extract and fix selectCollectionMenuItem
Browse files Browse the repository at this point in the history
  • Loading branch information
lerouxb committed Jul 18, 2024
1 parent cf89163 commit 387219f
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,24 @@ import * as Selectors from '../selectors';
export async function dropCollectionFromSidebar(
browser: CompassBrowser,
connectionName: string,
dbName: string,
databaseName: string,
collectionName: string
): Promise<void> {
const connectionId = await browser.getConnectionIdByName(connectionName);

// search for the collecton in the sidebar filter
await browser.clickVisible(Selectors.SidebarFilterInput);
await browser.setValueVisible(
Selectors.SidebarFilterInput,
`^(${dbName}|${collectionName})$`
await browser.selectCollectionMenuItem(
connectionName,
databaseName,
collectionName,
'drop-collection'
);
const dbElement = await browser.$(
Selectors.sidebarDatabase(connectionId, dbName)
);
await dbElement.waitForDisplayed();
await browser.dropNamespace(collectionName);

// wait for the collection to become displayed
// wait for it to be gone
const connectionId = await browser.getConnectionIdByName(connectionName);
const collectionSelector = Selectors.sidebarCollection(
connectionId,
dbName,
databaseName,
collectionName
);
await browser.scrollToVirtualItem(
Selectors.SidebarNavigationTree,
collectionSelector,
'tree'
);
const collectionElement = await browser.$(collectionSelector);
await collectionElement.waitForDisplayed();

// open the drop collection modal from the sidebar
await browser.hover(collectionSelector);

// NOTE: if the menu was already open for another collection this could get
// confusing. Also this selector is just for the actions button and it is
// assumed that at this point it is the only one. But the drop confirmation
// usually catches that.
await browser.clickVisible(Selectors.SidebarNavigationItemShowActionsButton);
await browser.clickVisible(Selectors.DropCollectionButton);

await browser.dropNamespace(collectionName);

// wait for it to be gone
await collectionElement.waitForExist({ reverse: true });
}
1 change: 1 addition & 0 deletions packages/compass-e2e-tests/helpers/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ export * from './drop-index';
export * from './hide-index';
export * from './unhide-index';
export * from './hide-visible-toasts';
export * from './sidebar-collection';
54 changes: 54 additions & 0 deletions packages/compass-e2e-tests/helpers/commands/sidebar-collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';

export async function selectCollectionMenuItem(
browser: CompassBrowser,
connectionName: string,
databaseName: string,
collectionName: string,
actionName: string
) {
const connectionId = await browser.getConnectionIdByName(connectionName);

// search for the view in the sidebar
await browser.clickVisible(Selectors.SidebarFilterInput);
await browser.setValueVisible(
Selectors.SidebarFilterInput,
`^(${databaseName}|${collectionName})$`
);

const collectionSelector = Selectors.sidebarCollection(
connectionId,
databaseName,
collectionName
);

// scroll to the collection if necessary
await browser.scrollToVirtualItem(
Selectors.SidebarNavigationTree,
collectionSelector,
'tree'
);

const collectionElement = await browser.$(collectionSelector);
await collectionElement.waitForDisplayed();

// hover over the collection
await browser.hover(collectionSelector);

// click the show collections button
// NOTE: This assumes it is currently closed
await browser.clickVisible(
`${collectionSelector} ${Selectors.SidebarNavigationItemShowActionsButton}`
);

const actionSelector = `[role="menuitem"][data-action="${actionName}"]`;

const actionButton = await browser.$(actionSelector);

// click the action
await browser.clickVisible(actionSelector);

// make sure the menu closed
await actionButton.waitForDisplayed({ reverse: true });
}
1 change: 0 additions & 1 deletion packages/compass-e2e-tests/helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ export const RenameCollectionButton =
'[data-testid="sidebar-navigation-item-actions-rename-collection-action"]';
export const DropDatabaseButton = '[data-action="drop-database"]';
export const CreateCollectionButton = '[data-action="create-collection"]';
export const DropCollectionButton = '[data-action="drop-collection"]';
export const DatabaseCollectionPlaceholder = '[data-testid="placeholder"]';

export const sidebarDatabase = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,56 +70,6 @@ async function getDocuments(browser: CompassBrowser) {
});
}

async function chooseCollectionAction(
browser: CompassBrowser,
connectionName: string,
dbName: string,
collectionName: string,
actionName: string
) {
const connectionId = await browser.getConnectionIdByName(connectionName);

// search for the view in the sidebar
await browser.clickVisible(Selectors.SidebarFilterInput);
await browser.setValueVisible(
Selectors.SidebarFilterInput,
`^(${dbName}|${collectionName})$`
);

const collectionSelector = Selectors.sidebarCollection(
connectionId,
dbName,
collectionName
);

// scroll to the collection if necessary
await browser.scrollToVirtualItem(
Selectors.SidebarNavigationTree,
collectionSelector,
'tree'
);

const collectionElement = await browser.$(collectionSelector);
await collectionElement.waitForDisplayed();

// hover over the collection
await browser.hover(collectionSelector);

// click the show collections button
// NOTE: This assumes it is currently closed
await browser.clickVisible(Selectors.SidebarNavigationItemShowActionsButton);

const actionSelector = `[role="menuitem"][data-action="${actionName}"]`;

const actionButton = await browser.$(actionSelector);

// click the action
await browser.clickVisible(actionSelector);

// make sure the menu closed
await actionButton.waitForDisplayed({ reverse: true });
}

async function waitForTab(browser: CompassBrowser, namespace: string) {
await browser.waitUntil(
async function () {
Expand Down Expand Up @@ -481,8 +431,7 @@ describe('Collection aggregations tab', function () {
await waitForTab(browser, 'test.my-view-from-pipeline');

// choose Duplicate view
await chooseCollectionAction(
browser,
await browser.selectCollectionMenuItem(
DEFAULT_CONNECTION_NAME,
'test',
'my-view-from-pipeline',
Expand Down Expand Up @@ -510,8 +459,7 @@ describe('Collection aggregations tab', function () {
await waitForTab(browser, 'test.duplicated-view');

// now select modify view of the non-duplicate
await chooseCollectionAction(
browser,
await browser.selectCollectionMenuItem(
DEFAULT_CONNECTION_NAME,
'test',
'my-view-from-pipeline',
Expand All @@ -524,6 +472,7 @@ describe('Collection aggregations tab', function () {
// make sure we're on the aggregations tab, in edit mode
const modifyBanner = await browser.$(Selectors.ModifySourceBanner);
await modifyBanner.waitForDisplayed();

expect(await modifyBanner.getText()).to.equal(
'MODIFYING PIPELINE BACKING "TEST.MY-VIEW-FROM-PIPELINE"'
);
Expand Down
Loading

0 comments on commit 387219f

Please sign in to comment.