Skip to content

Commit

Permalink
WEBUI-1399: Update ftest for features: Collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranit-Sotre committed Jan 4, 2024
1 parent c2c1782 commit 20bbe52
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 148 deletions.
29 changes: 16 additions & 13 deletions packages/nuxeo-web-ui-ftest/features/step_definitions/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ Then('I select all the documents', async function() {
});

Then('I deselect the {string} document', async function(title) {
await this.ui.browser.waitForVisible();
await this.ui.browser.deselectChildDocument(title);
const browser = await this.ui.browser;
await browser.waitForVisible();
await browser.deselectChildDocument(title);
});

Then('I select the {string} document', async function(title) {
Expand All @@ -105,9 +106,12 @@ When('I cannot see the display selection link', function() {
this.ui.browser.selectionToolbar.waitForNotVisible('.selectionLink').should.be.true;
});

Then('I can add selection to the {string} collection', function(collectionName) {
this.ui.browser.waitForVisible();
this.ui.browser.selectionToolbar.addToCollectionDialog.addToCollection(collectionName);
Then('I can add selection to the {string} collection', async function(collectionName) {
const browserEle = await this.ui.browser;
await browserEle.waitForVisible();
const selectionToolEle = await browserEle.selectionToolbar;
const addToDialog = await selectionToolEle.addToCollectionDialog;
await addToDialog.addToCollection(collectionName);
});

Then('I can add selection to clipboard', async function() {
Expand Down Expand Up @@ -144,14 +148,13 @@ When('I sort the content by {string} in {string} order', async function(field, o
});

Then('I can see {int} document(s)', async function(numberOfResults) {
const browserEle = await this.ui.browser;
const results = await browserEle.results;
await results.waitForVisible();
const displayMode = await results.displayMode;
await driver.pause(3000);
const countEle = await results.resultsCount(displayMode);
if (countEle !== numberOfResults) {
throw Error('Number of documents are not as expected');
const out = await this.ui.browser;
const uiResult = await out.results;

const displayMode = await uiResult.displayMode;
const outResult = await uiResult.resultsCount(displayMode);
if (outResult !== numberOfResults) {
throw Error(`Expecting to get ${numberOfResults} results but found ${outResult}`);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Then('I see a toast notification with the following message {string}', async fun
await notificationMessage.should.be.equals(trimmedMessage);
});

Then('I click the toast notification dismiss button', function() {
this.ui.getToastDismissButton().click();
this.ui.waitForToastNotVisible();
Then('I click the toast notification dismiss button', async function() {
const snackbar = await this.ui.getToastDismissButton();
await snackbar.click();
await this.ui.waitForToastNotVisible();
});
Original file line number Diff line number Diff line change
@@ -1,26 +1,69 @@
import { Then } from '../../node_modules/@cucumber/cucumber';

Then('I can see the {string} collection', function(name) {
this.ui.drawer.collections.waitForHasCollection(name).should.be.true;
Then('I can see the {string} collection', async function(name) {
const collection = await this.ui.drawer.collections.waitForHasCollection(name);
if (!collection) {
throw new Error(`Expected I can not click on the ${name} collection`);
}
});
Then('I can click on the {string} collection', function(name) {
this.ui.drawer.collections.select(name).should.be.true;

Then('I can click on the {string} collection', async function(name) {
const myCollection = await this.ui.drawer;
const collectionsEle = await myCollection.collections;
const selectEle = await collectionsEle.select(name);
if (!selectEle) {
throw new Error(`Expected I can not click on the ${name} collection`);
}
});
Then('I can see that the document belongs to the collection', function() {
this.ui.browser.waitForHasChild(this.doc).should.be.true;

Then('I can see that the document belongs to the collection', async function() {
const browser = await this.ui.browser;
const hasChild = await browser.waitForHasChild(this.doc);
if (!hasChild) {
throw new Error('Expected the document belongs to the collection not be visible');
}
});
Then('I can click the document in the collection', function() {
this.ui.browser.clickChild(this.doc.title).should.be.true;

Then('I can click the document in the collection', async function() {
const browserEle = await this.ui.browser;
const clickDocument = await browserEle.clickChild(this.doc.title);
if (!clickDocument) {
throw new Error('Expected I cannot click the document in the collection');
}
});
Then('I can see the collection is in queue mode', function() {
this.ui.drawer.collections.isQueueMode.should.be.true;

Then('I can see the collection is in queue mode', async function() {
const drawerEle = await this.ui.drawer;
const collectionsEle = await drawerEle.collections;
const isQueueModeEle = await collectionsEle.isQueueMode;
if (!isQueueModeEle) {
throw new Error('Expected the collection is in queue mode is not visible');
}
});
Then('I can see the collection queue has the document', function() {
this.ui.drawer.collections.waitForHasMember(this.doc).should.be.true;

Then('I can see the collection queue has the document', async function() {
const drawerEle = await this.ui.drawer;
const collectionsEle = await drawerEle.collections;
const hasMemberEle = await collectionsEle.waitForHasMember(this.doc);
if (!hasMemberEle) {
throw new Error('Expected the collection queue has the document is not visible');
}
});
Then('I can remove the document from the collection queue', function() {
this.ui.drawer.collections.removeMember(this.doc).should.be.true;

Then('I can remove the document from the collection queue', async function() {
const draweerEle = await this.ui.drawer;
const collectionsEle = await draweerEle.collections;
const removeMemberEle = await collectionsEle.removeMember(this.doc);
if (!removeMemberEle) {
throw new Error('Expected I can not remove the document from the collection queue');
}
});
Then('I can see the collection queue does not have the document', function() {
this.ui.drawer.collections.waitForHasMember(this.doc, true).should.be.true;

Then('I can see the collection queue does not have the document', async function() {
const drawerEle = await this.ui.drawer;
const collectionsEle = await drawerEle.collections;
const hasMemberEle = await collectionsEle.waitForHasMember(this.doc, true);
if (!hasMemberEle) {
throw new Error('Expected the collection queue does not have the document is not visible');
}
});
38 changes: 23 additions & 15 deletions packages/nuxeo-web-ui-ftest/features/step_definitions/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ Given(/^This document has a (major|minor) version$/, function(versionType) {
});
});

Given(/^I have a document added to "([^"]*)" collection$/, function(colName) {
Given(/^I have a document added to "([^"]*)" collection$/, async function(colName) {
const docFile = fixtures.documents.init('File');
// create the document
return fixtures.documents
.create(this.doc.path, docFile)
.then((doc) => fixtures.collections.addToNewCollection(doc, colName))
.then((d) => {
this.doc = d;
});
const doc = await fixtures.documents.create(this.doc.path, docFile);
const updatedDoc = await fixtures.collections.addToNewCollection(doc, colName);
this.doc = updatedDoc;
});

Given(/^This document has a "([^"]*)" workflow running$/, async function(workflowName) {
Expand Down Expand Up @@ -250,20 +247,31 @@ Then(/^I can edit the (.*) Note$/, function(format) {
}
});

Then('I add the document to the {string} collection', function(name) {
this.ui.browser.addToCollection(name);
Then('I add the document to the {string} collection', async function(name) {
const browser = await this.ui.browser;
await browser.addToCollection(name);
});

Then('I can see the document belongs to the {string} collection', function(name) {
this.ui.browser.hasCollection(name).should.be.true;
Then('I can see the document belongs to the {string} collection', async function(name) {
await driver.pause(3000);
const browser = await this.ui.browser;
const hasCollection = await browser.hasCollection(name);
if (!hasCollection) {
throw new Error(`Expected the document belongs to the ${name} that is not visible`);
}
});

Then('I can delete the document from the {string} collection', function(name) {
this.ui.browser.removeFromCollection(name);
Then('I can delete the document from the {string} collection', async function(name) {
const deleteCollection = await this.ui.browser;
await deleteCollection.removeFromCollection(name);
});

Then('I can see the document does not belong to the {string} collection', function(name) {
this.ui.browser.doesNotHaveCollection(name).should.be.true;
Then('I can see the document does not belong to the {string} collection', async function(name) {
const browserEle = await this.ui.browser;
const doesNotHaveCollection = await browserEle.doesNotHaveCollection(name);
if (!doesNotHaveCollection) {
throw new Error('Expected the document does not belong to the {string} collection is not visible');
}
});

Then('I add the document to the favorites', async function() {
Expand Down
131 changes: 77 additions & 54 deletions packages/nuxeo-web-ui-ftest/pages/ui/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,70 +148,86 @@ export default class Browser extends BasePage {
await ele.waitForExist();
}

addToCollection(name) {
const button = this.el.$('nuxeo-add-to-collection-button');
button.waitForVisible();
if (!button.isExisting('#dialog') || !button.isVisible('#dialog')) {
button.click();
async addToCollection(name) {
const button = await this.el.$('nuxeo-add-to-collection-button');
await button.waitForVisible();
const dialogExistingEle = await button.isExisting('#dialog');
const dialogVisibleEle = await button.isVisible('#dialog');
if (!dialogExistingEle || !dialogVisibleEle) {
await button.click();
}
const dialog = new AddToCollectionDialog(`${this._selector} nuxeo-add-to-collection-button #dialog`);
dialog.waitForVisible();
dialog.addToCollection(name);
this.el.waitForVisible('nuxeo-document-collections nuxeo-tag');
const dialog = await new AddToCollectionDialog(`${this._selector} nuxeo-add-to-collection-button #dialog`);
await dialog.waitForVisible();
await dialog.addToCollection(name);
const docCollectionEle = await this.el.$('nuxeo-document-collections nuxeo-tag');
await docCollectionEle.waitForVisible();
}

doesNotHaveCollection(name) {
async doesNotHaveCollection(name) {
const page = this.el;
driver.waitUntil(() => {
if (!driver.isExisting('nuxeo-document-collections')) {
return true;
}
try {
const collections = page.elements('nuxeo-document-collections nuxeo-tag');
return collections.every((collection) => collection.getText().trim() !== name);
} catch (e) {
return false;
const nuxeoDocEle = await driver.isExisting('nuxeo-document-collections');
if (!nuxeoDocEle) {
return true;
}
try {
const collections = await page.elements('nuxeo-document-collections nuxeo-tag');
for (let i = 0; i < collections.length; i++) {
const collection = await collections[i];
const getTextEle = await collection.getText();
if (getTextEle.trim() !== name) {
return false;
}
}
}, 'The document does belong to the collection');
return true;
return true;
} catch (e) {
return false;
}
}

hasCollection(name) {
const page = this.el;
driver.waitUntil(() => {
if (!driver.isExisting('nuxeo-document-collections')) {
return false;
}
try {
const collections = page.elements('nuxeo-document-collections nuxeo-tag a');
return collections.some((collection) => collection.getText().trim() === name);
} catch (e) {
return false;
async hasCollection(name) {
const page = await this.el;
const docCollection = await driver.isExisting('nuxeo-document-collections');
if (!docCollection) {
return false;
}
try {
const collections = await page.$$('nuxeo-document-collections nuxeo-tag a');
for (let i = 0; i < collections.length; i++) {
const collection = await collections[i];
const getTextEle = await collection.getText();
if (getTextEle.trim() === name) {
return true;
}
}
}, 'The document does not belong to the collection');
return true;
return false;
} catch (e) {
return false;
}
}

removeFromCollection(name) {
const { el } = this;
el.waitForVisible('nuxeo-document-collections nuxeo-tag');
const collections = this.el.$$('nuxeo-document-collections nuxeo-tag');
collections.some((collection) => {
if (collection.getText().trim() === name) {
const remove = collection.$('iron-icon[name="remove"]');
remove.waitForVisible();
remove.scrollIntoView();
remove.click();
return true;
async removeFromCollection(name) {
const { el } = await this;
await el.$('nuxeo-document-collections nuxeo-tag').waitForVisible();
const collections = await this.el.$$('nuxeo-document-collections nuxeo-tag');
let found = false;
for (let index = 0; index < collections.length; index++) {
const collectionText = await collections[index].getText();
if (collectionText.trim() === name) {
const remove = await collections[index].$('iron-icon[name="remove"]');
await remove.waitForVisible();
await remove.scrollIntoView();
await remove.click();
found = true;
}
return false;
});
}
return found;
}

removeSelectionFromCollection() {
const button = this.el.$('nuxeo-collection-remove-action');
button.waitForVisible();
button.click();
async removeSelectionFromCollection() {
const button = await this.el.$('nuxeo-collection-remove-action');
await button.waitForVisible();
await button.click();
}

get isFavorite() {
Expand Down Expand Up @@ -239,11 +255,18 @@ export default class Browser extends BasePage {
})();
}

waitForHasChild(doc) {
async waitForHasChild(doc) {
const { el } = this;
el.waitForVisible('nuxeo-data-table[name="table"] nuxeo-data-table-row a.title');
const titles = el.$$('nuxeo-data-table[name="table"] nuxeo-data-table-row a.title');
return titles.some((title) => title.getText().trim() === doc.title);
const dataTable = await el.$('nuxeo-data-table[name="table"] nuxeo-data-table-row a.title');
await dataTable.waitForVisible();
const titles = await el.$$('nuxeo-data-table[name="table"] nuxeo-data-table-row a.title');
for (let i = 0; i < titles.length; i++) {
const row = await titles[i].getText();
if (row.trim() === doc.title) {
return true;
}
}
return false;
}

async clickChild(title) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import BasePage from '../../base';

export default class AddToCollectionDialog extends BasePage {
addToCollection(collectionName) {
const collectionSelect = this.el.element('#nxSelect');
collectionSelect.waitForVisible();
fixtures.layouts.setValue(collectionSelect, collectionName);
this.el.waitForEnabled('paper-button[name="add"]');
this.el.click('paper-button[name = "add"]');
async addToCollection(collectionName) {
const collectionSelect = await this.el.$('#nxSelect');
await collectionSelect.waitForVisible();
await fixtures.layouts.setValue(collectionSelect, collectionName);
await this.el.waitForEnabled('paper-button[name="add"]');
const addCollection = await this.el.$('paper-button[name = "add"]');
await addCollection.click();
}

waitForVisible() {
Expand Down
Loading

0 comments on commit 20bbe52

Please sign in to comment.