[ADF-3823] Add tests for create site dialog (#4090)

* [ADF-3823] Create Library component tests

* [ADF-3823] Create Library component tests

* [ADF-3823] Fixing lint errors.

* [ADF-3823] Added automation id for Create Library btn

* [ADF-3823] Updated tests and added check for white spaces only.

* [ADF-3823] Updated tests & rebased
This commit is contained in:
Florin Butu
2019-01-15 19:34:00 +02:00
committed by Eugenio Romano
parent c7c4dcb659
commit 5b2887fea1
8 changed files with 538 additions and 3 deletions

View File

@@ -88,6 +88,7 @@
<button
mat-icon-button
matTooltip="{{ 'DOCUMENT_LIST.TOOLBAR.CREATE_LIBRARY' | translate }}"
data-automation-id="create-new-library"
(click)="createLibrary()">
<mat-icon>library_add</mat-icon>
</button>

View File

@@ -0,0 +1,264 @@
/*!
* @license
* Copyright 2016 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 { LoginPage } from '../../pages/adf/loginPage';
import { ContentServicesPage } from '../../pages/adf/contentServicesPage';
import { CreateLibraryDialog } from '../../pages/adf/dialog/createLibraryDialog';
import { CustomSources } from '../../pages/adf/demo-shell/customSourcesPage';
import { AcsUserModel } from '../../models/ACS/acsUserModel';
import TestConfig = require('../../test.config');
import AlfrescoApi = require('alfresco-js-api-node');
import { browser, Key } from 'protractor';
import { Util } from '../../util/util';
describe('Create library directive', function () {
let loginPage = new LoginPage();
let contentServicesPage = new ContentServicesPage();
let createLibraryDialog = new CreateLibraryDialog();
let customSourcesPage = new CustomSources();
let visibility = {
public: 'Public',
private: 'Private',
moderated: 'Moderated'
};
let createSite;
let acsUser = new AcsUserModel();
beforeAll(async (done) => {
this.alfrescoJsApi = new AlfrescoApi({
provider: 'ECM',
hostEcm: TestConfig.adf.url
});
await this.alfrescoJsApi.login(TestConfig.adf.adminEmail, TestConfig.adf.adminPassword);
await this.alfrescoJsApi.core.peopleApi.addPerson(acsUser);
loginPage.loginToContentServicesUsingUserModel(acsUser);
createSite = await this.alfrescoJsApi.core.sitesApi.createSite({
'title': Util.generateRandomString(20).toLowerCase(),
'visibility': 'PUBLIC'
});
done();
});
beforeEach( (done) => {
contentServicesPage.goToDocumentList();
contentServicesPage.openCreateLibraryDialog();
done();
});
afterEach(async (done) => {
await browser.actions().sendKeys(Key.ESCAPE).perform();
done();
});
it('[C290158] Should display the Create Library defaults', () => {
expect(createLibraryDialog.getTitle()).toMatch('Create Library');
expect(createLibraryDialog.isNameDisplayed()).toBe(true, 'Name input field is not displayed');
expect(createLibraryDialog.isLibraryIdDisplayed()).toBe(true, 'Library ID field is not displayed');
expect(createLibraryDialog.isDescriptionDisplayed()).toBe(true, 'Library description is not displayed');
expect(createLibraryDialog.isPublicDisplayed()).toBe(true, 'Public radio button is not displayed');
expect(createLibraryDialog.isPrivateDisplayed()).toBe(true, 'Private radio button is not displayed');
expect(createLibraryDialog.isModeratedDisplayed()).toBe(true, 'Moderated radio button is not displayed');
expect(createLibraryDialog.isCreateEnabled()).toBe(false, 'Create button is not disabled');
expect(createLibraryDialog.isCancelEnabled()).toBe(true, 'Cancel button is disabled');
expect(createLibraryDialog.getSelectedRadio()).toMatch(visibility.public, 'The default visibility is not public');
});
it('[C290159] Should close the dialog when clicking Cancel button', () => {
let libraryName = 'cancelLibrary';
createLibraryDialog.typeLibraryName(libraryName);
createLibraryDialog.clickCancel();
createLibraryDialog.waitForDialogToClose();
});
it('[C290160] Should create a public library', () => {
let libraryName = Util.generateRandomString();
let libraryDescription = Util.generateRandomString();
createLibraryDialog.typeLibraryName(libraryName);
createLibraryDialog.typeLibraryDescription(libraryDescription);
createLibraryDialog.selectPublic();
expect(createLibraryDialog.getSelectedRadio()).toMatch(visibility.public, 'The visibility is not public');
createLibraryDialog.clickCreate();
createLibraryDialog.waitForDialogToClose();
expect(createLibraryDialog.isDialogOpen()).not.toBe(true, 'The Create Library dialog is not closed');
customSourcesPage.navigateToCustomSources();
customSourcesPage.selectMySitesSourceType();
customSourcesPage.checkRowIsDisplayed(libraryName);
expect(customSourcesPage.getStatusCell(libraryName)).toMatch('PUBLIC', 'Wrong library status.');
});
it('[C290173] Should create a private library', () => {
let libraryName = Util.generateRandomString();
let libraryDescription = Util.generateRandomString();
createLibraryDialog.typeLibraryName(libraryName);
createLibraryDialog.typeLibraryDescription(libraryDescription);
createLibraryDialog.selectPrivate();
expect(createLibraryDialog.getSelectedRadio()).toMatch(visibility.private, 'The visibility is not private');
createLibraryDialog.clickCreate();
createLibraryDialog.waitForDialogToClose();
expect(createLibraryDialog.isDialogOpen()).not.toBe(true, 'The Create Library dialog is not closed');
customSourcesPage.navigateToCustomSources();
customSourcesPage.selectMySitesSourceType();
customSourcesPage.checkRowIsDisplayed(libraryName);
expect(customSourcesPage.getStatusCell(libraryName)).toMatch('PRIVATE', 'Wrong library status.');
});
it('[C290174, C290175] Should create a moderated library with a given Library ID', () => {
let libraryName = Util.generateRandomString();
let libraryId = Util.generateRandomString();
let libraryDescription = Util.generateRandomString();
createLibraryDialog.typeLibraryName(libraryName);
createLibraryDialog.typeLibraryId(libraryId);
createLibraryDialog.typeLibraryDescription(libraryDescription);
createLibraryDialog.selectModerated();
expect(createLibraryDialog.getSelectedRadio()).toMatch(visibility.moderated, 'The visibility is not moderated');
createLibraryDialog.clickCreate();
createLibraryDialog.waitForDialogToClose();
expect(createLibraryDialog.isDialogOpen()).not.toBe(true, 'The Create Library dialog is not closed');
customSourcesPage.navigateToCustomSources();
customSourcesPage.selectMySitesSourceType();
customSourcesPage.checkRowIsDisplayed(libraryName);
expect(customSourcesPage.getStatusCell(libraryName)).toMatch('MODERATED', 'Wrong library status.');
});
it('[C290163] Should disable Create button when a mandatory field is not filled in', () => {
let inputValue = Util.generateRandomString();
createLibraryDialog.typeLibraryName(inputValue);
createLibraryDialog.clearLibraryId();
expect(createLibraryDialog.isCreateEnabled()).not.toBe(true, 'The Create button is enabled');
createLibraryDialog.clearLibraryName();
createLibraryDialog.typeLibraryId(inputValue);
expect(createLibraryDialog.isCreateEnabled()).not.toBe(true, 'The Create button is enabled');
createLibraryDialog.clearLibraryId();
createLibraryDialog.typeLibraryDescription(inputValue);
expect(createLibraryDialog.isCreateEnabled()).not.toBe(true, 'The Create button is enabled');
});
it('[C290164] Should auto-fill in the Library Id built from library name', () => {
let name: string[] = ['abcd1234', 'ab cd 12 34', 'ab cd&12+34_@link/*'];
let libraryId: string[] = ['abcd1234', 'ab-cd-12-34', 'ab-cd1234link'];
for (let _i = 0; _i < 3; _i++) {
createLibraryDialog.typeLibraryName(name[_i]);
expect(createLibraryDialog.getLibraryIdText()).toMatch(libraryId[_i]);
createLibraryDialog.clearLibraryName();
}
});
it('[C290176] Should not accept special characters for Library Id', () => {
let name = 'My Library';
let libraryId: string[] = ['My New Library', 'My+New+Library123!', '<>'];
createLibraryDialog.typeLibraryName(name);
for (let _i = 0; _i < 3; _i++) {
createLibraryDialog.typeLibraryId(libraryId[_i]);
expect(createLibraryDialog.isErrorMessageDisplayed()).toBe(true, 'Error message is not displayed');
expect(createLibraryDialog.getErrorMessage()).toMatch('Use numbers and letters only');
}
});
it('[C291793] Should display error for Name field filled in with spaces only', () => {
let name = ' ';
let libraryId = Util.generateRandomString();
createLibraryDialog.typeLibraryName(name);
createLibraryDialog.typeLibraryId(libraryId);
expect(createLibraryDialog.isErrorMessageDisplayed()).toBe(true, 'Error message is not displayed');
expect(createLibraryDialog.getErrorMessage()).toMatch("Library name can't contain only spaces");
});
it('[C290177] Should not accept a duplicate Library Id', () => {
let name = 'My Library';
let libraryId = Util.generateRandomString();
createLibraryDialog.typeLibraryName(name);
createLibraryDialog.typeLibraryId(libraryId);
createLibraryDialog.clickCreate();
createLibraryDialog.waitForDialogToClose();
contentServicesPage.openCreateLibraryDialog();
createLibraryDialog.typeLibraryName(name);
createLibraryDialog.typeLibraryId(libraryId);
expect(createLibraryDialog.isErrorMessageDisplayed()).toBe(true, 'Error message is not displayed');
expect(createLibraryDialog.getErrorMessage()).toMatch("This Library ID isn't available. Try a different Library ID.");
});
it('[C290178] Should accept the same library name but different Library Ids', () => {
let name = createSite.entry.title;
let libraryId = Util.generateRandomString();
createLibraryDialog.typeLibraryName(name.toUpperCase());
createLibraryDialog.typeLibraryId(libraryId);
createLibraryDialog.waitForLibraryNameHint();
expect(createLibraryDialog.getLibraryNameHint()).toMatch('Library name already in use', 'The library name hint is wrong');
createLibraryDialog.clickCreate();
createLibraryDialog.waitForDialogToClose();
expect(createLibraryDialog.isDialogOpen()).not.toBe(true, 'The Create library dialog remained open');
});
it('[C290179] Should not accept more than the expected characters for input fields', () => {
let name = Util.generateRandomString(257);
let libraryId = Util.generateRandomString(73);
let libraryDescription = Util.generateRandomString(513);
createLibraryDialog.typeLibraryName(name);
createLibraryDialog.typeLibraryId(libraryId);
createLibraryDialog.typeLibraryDescription(libraryDescription);
createLibraryDialog.selectPublic();
expect(createLibraryDialog.getErrorMessages(0)).toMatch('Use 256 characters or less for title');
expect(createLibraryDialog.getErrorMessages(1)).toMatch('Use 72 characters or less for the URL name');
expect(createLibraryDialog.getErrorMessages(2)).toMatch('Use 512 characters or less for description');
});
});

View File

@@ -19,6 +19,7 @@ import TestConfig = require('../../test.config');
import { Util } from '../../util/util';
import { ContentListPage } from './dialog/contentListPage';
import { CreateFolderDialog } from './dialog/createFolderDialog';
import { CreateLibraryDialog } from './dialog/createLibraryDialog';
import { NavigationBarPage } from './navigationBarPage';
import { NodeActions } from '../../actions/ACS/node.actions';
import { by, element, protractor, $$, browser } from 'protractor';
@@ -30,11 +31,13 @@ export class ContentServicesPage {
contentList = new ContentListPage();
createFolderDialog = new CreateFolderDialog();
nodeActions = new NodeActions();
createLibraryDialog = new CreateLibraryDialog();
uploadBorder = element(by.id('document-list-container'));
tableBody = element.all(by.css('adf-document-list div[class="adf-datatable-body"]')).first();
contentServices = element(by.css('a[data-automation-id="Content Services"]'));
currentFolder = element(by.css('div[class*="adf-breadcrumb-item adf-active"] div'));
createFolderButton = element(by.css('button[data-automation-id="create-new-folder"]'));
createLibraryButton = element(by.css('button[data-automation-id="create-new-library"]'));
activeBreadcrumb = element(by.css('div[class*="active"]'));
tooltip = by.css('div[class*="--text adf-full-width"] span');
uploadFileButton = element(by.css('input[data-automation-id="upload-single-file"]'));
@@ -360,6 +363,13 @@ export class ContentServicesPage {
return this;
}
openCreateLibraryDialog() {
Util.waitUntilElementIsVisible(this.createLibraryButton);
this.createLibraryButton.click();
this.createLibraryDialog.waitForDialogToOpen();
return this.createLibraryDialog;
}
createNewFolder(folder) {
this.clickOnCreateNewFolder();
this.createFolderDialog.addFolderName(folder);

View File

@@ -0,0 +1,79 @@
/*!
* @license
* Copyright 2016 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 { Util } from '../../../util/util';
import { element, by } from 'protractor';
import { ContentListPage } from '../dialog/contentListPage';
import { NavigationBarPage } from '../navigationBarPage';
let source = {
favorites: 'Favorites',
recent: 'Recent',
sharedLinks: 'Shared Links',
sites: 'Sites',
mySites: 'My Sites',
trashcan: 'Trashcan',
root: 'Root',
my: 'My',
shared: 'Shared'
};
let column = {
status: 'Status'
};
export class CustomSources {
contentList = new ContentListPage();
navigationBarPage = new NavigationBarPage();
toolbar = element(by.css('app-custom-sources .adf-toolbar-title'));
sourceTypeDropdown = element(by.css('div[class*="select-arrow"]>div'));
getSourceType(option) {
return element(by.cssContainingText('.cdk-overlay-pane span', `${option}`));
}
waitForToolbarToBeVisible() {
Util.waitUntilElementIsVisible(this.toolbar);
return this;
}
navigateToCustomSources() {
this.navigationBarPage.navigateToCustomSources();
this.waitForToolbarToBeVisible();
}
clickOnSourceType() {
return this.sourceTypeDropdown.click();
}
selectMySitesSourceType() {
this.clickOnSourceType();
this.getSourceType(source.mySites).click();
}
checkRowIsDisplayed(rowName) {
let row = this.contentList.getRowsName(rowName);
Util.waitUntilElementIsVisible(row);
}
getStatusCell(rowName) {
Util.waitUntilElementIsVisible(this.contentList.getCellByNameAndColumn(rowName, column.status));
return this.contentList.getCellByNameAndColumn(rowName, column.status).getText();
}
}

View File

@@ -47,11 +47,11 @@ export class ContentListPage {
}
getTooltip(nodeName) {
return this.getRowByRowName(nodeName).element(by.css(`#document-list-container span[title="${nodeName}"]`)).getAttribute('title');
return this.getRowByRowName(nodeName).element(by.css(`adf-document-list span[title="${nodeName}"]`)).getAttribute('title');
}
getRowsName(content) {
let row = element.all(by.css(`#document-list-container span[title='${content}']`)).first();
let row = element.all(by.css(`adf-document-list span[title='${content}']`)).first();
Util.waitUntilElementIsVisible(row);
return row;
}
@@ -61,6 +61,10 @@ export class ContentListPage {
return this.getRowsName(content).element(this.rowByRowName);
}
getCellByNameAndColumn(content, columnName) {
return this.getRowByRowName(content).element(by.css(`div[title='${columnName}']`));
}
getAllDisplayedRows() {
return element.all(this.rows).count();
}

View File

@@ -0,0 +1,169 @@
/*!
* @license
* Copyright 2016 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 { by, element, browser, protractor } from 'protractor';
import { Util } from '../../../util/util';
export class CreateLibraryDialog {
libraryDialog = element(by.css('[role="dialog"]'));
libraryTitle = element(by.css('.adf-library-dialog>h2'));
libraryNameField = element(by.css('input[formcontrolname="title"]'));
libraryIdField = element(by.css('input[formcontrolname="id"]'));
libraryDescriptionField = element(by.css('textarea[formcontrolname="description"]'));
publicRadioButton = element(by.css('[data-automation-id="PUBLIC"]>label'));
privateRadioButton = element(by.css('[data-automation-id="PRIVATE"]>label'));
moderatedRadioButton = element(by.css('[data-automation-id="MODERATED"]>label'));
cancelButton = element(by.css('button[data-automation-id="cancel-library-id"]'));
createButton = element(by.css('button[data-automation-id="create-library-id"]'));
errorMessage = element(by.css('.mat-dialog-content .mat-error'));
errorMessages = element.all(by.css('.mat-dialog-content .mat-error'));
libraryNameHint = element(by.css('adf-library-dialog .mat-hint'));
getSelectedRadio() {
let radio = element(by.css('.mat-radio-button[class*="checked"]'));
Util.waitUntilElementIsVisible(radio);
return radio.getText();
}
waitForDialogToOpen() {
Util.waitUntilElementIsPresent(this.libraryDialog);
return this;
}
waitForDialogToClose() {
Util.waitUntilElementIsNotOnPage(this.libraryDialog);
return this;
}
isDialogOpen() {
return browser.isElementPresent(this.libraryDialog);
}
getTitle() {
return this.libraryTitle.getText();
}
getLibraryIdText() {
return this.libraryIdField.getAttribute('value');
}
isErrorMessageDisplayed() {
return this.errorMessage.isDisplayed();
}
getErrorMessage() {
Util.waitUntilElementIsVisible(this.errorMessage);
return this.errorMessage.getText();
}
getErrorMessages(position) {
Util.waitUntilElementIsVisible(this.errorMessages);
return this.errorMessages.get(position).getText();
}
waitForLibraryNameHint() {
Util.waitUntilElementIsVisible(this.libraryNameHint);
return this;
}
getLibraryNameHint() {
Util.waitUntilElementIsVisible(this.libraryNameHint);
return this.libraryNameHint.getText();
}
isNameDisplayed() {
return this.libraryNameField.isDisplayed();
}
isLibraryIdDisplayed() {
return this.libraryIdField.isDisplayed();
}
isDescriptionDisplayed() {
return this.libraryDescriptionField.isDisplayed();
}
isPublicDisplayed() {
return this.publicRadioButton.isDisplayed();
}
isModeratedDisplayed() {
return this.moderatedRadioButton.isDisplayed();
}
isPrivateDisplayed() {
return this.privateRadioButton.isDisplayed();
}
isCreateEnabled() {
return this.createButton.isEnabled();
}
isCancelEnabled() {
return this.cancelButton.isEnabled();
}
clickCreate() {
Util.waitUntilElementIsClickable(this.createButton);
this.createButton.click();
}
clickCancel() {
this.cancelButton.click();
}
typeLibraryName(libraryName: string) {
this.libraryNameField.clear();
this.libraryNameField.sendKeys(libraryName);
}
typeLibraryId(libraryId) {
this.libraryIdField.clear();
this.libraryIdField.sendKeys(libraryId);
}
typeLibraryDescription(libraryDescription) {
this.libraryDescriptionField.clear();
this.libraryDescriptionField.sendKeys(libraryDescription);
}
clearLibraryName() {
this.libraryNameField.clear();
this.libraryNameField.sendKeys(' ', protractor.Key.CONTROL, 'a', protractor.Key.NULL, protractor.Key.BACK_SPACE);
}
clearLibraryId() {
this.libraryIdField.clear();
this.libraryIdField.sendKeys(' ', protractor.Key.CONTROL, 'a', protractor.Key.NULL, protractor.Key.BACK_SPACE);
}
clearLibraryDescription() {
this.libraryDescriptionField.clear();
this.libraryDescriptionField.sendKeys(' ', protractor.Key.CONTROL, 'a', protractor.Key.NULL, protractor.Key.BACK_SPACE);
}
selectPublic() {
this.publicRadioButton.click();
}
selectPrivate() {
this.privateRadioButton.click();
}
selectModerated() {
this.moderatedRadioButton.click();
}
}

View File

@@ -46,6 +46,7 @@ export class NavigationBarPage {
processListButton = element(by.css('a[data-automation-id="Process List"]'));
treeViewButton = element(by.css('a[data-automation-id="Tree View"]'));
iconsButton = element(by.css('a[data-automation-id="Icons"]'));
customSourcesButton = element(by.css('a[data-automation-id="Custom Sources"]'));
navigateToDatatable() {
Util.waitUntilElementIsVisible(this.dataTableButton);
@@ -221,4 +222,9 @@ export class NavigationBarPage {
Util.waitUntilElementIsVisible(this.processListButton);
return this;
};
navigateToCustomSources() {
Util.waitUntilElementIsVisible(this.customSourcesButton);
this.customSourcesButton.click();
}
}

View File

@@ -68,6 +68,7 @@
color="primary"
[disabled]="option.disabled"
*ngFor="let option of visibilityOptions"
[attr.data-automation-id]="option.value"
[value]="option.value"
[checked]="visibilityOption.value === option.value"
>
@@ -78,7 +79,7 @@
</mat-dialog-content>
<mat-dialog-actions class="adf-action-buttons">
<button mat-button mat-dialog-close>
<button mat-button mat-dialog-close data-automation-id="cancel-library-id">
{{ 'LIBRARY.DIALOG.CANCEL' | translate }}
</button>
@@ -87,6 +88,7 @@
mat-button
(click)="submit()"
[disabled]="!form.valid"
data-automation-id="create-library-id"
>
{{ 'LIBRARY.DIALOG.CREATE' | translate }}
</button>