Skip to content

Commit

Permalink
[ACS-6269] create file from template tests
Browse files Browse the repository at this point in the history
  • Loading branch information
azakrzewski-hy committed Nov 7, 2023
1 parent e8c14e4 commit 6a92c97
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 434 deletions.
402 changes: 402 additions & 0 deletions e2e/playwright/actions/src/tests/create-file-from-template.spec.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ test.describe('Create folder from template', () => {
test('[C325156] Create a folder with a duplicate name', async ({ personalFiles }) => {
const snackBar = personalFiles.snackBar;

await createFolderFromTemplateDialog.createNewFolderFromTemplate(commonFolderName);
await createFolderFromTemplateDialog.createFromTemplateAction(commonFolderName);
await expect(snackBar.getByMessageLocator(errorStrings.nameAlreadyUsedError)).toBeVisible();
await expect(createFolderFromTemplateDialog.getDialogTitle(createDialogTitle)).toBeVisible();
});
Expand Down Expand Up @@ -334,7 +334,7 @@ test.describe('Create folder from template', () => {
});

test('[C325157] Create a folder from a template - with a new Name', async () => {
await createFolderFromTemplateDialog.createNewFolderFromTemplate(randomFolderName);
await createFolderFromTemplateDialog.createFromTemplateAction(randomFolderName);
await dataTable.goThroughPagesLookingForRowWithName(randomFolderName);
await expect(dataTable.getRowByName(randomFolderName)).toBeVisible();

Expand All @@ -344,13 +344,13 @@ test.describe('Create folder from template', () => {
});

test('[C325154] Create a folder from a template - with a Name, Title and Description', async () => {
await createFolderFromTemplateDialog.createNewFolderFromTemplate(randomFolderName, randomFolderTitle, randomFolderDescription);
await createFolderFromTemplateDialog.createFromTemplateAction(randomFolderName, randomFolderTitle, randomFolderDescription);
await dataTable.goThroughPagesLookingForRowWithName(randomFolderName);
await expect(dataTable.getCellLinkByName(randomFolderName)).toHaveAttribute(titleLabel, randomFolderTitle + `\n` + randomFolderDescription);
});

test('[C325158] Trim spaces from folder Name', async () => {
await createFolderFromTemplateDialog.createNewFolderFromTemplate(' ' + randomFolderName + ' ');
await createFolderFromTemplateDialog.createFromTemplateAction(' ' + randomFolderName + ' ');
await dataTable.goThroughPagesLookingForRowWithName(randomFolderName);
await expect(dataTable.getRowByName(randomFolderName)).toBeVisible();
});
Expand Down Expand Up @@ -388,7 +388,7 @@ test.describe('Create folder from template', () => {
});

test('[C325161] Create a folder from a template from library - with Name, Title and Description', async () => {
await createFolderFromTemplateDialog.createNewFolderFromTemplate(randomFolderName, randomFolderTitle, randomFolderDescription);
await createFolderFromTemplateDialog.createFromTemplateAction(randomFolderName, randomFolderTitle, randomFolderDescription);
await expect
.soft(dataTable.getCellLinkByName(randomFolderName))
.toHaveAttribute(titleLabel, randomFolderTitle + `\n` + randomFolderDescription);
Expand All @@ -408,7 +408,7 @@ test.describe('Create folder from template', () => {
test('[C325163] Create a folder with a duplicate name in a library', async ({ myLibrariesPage }) => {
const snackBar = myLibrariesPage.snackBar;

await createFolderFromTemplateDialog.createNewFolderFromTemplate(commonFolderName);
await createFolderFromTemplateDialog.createFromTemplateAction(commonFolderName);
await expect(snackBar.getByMessageLocator(errorStrings.nameAlreadyUsedError)).toBeVisible();
await expect(createFolderFromTemplateDialog.getDialogTitle(createDialogTitle)).toBeVisible();
});
Expand Down
422 changes: 0 additions & 422 deletions e2e/protractor/suites/actions/create/create-file-from-template.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ <h2 mat-dialog-title [innerHTML]="title"></h2>
</form>
</div>
<div mat-dialog-actions>
<button mat-button mat-dialog-close data-automation-id="cancel-folder-template-button">
<button mat-button mat-dialog-close data-automation-id="create-from-template-dialog-cancel-button">
{{ 'NODE_FROM_TEMPLATE.CANCEL' | translate }}
</button>
<button
class="create"
[disabled]="form.invalid"
mat-button
(click)="onSubmit()"
data-automation-id="create-folder-template-button"
data-automation-id="create-from-template-dialog-create-button"
>
{{ 'NODE_FROM_TEMPLATE.CREATE' | translate }}
</button>
Expand Down
68 changes: 68 additions & 0 deletions projects/aca-playwright-shared/src/api/nodes-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ export class NodesApi {
}
}

async cleanupNodeTemplatesItems(nodeNames: string[]): Promise<void> {
try {
const templatesFolderId = await this.getNodeTemplatesFolderId();
for (const nodeName of nodeNames) {
const nodeId = await this.getNodeIdFromParent(nodeName, templatesFolderId);
await this.deleteNodeById(nodeId);
}
} catch (error) {
logger.error('Admin Actions - cleanupNodeTemplatesItems failed : ', error);
}
}

async cleanupSpaceTemplatesItems(nodeNames: string[]): Promise<void> {
try {
const spaceTemplatesNodeId = await this.getSpaceTemplatesFolderId();
Expand All @@ -205,6 +217,15 @@ export class NodesApi {
}
}

async getNodeTemplatesFolderId(): Promise<string> {
try {
return this.getNodeIdFromParent('Node Templates', await this.getDataDictionaryId());
} catch (error) {
logger.error('Admin Actions - getNodeTemplatesFolderId failed : ', error);
return '';
}
}

async getSpaceTemplatesFolderId(): Promise<string> {
try {
return this.getNodeIdFromParent('Space Templates', await this.getDataDictionaryId());
Expand Down Expand Up @@ -243,6 +264,18 @@ export class NodesApi {
}
}

async removeUserAccessOnNodeTemplate(nodeName: string): Promise<NodeEntry> {
try {
const templatesRootFolderId = await this.getNodeTemplatesFolderId();
const nodeId: string = await this.getNodeIdFromParent(nodeName, templatesRootFolderId);

return this.setInheritPermissions(nodeId, false);
} catch (error) {
logger.error('Admin Actions - removeUserAccessOnNodeTemplate failed : ', error);
return null;
}
}

async removeUserAccessOnSpaceTemplate(nodeName: string): Promise<NodeEntry> {
try {
const templatesRootFolderId = await this.getSpaceTemplatesFolderId();
Expand Down Expand Up @@ -279,6 +312,26 @@ export class NodesApi {
}
}

async createFileLink(originalNodeId: string, destinationId: string): Promise<NodeEntry | null> {
const name = (await this.getNodeById(originalNodeId)).entry.name;
const nodeBody = {
name: `Link to ${name}.url`,
nodeType: 'app:filelink',
properties: {
'cm:destination': originalNodeId
}
};

try {
const link = await this.apiService.nodes.createNode(destinationId, nodeBody);
await this.addAspects(originalNodeId, ['app:linked']);
return link;
} catch (error) {
logger.error(`${this.constructor.name} ${this.createFileLink.name}`, error);
return null;
}
}

async createFolderLink(originalNodeId: string, destinationId: string): Promise<NodeEntry | null> {
const name = (await this.getNodeById(originalNodeId)).entry.name;
const nodeBody = {
Expand All @@ -302,6 +355,21 @@ export class NodesApi {
}
}

async createLinkToFileName(originalFileName: string, originalFileParentId: string, destinationParentId?: string): Promise<NodeEntry> {
if (!destinationParentId) {
destinationParentId = originalFileParentId;
}

try {
const nodeId = await this.getNodeIdFromParent(originalFileName, originalFileParentId);

return this.createFileLink(nodeId, destinationParentId);
} catch (error) {
logger.error('Admin Actions - createLinkToFileName failed : ', error);
return null;
}
}

async createLinkToFolderName(originalFolderName: string, originalFolderParentId: string, destinationParentId?: string): Promise<NodeEntry> {
if (!destinationParentId) {
destinationParentId = originalFolderParentId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ export class AcaHeader extends BaseComponent {
await this.createButton.click();
await this.matMenu.createFolderFromTemplate.click();
}

async clickCreateFileFromTemplate(): Promise<void> {
await this.createButton.click();
await this.matMenu.createFileFromTemplate.click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class MatMenuComponent extends BaseComponent {
public getMenuItemTextLocator = this.getChild('[data-automation-id="menu-item-title"]');
public createFolder = this.getChild('[id="app.create.folder"]');
public createFolderFromTemplate = this.getChild('[id="app.create.folderFromTemplate"]');
public createFileFromTemplate = this.getChild('[id="app.create.fileFromTemplate"]');
public createLibrary = this.getChild('[id="app.create.library"]');
public getButtonByText = (text: string) => this.getChild('button', { hasText: text });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class CreateFromTemplateDialogComponent extends BaseComponent {
super(page, CreateFromTemplateDialogComponent.rootElement);
}

cancelButton = this.getChild('[data-automation-id="cancel-folder-template-button"]');
createButton = this.getChild('[data-automation-id="create-folder-template-button"]');
cancelButton = this.getChild('[data-automation-id="create-from-template-dialog-cancel-button"]');
createButton = this.getChild('[data-automation-id="create-from-template-dialog-create-button"]');
getDialogTitle = (text: string) => this.getChild('.mat-dialog-title', { hasText: text });
getDialogLabel = (text: string) => this.getChild('label', { hasText: text });
getErrorByText = (text: string): Locator => this.page.locator('mat-error', {hasText: text});
Expand All @@ -46,9 +46,9 @@ export class CreateFromTemplateDialogComponent extends BaseComponent {
}

/**
* This method is used when we want to fill in Create new folder from template dialog and choose Create button
* This method is used when we want to fill in Create new folder/document/file from template dialog and choose Create button
*/
async createNewFolderFromTemplate( nameInput: string, titleInput?: string, descriptionInput?: string): Promise<void> {
async createFromTemplateAction( nameInput: string, titleInput?: string, descriptionInput?: string): Promise<void> {
await this.getDialogLabel('Name *').fill(nameInput);
if (titleInput) { await this.getDialogLabel('Title').fill(titleInput); }
if (descriptionInput) { await this.getDialogLabel('Description').fill(descriptionInput); }
Expand Down

0 comments on commit 6a92c97

Please sign in to comment.