[ACA-2989]Creating data-table-component PO to support all kind of columns, including custom (#5715)

* POC for refactoring data-table-component.page.ts [PO for datatable from adf testing package]. Currently the majority of the methods that we have on this class are working only on 'text' column type. The scope of this PR was to make them work on all types of columns (text, image, date, fileSize, location, json) and also custom columns that may be created on different applications or other pages.

* Set 'text' as default and add rootElement

* Remove comments
This commit is contained in:
Cristina Jalba 2020-05-26 13:56:10 +03:00 committed by GitHub
parent a8251fa7ef
commit 97b8e995be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 210 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export abstract class Column {
columnName: string;
columnType: string;
locator: string;
constructor(columnName: string) {
this.columnName = columnName;
}
createLocator(columnValue: string): string {
return `//div[@data-automation-id="${this.columnType}_${columnValue}"]`;
}
}

View File

@ -0,0 +1,43 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Column } from './column';
import { TextColumn } from './text-column';
import { DateColumn } from './date-column';
import { DataTableItem } from './data-table-item';
import { ElementFinder } from 'protractor';
export class DataTableBuilder {
createDataTable(columns: Array<Column>, rootElement?: ElementFinder): DataTableItem {
const datatable: DataTableItem = new DataTableItem(rootElement);
for (const column of columns) {
switch (column.columnType) {
case 'date': {
datatable.addItem(new DateColumn(column.columnName));
break;
}
case 'custom': {
datatable.addItem(column);
break;
}
default: datatable.addItem(new TextColumn(column.columnName));
}
}
return datatable;
}
}

View File

@ -0,0 +1,62 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Column } from './column';
import { by, element, ElementFinder, Locator } from 'protractor';
import { BrowserActions } from '../../utils/browser-actions';
import { BrowserVisibility } from '../../utils/browser-visibility';
export class DataTableItem {
columns = new Array<Column>();
rootElement: ElementFinder;
rows: Locator = by.css(`div[class*='adf-datatable-body'] adf-datatable-row[class*='adf-datatable-row']`);
constructor(rootElement: ElementFinder = element.all(by.css('adf-datatable')).first()) {
this.rootElement = rootElement;
}
addItem(column: Column): void {
this.columns.push(column);
}
getColumn(columnName: string): Column {
return this.columns.find(
(column) => column.columnName === columnName
);
}
getRow(columnName: string, columnValue: string): ElementFinder {
const column = this.getColumn(columnName);
const locator = `//div[@title="${columnName}"]` + column.createLocator(columnValue) + `//ancestor::adf-datatable-row[contains(@class, 'adf-datatable-row')]`;
return this.rootElement.element(by.xpath(locator));
}
async selectRow(columnName: string, columnValue: string): Promise<void> {
await BrowserActions.closeMenuAndDialogs();
const row = await this.getRow(columnName, columnValue);
await BrowserActions.click(row);
}
async rightClickOnRow(columnName: string, columnValue: string): Promise<void> {
const row = this.getRow(columnName, columnValue);
await BrowserActions.rightClick(row);
}
async waitForFirstRow(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.rootElement.all(this.rows).first());
}
}

View File

@ -0,0 +1,27 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Column } from './column';
export class DateColumn extends Column {
columnType: string = 'date';
columnName: string;
constructor(columnName: string) {
super(columnName);
}
}

View File

@ -0,0 +1,20 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './data-table-builder';
export * from './column';
export * from './data-table-item';

View File

@ -0,0 +1,27 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Column } from './column';
export class TextColumn extends Column {
columnType: string = 'text';
columnName: string;
constructor(columnName: string) {
super(columnName);
}
}

View File

@ -31,3 +31,4 @@ export * from './viewer.page';
export * from './config-editor-page';
export * from './about.page';
export * from './snackbar.page';
export * from './data-table/public-api';