mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[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:
parent
a8251fa7ef
commit
97b8e995be
30
lib/testing/src/lib/core/pages/data-table/column.ts
Normal file
30
lib/testing/src/lib/core/pages/data-table/column.ts
Normal 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}"]`;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
62
lib/testing/src/lib/core/pages/data-table/data-table-item.ts
Normal file
62
lib/testing/src/lib/core/pages/data-table/data-table-item.ts
Normal 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());
|
||||
}
|
||||
}
|
27
lib/testing/src/lib/core/pages/data-table/date-column.ts
Normal file
27
lib/testing/src/lib/core/pages/data-table/date-column.ts
Normal 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);
|
||||
}
|
||||
}
|
20
lib/testing/src/lib/core/pages/data-table/public-api.ts
Normal file
20
lib/testing/src/lib/core/pages/data-table/public-api.ts
Normal 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';
|
27
lib/testing/src/lib/core/pages/data-table/text-column.ts
Normal file
27
lib/testing/src/lib/core/pages/data-table/text-column.ts
Normal 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);
|
||||
}
|
||||
}
|
@ -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';
|
||||
|
Loading…
x
Reference in New Issue
Block a user