[ACA-1797] add tests for viewer actions extension (#666)

This commit is contained in:
Adina Parpalita
2018-09-25 11:29:21 +03:00
committed by Denys Vuika
parent 8f0ae1a917
commit b2b0da4c86
5 changed files with 996 additions and 756 deletions

View File

@@ -69,6 +69,10 @@ export class Menu extends Component {
return this.component.element(by.cssContainingText(Menu.selectors.item, menuItem)); return this.component.element(by.cssContainingText(Menu.selectors.item, menuItem));
} }
getItemById(id: string) {
return this.component.element(by.id(id));
}
getItemTooltip(menuItem: string): promise.Promise<string> { getItemTooltip(menuItem: string): promise.Promise<string> {
return this.getItemByLabel(menuItem).getAttribute('title'); return this.getItemByLabel(menuItem).getAttribute('title');
} }
@@ -78,6 +82,10 @@ export class Menu extends Component {
} }
getItemIdAttribute(menuItem: string) {
return this.getItemByLabel(menuItem).getAttribute('id');
}
getItemsCount(): promise.Promise<number> { getItemsCount(): promise.Promise<number> {
return this.items.count(); return this.items.count();
} }

View File

@@ -56,6 +56,10 @@ export class Toolbar extends Component {
return this.component.element(by.css(`${Toolbar.selectors.button}[title="${title}"]`)); return this.component.element(by.css(`${Toolbar.selectors.button}[title="${title}"]`));
} }
getButtonById(id: string) {
return this.component.element(by.id(id));
}
async openMoreMenu() { async openMoreMenu() {
await this.getButtonByTitleAttribute('More actions').click(); await this.getButtonByTitleAttribute('More actions').click();
await this.menu.waitForMenuToOpen(); await this.menu.waitForMenuToOpen();

View File

@@ -2,11 +2,7 @@
"$schema": "../../extension.schema.json", "$schema": "../../extension.schema.json",
"$name": "app", "$name": "app",
"$version": "1.0.0", "$version": "1.0.0",
"$references": [ "$references": ["plugin1.json", "dev.tools.json", "app.header.json"],
"plugin1.json",
"plugin2.json",
"dev.tools.json"
],
"rules": [ "rules": [
{ {
@@ -28,7 +24,8 @@
"parameters": [ "parameters": [
{ "type": "rule", "value": "app.navigation.isRecentFiles" }, { "type": "rule", "value": "app.navigation.isRecentFiles" },
{ "type": "rule", "value": "app.navigation.isSharedFiles" }, { "type": "rule", "value": "app.navigation.isSharedFiles" },
{ "type": "rule", "value": "app.navigation.isSearchResults" } { "type": "rule", "value": "app.navigation.isSearchResults" },
{ "type": "rule", "value": "app.navigation.isFavorites" }
] ]
} }
] ]
@@ -40,7 +37,8 @@
{ "type": "rule", "value": "app.selection.canAddFavorite" }, { "type": "rule", "value": "app.selection.canAddFavorite" },
{ "type": "rule", "value": "app.navigation.isNotRecentFiles" }, { "type": "rule", "value": "app.navigation.isNotRecentFiles" },
{ "type": "rule", "value": "app.navigation.isNotSharedFiles" }, { "type": "rule", "value": "app.navigation.isNotSharedFiles" },
{ "type": "rule", "value": "app.navigation.isNotSearchResults" } { "type": "rule", "value": "app.navigation.isNotSearchResults" },
{ "type": "rule", "value": "app.navigation.isNotFavorites" }
] ]
}, },
{ {
@@ -50,7 +48,8 @@
{ "type": "rule", "value": "app.selection.canRemoveFavorite" }, { "type": "rule", "value": "app.selection.canRemoveFavorite" },
{ "type": "rule", "value": "app.navigation.isNotRecentFiles" }, { "type": "rule", "value": "app.navigation.isNotRecentFiles" },
{ "type": "rule", "value": "app.navigation.isNotSharedFiles" }, { "type": "rule", "value": "app.navigation.isNotSharedFiles" },
{ "type": "rule", "value": "app.navigation.isNotSearchResults" } { "type": "rule", "value": "app.navigation.isNotSearchResults" },
{ "type": "rule", "value": "app.navigation.isNotFavorites" }
] ]
}, },
{ {
@@ -75,7 +74,6 @@
"id": "app.toolbar.permissions", "id": "app.toolbar.permissions",
"type": "core.every", "type": "core.every",
"parameters": [ "parameters": [
{ "type": "rule", "value": "app.selection.file" },
{ "type": "rule", "value": "app.selection.first.canUpdate" }, { "type": "rule", "value": "app.selection.first.canUpdate" },
{ "type": "rule", "value": "app.navigation.isNotTrashcan" } { "type": "rule", "value": "app.navigation.isNotTrashcan" }
] ]
@@ -628,7 +626,57 @@
} }
], ],
"viewer": { "viewer": {
"toolbar": [ "toolbarActions": [
{
"id": "app.toolbar.download",
"order": 100,
"title": "APP.ACTIONS.DOWNLOAD",
"icon": "get_app",
"actions": {
"click": "DOWNLOAD_NODES"
},
"rules": {
"visible": "app.toolbar.canDownload"
}
},
{
"id": "app.viewer.print",
"order": 200,
"title": "APP.ACTIONS.PRINT",
"icon": "print",
"actions": {
"click": "PRINT_FILE"
},
"rules": {
"visible": "app.toolbar.canViewFile"
}
},
{
"id": "app.viewer.share",
"order": 300,
"title": "APP.ACTIONS.SHARE",
"icon": "share",
"actions": {
"click": "SHARE_NODE"
},
"rules": {
"visible": "app.selection.file.canShare"
}
},
{
"id": "app.viewer.fullscreen",
"order": 400,
"title": "APP.ACTIONS.FULLSCREEN",
"icon": "fullscreen",
"actions": {
"click": "FULLSCREEN_VIEWER"
},
"rules": {
"visible": "app.toolbar.canViewFile"
}
}
],
"toolbarMoreMenu": [
{ {
"id": "app.viewer.favorite.add", "id": "app.viewer.favorite.add",
"order": 100, "order": 100,
@@ -653,6 +701,16 @@
"visible": "app.toolbar.favorite.canRemove" "visible": "app.toolbar.favorite.canRemove"
} }
}, },
{
"id": "app.viewer.favorite",
"comment": "workaround for Recent Files and Search API issue",
"type": "custom",
"order": 101,
"component": "app.toolbar.toggleFavorite",
"rules": {
"visible": "app.toolbar.favorite.canToggle"
}
},
{ {
"id": "app.viewer.share", "id": "app.viewer.share",
"order": 300, "order": 300,
@@ -763,4 +821,4 @@
} }
] ]
} }
} }

View File

@@ -628,7 +628,70 @@
} }
], ],
"viewer": { "viewer": {
"toolbar": [ "toolbarActions": [
{
"id": "app.toolbar.download",
"order": 100,
"title": "My custom title",
"icon": "get_app",
"actions": {
"click": "DOWNLOAD_NODES"
},
"rules": {
"visible": "app.toolbar.canDownload"
}
},
{
"id": "app.toolbar.my-action",
"order": 150,
"title": "My action",
"icon": "http",
"actions": {
"click": "SHARE_NODE"
},
"rules": {
"visible": "app.selection.file.canShare"
}
},
{
"id": "app.viewer.print",
"order": 200,
"title": "APP.ACTIONS.PRINT",
"icon": "print",
"disabled": true,
"actions": {
"click": "PRINT_FILE"
},
"rules": {
"visible": "app.toolbar.canViewFile"
}
},
{
"id": "app.viewer.share",
"order": 300,
"title": "APP.ACTIONS.SHARE",
"icon": "share",
"actions": {
"click": "SHARE_NODE"
},
"rules": {
"visible": "app.selection.file.canShare"
}
},
{
"id": "app.viewer.fullscreen",
"order": 400,
"title": "APP.ACTIONS.FULLSCREEN",
"icon": "fullscreen",
"actions": {
"click": "FULLSCREEN_VIEWER"
},
"rules": {
"visible": "app.toolbar.canViewFile"
}
}
],
"toolbarMoreMenu": [
{ {
"id": "app.viewer.favorite.add", "id": "app.viewer.favorite.add",
"order": 100, "order": 100,
@@ -653,6 +716,28 @@
"visible": "app.toolbar.favorite.canRemove" "visible": "app.toolbar.favorite.canRemove"
} }
}, },
{
"id": "app.viewer.favorite",
"comment": "workaround for Recent Files and Search API issue",
"type": "custom",
"order": 101,
"component": "app.toolbar.toggleFavorite",
"rules": {
"visible": "app.toolbar.favorite.canToggle"
}
},
{
"id": "app.toolbar.my-secondary-action",
"order": 150,
"title": "My secondary action",
"icon": "alarm",
"actions": {
"click": "PRINT_FILE"
},
"rules": {
"visible": "app.toolbar.canViewFile"
}
},
{ {
"id": "app.viewer.share", "id": "app.viewer.share",
"order": 300, "order": 300,
@@ -680,7 +765,7 @@
{ {
"id": "app.viewer.move", "id": "app.viewer.move",
"order": 500, "order": 500,
"title": "APP.ACTIONS.MOVE", "title": "My new title",
"icon": "library_books", "icon": "library_books",
"actions": { "actions": {
"click": "MOVE_NODES" "click": "MOVE_NODES"
@@ -717,6 +802,7 @@
"id": "app.viewer.permissions", "id": "app.viewer.permissions",
"order": 800, "order": 800,
"title": "APP.ACTIONS.PERMISSIONS", "title": "APP.ACTIONS.PERMISSIONS",
"disabled": true,
"icon": "settings_input_component", "icon": "settings_input_component",
"actions": { "actions": {
"click": "MANAGE_PERMISSIONS" "click": "MANAGE_PERMISSIONS"

View File

@@ -44,6 +44,28 @@ describe('Extensions - Viewer', () => {
}; };
let docxFileId; let docxFileId;
const customAction = {
id: 'app.toolbar.my-action',
title: 'My action',
icon: 'http'
};
const customSecondaryAction = {
id: 'app.toolbar.my-secondary-action',
title: 'My secondary action',
icon: 'alarm'
};
const downloadButton = {
id: 'app.toolbar.download',
title: 'My custom title'
};
const moveAction = {
id: 'app.viewer.move',
title: 'My new title'
}
const apis = { const apis = {
admin: new RepoClient(), admin: new RepoClient(),
user: new RepoClient(username, username) user: new RepoClient(username, username)
@@ -54,6 +76,7 @@ describe('Extensions - Viewer', () => {
const page = new BrowsingPage(); const page = new BrowsingPage();
const viewer = new Viewer(); const viewer = new Viewer();
const { toolbar } = viewer;
beforeAll(async (done) => { beforeAll(async (done) => {
await apis.admin.people.createUser({ username }); await apis.admin.people.createUser({ username });
@@ -80,6 +103,14 @@ describe('Extensions - Viewer', () => {
done(); done();
}); });
afterEach(async (done) => {
await Utils.pressEscape();
done();
})
xit('');
describe('content', () => {
it('Insert new component in a content viewer - [C284659]', async () => { it('Insert new component in a content viewer - [C284659]', async () => {
await page.dataTable.doubleClickOnRowByName(pdfFile.file_name); await page.dataTable.doubleClickOnRowByName(pdfFile.file_name);
expect(await viewer.isViewerOpened()).toBe(true, 'Viewer is not opened'); expect(await viewer.isViewerOpened()).toBe(true, 'Viewer is not opened');
@@ -92,5 +123,58 @@ describe('Extensions - Viewer', () => {
expect(await viewer.isCustomContentPresent()).toBe(true, 'Custom content is not present'); expect(await viewer.isCustomContentPresent()).toBe(true, 'Custom content is not present');
expect(await viewer.getComponentIdOfView()).toEqual(docxFile.component); expect(await viewer.getComponentIdOfView()).toEqual(docxFile.component);
}); });
});
describe('toolbar actions', () => {
it('Add a new action in the toolbar - [C286416]', async () => {
await page.dataTable.doubleClickOnRowByName(pdfFile.file_name);
expect(await viewer.isViewerOpened()).toBe(true, 'Viewer is not opened');
expect(await toolbar.isButtonPresent(customAction.title)).toBe(true, 'Custom action is not present');
expect(await toolbar.getButtonByTitleAttribute(customAction.title).getAttribute('id')).toEqual(customAction.id);
expect(await toolbar.getButtonByTitleAttribute(customAction.title).getText()).toEqual(customAction.icon);
});
it('Modify title of action from toolbar - [C286417]', async () => {
await page.dataTable.doubleClickOnRowByName(pdfFile.file_name);
expect(await viewer.isViewerOpened()).toBe(true, 'Viewer is not opened');
expect(await toolbar.getButtonById(downloadButton.id).getAttribute('title')).toEqual(downloadButton.title);
});
it('Remove action from toolbar - [C286419]', async () => {
await page.dataTable.doubleClickOnRowByName(pdfFile.file_name);
expect(await viewer.isViewerOpened()).toBe(true, 'Viewer is not opened');
expect(await toolbar.isButtonPresent('Print')).toBe(false, 'Print button is still displayed');
});
});
describe('toolbar More actions menu', () => {
it('Add a new action - [C286420]', async () => {
await page.dataTable.doubleClickOnRowByName(pdfFile.file_name);
expect(await viewer.isViewerOpened()).toBe(true, 'Viewer is not opened');
await toolbar.openMoreMenu();
expect(await toolbar.menu.isMenuItemPresent(customSecondaryAction.title)).toBe(true, 'action is not present');
expect(await toolbar.menu.getItemIconText(customSecondaryAction.title)).toEqual(customSecondaryAction.icon);
expect(await toolbar.menu.getItemIdAttribute(customSecondaryAction.title)).toEqual(customSecondaryAction.id);
});
it('Modify title of action from More actions menu - [C286421]', async () => {
await page.dataTable.doubleClickOnRowByName(pdfFile.file_name);
expect(await viewer.isViewerOpened()).toBe(true, 'Viewer is not opened');
await toolbar.openMoreMenu();
expect(await toolbar.menu.getItemById(moveAction.id).getAttribute('title')).toEqual(moveAction.title);
});
it('Remove action from More actions menu - [C286423]', async () => {
await page.dataTable.doubleClickOnRowByName(pdfFile.file_name);
expect(await viewer.isViewerOpened()).toBe(true, 'Viewer is not opened');
await toolbar.openMoreMenu();
expect(await toolbar.menu.isMenuItemPresent('Permissions')).toBe(false, 'Action is still displayed');
});
});
}); });