[ACS-6269] create file from template tests (#3509)

* [ACS-6269] create file from template tests

* applying shorten expression
This commit is contained in:
Adam Zakrzewski
2023-11-07 17:35:04 +01:00
committed by GitHub
parent e8c14e44e1
commit 779e4e4b05
8 changed files with 487 additions and 437 deletions

View File

@@ -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();
@@ -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());
@@ -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();
@@ -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 = {
@@ -302,10 +355,21 @@ export class NodesApi {
}
}
async createLinkToFolderName(originalFolderName: string, originalFolderParentId: string, destinationParentId?: string): Promise<NodeEntry> {
if (!destinationParentId) {
destinationParentId = originalFolderParentId;
async createLinkToFileName(originalFileName: string, originalFileParentId: string, destinationParentId?: string): Promise<NodeEntry> {
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> {
destinationParentId = destinationParentId ?? originalFolderParentId;
try {
const nodeId = await this.getNodeIdFromParent(originalFolderName, originalFolderParentId);

View File

@@ -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();
}
}

View File

@@ -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 });

View File

@@ -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});
@@ -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); }