Skip to content

Commit

Permalink
Refactoring to remove new code duplications
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalKinas committed Oct 27, 2023
1 parent 6dd679d commit e16ff84
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 165 deletions.
218 changes: 59 additions & 159 deletions e2e/protractor/suites/actions/copy-move/copy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,42 +246,72 @@ describe('Copy content', () => {
undoCopyFolderWithExistingName(folderExisting, '', destinationPF));
});

async function copyFile(fileName: string, location: string = '', destination: string, doBefore?: () => void) {
if (doBefore) {
doBefore();
async function baseCopy(
itemName: string | string[],
location: string,
destination: string,
undo: boolean = false,
expectedMsg: string = 'Copied 1 item'
) {
if (itemName instanceof Array) {
await dataTable.selectMultipleItems(itemName, location);
} else {
await dataTable.selectItem(itemName, location);
}
await dataTable.selectItem(fileName, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.selectDestination(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 1 item');
expect(msg).toContain(expectedMsg);
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');
if (undo) {
await page.clickSnackBarAction();
await page.clickPersonalFilesAndWait();
} else {
await copyDialog.waitForDialogToClose();
}
}

await copyDialog.waitForDialogToClose();
async function baseCopyDoBefore(
itemName: string | string[],
location: string,
destination: string,
doBefore?: () => void,
undo?: boolean,
expectedMsg?: string
) {
if (doBefore) {
doBefore();
}
await baseCopy(itemName, location, destination, undo, expectedMsg);
}

async function baseCopyDoBeforeAsync(
itemName: string | string[],
location: string,
destination: string,
doBefore?: () => Promise<void>,
undo?: boolean,
expectedMsg?: string
) {
if (doBefore) {
await doBefore();
}
await baseCopy(itemName, location, destination, undo, expectedMsg);
}

async function copyFile(fileName: string, location: string = '', destination: string, doBefore?: () => void) {
await baseCopyDoBefore(fileName, location, destination, doBefore);
expect(await dataTable.isItemPresent(fileName)).toBe(true, `${fileName} not present in source folder`);
await page.clickPersonalFilesAndWait();
await dataTable.doubleClickOnRowByName(destination);
expect(await dataTable.isItemPresent(fileName)).toBe(true, `${fileName} not present in ${destination} folder`);
}

async function copyFolderWithContent(folderName: string, location: string = '', destination: string, doBefore?: () => void) {
if (doBefore) {
doBefore();
}
await dataTable.selectItem(folderName, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.selectDestination(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 1 item');
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');

await copyDialog.waitForDialogToClose();
await baseCopyDoBefore(folderName, location, destination, doBefore);
expect(await dataTable.isItemPresent(folderName)).toBe(true, `${folderName} not present in source folder`);
await page.clickPersonalFilesAndWait();
await dataTable.doubleClickOnRowByName(destination);
Expand All @@ -293,20 +323,7 @@ describe('Copy content', () => {
}

async function copyMultipleItems(items: string[], location: string = '', destination: string, doBefore?: () => void) {
if (doBefore) {
doBefore();
}
await dataTable.selectMultipleItems(items, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.selectDestination(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 2 items');
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');

await copyDialog.waitForDialogToClose();
await baseCopyDoBefore(items, location, destination, doBefore, false, 'Copied 2 items');
expect(await dataTable.isItemPresent(items[0])).toBe(true, `${items[0]} not present in source folder`);
expect(await dataTable.isItemPresent(items[1])).toBe(true, `${items[1]} not present in source folder`);
await page.clickPersonalFilesAndWait();
Expand All @@ -316,41 +333,15 @@ describe('Copy content', () => {
}

async function copyFileWithNameThatAlreadyExists(fileName: string, location: string = '', destination: string, doBefore?: () => void) {
if (doBefore) {
doBefore();
}
await dataTable.selectItem(fileName, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.selectDestination(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 1 item');
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');

await copyDialog.waitForDialogToClose();
await baseCopyDoBefore(fileName, location, destination, doBefore);
expect(await dataTable.isItemPresent(fileName)).toBe(true, `${fileName}.txt not present in source folder`);
await page.clickPersonalFilesAndWait();
await dataTable.doubleClickOnRowByName(destination);
expect(await dataTable.isItemPresent(fileName)).toBe(true, `${fileName}.txt not present in ${destination} folder`);
}

async function copyFolderWithNameThatAlreadyExists(folderName: string, location: string = '', destination: string, doBefore?: () => void) {
if (doBefore) {
doBefore();
}
await dataTable.selectItem(folderName, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.selectDestination(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 1 item');
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');

await copyDialog.waitForDialogToClose();
await baseCopyDoBefore(folderName, location, destination, doBefore);
expect(await dataTable.isItemPresent(folderName)).toBe(true, `${folderName} not present in source folder`);
await page.clickPersonalFilesAndWait();
await dataTable.doubleClickOnRowByName(destination);
Expand Down Expand Up @@ -392,21 +383,7 @@ describe('Copy content', () => {
}

async function copyLockedFile(fileName: string, location: string = '', destination: string, doBefore?: () => void) {
if (doBefore) {
doBefore();
}

await dataTable.selectItem(fileName, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.selectDestination(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 1 item');
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');

await copyDialog.waitForDialogToClose();
await baseCopyDoBefore(fileName, location, destination, doBefore);
expect(await dataTable.isItemPresent(fileName)).toBe(true, `${fileName} not present in source folder`);
expect(await apis.nodes.isFileLockedByName(fileName, locationId)).toBe(true, `${fileName} not locked in ${location}`);
await page.clickPersonalFilesAndWait();
Expand All @@ -416,21 +393,7 @@ describe('Copy content', () => {
}

async function copyFolderThatContainsLockedFile(folderName: string, location: string = '', destination: string, doBefore?: () => void) {
if (doBefore) {
doBefore();
}

await dataTable.selectItem(folderName, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.selectDestination(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 1 item');
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');

await copyDialog.waitForDialogToClose();
await baseCopyDoBefore(folderName, location, destination, doBefore);
expect(await dataTable.isItemPresent(folderName)).toBe(true, `${folderName} not present in source folder`);
await page.clickPersonalFilesAndWait();
await dataTable.doubleClickOnRowByName(destination);
Expand All @@ -450,22 +413,7 @@ describe('Copy content', () => {
}

async function undoCopyFile(fileName: string, location: string = '', destination: string, doBefore?: () => void) {
if (doBefore) {
doBefore();
}
await dataTable.selectItem(fileName, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.selectDestination(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 1 item');
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');

await page.clickSnackBarAction();

await page.clickPersonalFilesAndWait();
await baseCopyDoBefore(fileName, location, destination, doBefore, true);
await dataTable.doubleClickOnRowByName(destination);
expect(await dataTable.isItemPresent(fileName)).toBe(false, `${fileName} present in ${destination} folder`);

Expand All @@ -474,22 +422,7 @@ describe('Copy content', () => {
}

async function undoCopyFolder(folderName: string, location: string = '', destination: string, doBefore?: () => void) {
if (doBefore) {
doBefore();
}
await dataTable.selectItem(folderName, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.selectDestination(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 1 item');
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');

await page.clickSnackBarAction();

await page.clickPersonalFilesAndWait();
await baseCopyDoBefore(folderName, location, destination, doBefore, true);
await dataTable.doubleClickOnRowByName(destination);
expect(await dataTable.isItemPresent(folderName)).toBe(false, `${folderName} present in ${destination} folder`);

Expand All @@ -498,24 +431,7 @@ describe('Copy content', () => {
}

async function undoCopyFileWithExistingName(fileName: string, location: string = '', destination: string, doBefore?: () => Promise<void>) {
if (doBefore) {
await doBefore();
}

await dataTable.selectItem(fileName, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.dataTable.doubleClickOnRowByName(source);
await copyDialog.selectDestination(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 1 item');
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');

await page.clickSnackBarAction();

await page.clickPersonalFilesAndWait();
await baseCopyDoBeforeAsync(fileName, location, destination, doBefore, true);
await dataTable.doubleClickOnRowByName(source);
await dataTable.doubleClickOnRowByName(folder2);
expect(await dataTable.isItemPresent(fileInFolder2)).toBe(true, `${fileInFolder2} not present in ${destination} folder`);
Expand All @@ -526,23 +442,7 @@ describe('Copy content', () => {
}

async function undoCopyFolderWithExistingName(folderName: string, location: string = '', destination: string, doBefore?: () => void) {
if (doBefore) {
doBefore();
}

await dataTable.selectItem(folderName, location);
await toolbar.clickMoreActionsCopy();
await copyDialog.selectLocation('Personal Files');
await copyDialog.dataTable.doubleClickOnRowByName(destination);
await BrowserActions.click(copyDialog.copyButton);
const msg = await page.getSnackBarMessage();
expect(msg).toContain('Copied 1 item');
const action = await page.getSnackBarAction();
expect(action).toContain('Undo');

await page.clickSnackBarAction();

await page.clickPersonalFilesAndWait();
await baseCopyDoBefore(folderName, location, destination, doBefore, true);
await dataTable.doubleClickOnRowByName(destination);
expect(await dataTable.isItemPresent(folderName)).toBe(true, `${folderName} not present in ${destination} folder`);
await dataTable.doubleClickOnRowByName(folderName);
Expand Down
13 changes: 7 additions & 6 deletions e2e/protractor/suites/list-views/file-libraries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ describe('File Libraries', () => {
const adminApiActions = new AdminActions();

const sortAlphabetically = (a: string, b: string) => a.localeCompare(b);
const sortAndCompare = (actual: string[], expected: string[]) => {
actual.sort(sortAlphabetically);
expected.sort(sortAlphabetically);
expect(actual).toEqual(expected);
};

beforeAll(async () => {
try {
Expand Down Expand Up @@ -148,9 +153,7 @@ describe('File Libraries', () => {
it('[C217098] Site ID is displayed when two sites have the same name', async () => {
const expectedSites = [`${siteName} (${siteId1})`, `${siteName} (${siteId2})`];
const actualSites = await dataTable.getCellsContainingName(siteName);
actualSites.sort(sortAlphabetically);
expectedSites.sort(sortAlphabetically);
expect(actualSites).toEqual(expectedSites);
sortAndCompare(actualSites, expectedSites);
});

it('[C217096] Tooltip for sites without description', async () => {
Expand Down Expand Up @@ -215,9 +218,7 @@ describe('File Libraries', () => {
it('[C289896] Site ID is displayed when two sites have the same name', async () => {
const expectedSites = [`${siteName} (${siteId1})`, `${siteName} (${siteId2})`];
const actualSites = await dataTable.getCellsContainingName(siteName);
actualSites.sort(sortAlphabetically);
expectedSites.sort(sortAlphabetically);
expect(actualSites).toEqual(expectedSites);
sortAndCompare(actualSites, expectedSites);
});

it('[C289894] Tooltip for sites without description', async () => {
Expand Down

0 comments on commit e16ff84

Please sign in to comment.