Skip to content

Commit

Permalink
[ACA-1259] automate remaining tests for sidebar (Alfresco#977)
Browse files Browse the repository at this point in the history
* automate remaining tests for sidebar

* formatting
  • Loading branch information
adinapitul authored and dhrn committed Apr 30, 2019
1 parent 3e595a3 commit 6107ca2
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 52 deletions.
35 changes: 33 additions & 2 deletions e2e/components/header/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,29 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/

import { ElementFinder, by, browser } from 'protractor';
import { ElementFinder, by, browser, until } from 'protractor';
import { Component } from '../component';
import { UserInfo } from './user-info';
import { Menu } from '../menu/menu';
import { Toolbar } from './../toolbar/toolbar';
import { SearchInput } from '../search/search-input';
import { BROWSER_WAIT_TIMEOUT } from '../../configs';

export class Header extends Component {
private static selectors = {
root: 'app-header',
logoLink: by.css('.app-menu__title'),
userInfo: by.css('aca-current-user'),
moreActions: by.id('app.header.more')
moreActions: by.id('app.header.more'),

sidenavToggle: `[id='adf-sidebar-toggle-start']`,
expandedSidenav: by.css(`[data-automation-id='expanded']`),
collapsedSidenav: by.css(`[data-automation-id='collapsed']`)
};

logoLink: ElementFinder = this.component.element(Header.selectors.logoLink);
moreActions: ElementFinder = browser.element(Header.selectors.moreActions);
sidenavToggle: ElementFinder = this.component.element(by.css(Header.selectors.sidenavToggle));

userInfo: UserInfo = new UserInfo(this.component);
menu: Menu = new Menu();
Expand All @@ -58,5 +64,30 @@ export class Header extends Component {
async isSignOutDisplayed() {
return await this.userInfo.menu.isMenuItemPresent('Sign out');
}

async clickSidenavToggle() {
await this.sidenavToggle.click();
}

async isExpandedSidenav() {
return await browser.isElementPresent(Header.selectors.expandedSidenav);
}

async expandSideNav() {
const expanded = await this.isExpandedSidenav();
if ( !expanded ) {
await this.clickSidenavToggle();
await browser.wait(until.elementLocated(Header.selectors.expandedSidenav), BROWSER_WAIT_TIMEOUT, '--- timeout waiting for expanded sidenav' );
}
}

async collapseSideNav() {
const expanded = await this.isExpandedSidenav();
if ( expanded ) {
await this.clickSidenavToggle();
await browser.wait(until.elementLocated(Header.selectors.collapsedSidenav), BROWSER_WAIT_TIMEOUT, '--- timeout waiting for collapsed sidenav')
}
}

}

42 changes: 25 additions & 17 deletions e2e/components/sidenav/sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/

import { ElementFinder, ElementArrayFinder, by, element } from 'protractor';
import { SIDEBAR_LABELS } from '../../configs';
import { ElementFinder, ElementArrayFinder, by, element, browser } from 'protractor';
import { SIDEBAR_LABELS, BROWSER_WAIT_TIMEOUT } from '../../configs';
import { Menu } from '../menu/menu';
import { Component } from '../component';
import { Utils } from '../../utilities/utils';
Expand All @@ -37,28 +37,29 @@ export class Sidenav extends Component {
expansion_panel: ".mat-expansion-panel-header",
expansion_panel_content: ".mat-expansion-panel-body",
active: 'mat-accent',
activeLink: '.mat-accent',
activeClass: '.item--active',
activeChild: 'item--active',

newButton: '[data-automation-id="create-button"]',

personalFiles: `[id='app.navbar.personalFiles']`,
fileLibraries: `[id='app.navbar.libraries.menu']`,
myLibraries: `[id='app.navbar.libraries.files']`,
favoriteLibraries: `[id='app.navbar.libraries.favorite']`,
shared: `[id='app.navbar.shared']`,
recentFiles: `[id='app.navbar.recentFiles']`,
favorites: `[id='app.navbar.favorites']`,
trash: `[id='app.navbar.trashcan']`
personalFiles: `[data-automation-id='app.navbar.personalFiles']`,
fileLibraries: `[data-automation-id='app.navbar.libraries.menu']`,
myLibraries: `[data-automation-id='app.navbar.libraries.files']`,
favoriteLibraries: `[data-automation-id='app.navbar.libraries.favorite']`,
shared: `[data-automation-id='app.navbar.shared']`,
recentFiles: `[data-automation-id='app.navbar.recentFiles']`,
favorites: `[data-automation-id='app.navbar.favorites']`,
trash: `[data-automation-id='app.navbar.trashcan']`
};

links: ElementArrayFinder = this.component.all(by.css(Sidenav.selectors.link));
activeLink: ElementFinder = this.component.element(by.css(Sidenav.selectors.activeLink));
activeLink: ElementFinder = this.component.element(by.css(Sidenav.selectors.activeClass));
newButton: ElementArrayFinder = this.component.all(by.css(Sidenav.selectors.newButton));

personalFiles: ElementFinder = this.component.element(by.css(Sidenav.selectors.personalFiles));
fileLibraries: ElementFinder = this.component.element(by.css(Sidenav.selectors.fileLibraries));
myLibraries: ElementFinder = this.component.element(by.css(Sidenav.selectors.myLibraries));
favoriteLibraries: ElementFinder = this.component.element(by.css(Sidenav.selectors.favoriteLibraries));
myLibraries: ElementFinder = browser.element(by.css(Sidenav.selectors.myLibraries));
favoriteLibraries: ElementFinder = browser.element(by.css(Sidenav.selectors.favoriteLibraries));
shared: ElementFinder = this.component.element(by.css(Sidenav.selectors.shared));
recentFiles: ElementFinder = this.component.element(by.css(Sidenav.selectors.recentFiles));
favorites: ElementFinder = this.component.element(by.css(Sidenav.selectors.favorites));
Expand Down Expand Up @@ -105,8 +106,7 @@ export class Sidenav extends Component {
}

async isActive(name: string) {
const className = await this.getLinkLabel(name).getAttribute('class');
return className.includes(Sidenav.selectors.active);
return await this.getLinkLabel(name).isElementPresent(by.css(Sidenav.selectors.activeClass));
}

async childIsActive(name: string) {
Expand Down Expand Up @@ -137,7 +137,15 @@ export class Sidenav extends Component {
}

async getLinkTooltip(name: string) {
return await this.getLink(name).getAttribute('title');
const link = this.getLinkLabel(name);

const condition = () => link.getAttribute('title').then(value => value && value.length > 0);

await browser.actions().mouseMove(link).perform();

await browser.wait(condition, BROWSER_WAIT_TIMEOUT);

return await link.getAttribute('title');
}

async clickLink(name: string) {
Expand Down
144 changes: 115 additions & 29 deletions e2e/suites/navigation/sidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,28 @@
*/

import { browser } from 'protractor';

import { APP_ROUTES, SIDEBAR_LABELS } from '../../configs';
import { LoginPage, BrowsingPage } from '../../pages/pages';
import { LoginPage, BrowsingPage, SearchResultsPage } from '../../pages/pages';
import { Utils } from '../../utilities/utils';

describe('Sidebar', () => {
const loginPage = new LoginPage();
const page = new BrowsingPage();
const { sidenav } = page;
const { sidenav, header } = page;
const searchResultsPage = new SearchResultsPage();
const { searchInput } = searchResultsPage.header;

beforeAll(async (done) => {
await loginPage.loginWithAdmin();
done();
});

beforeEach(async (done) => {
await Utils.pressEscape();
await header.expandSideNav();
done();
});

it('has "Personal Files" as default - [C217149]', async () => {
expect(await browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES);
expect(await sidenav.isActive(SIDEBAR_LABELS.PERSONAL_FILES)).toBe(true, 'Default active link');
Expand All @@ -51,7 +59,7 @@ describe('Sidebar', () => {
});

it('My Libraries is automatically selected on expanding File Libraries - [C289900]', async () => {
await page.clickFileLibraries();
await sidenav.expandFileLibraries();
expect(await browser.getCurrentUrl()).toContain(APP_ROUTES.MY_LIBRARIES);
expect(await sidenav.isActive(SIDEBAR_LABELS.FILE_LIBRARIES)).toBe(false, 'File Libraries link is active');
expect(await sidenav.childIsActive(SIDEBAR_LABELS.MY_LIBRARIES)).toBe(true, 'My Libraries link not active');
Expand All @@ -71,12 +79,6 @@ describe('Sidebar', () => {
expect(await sidenav.childIsActive(SIDEBAR_LABELS.MY_LIBRARIES)).toBe(true, 'My Libraries link not active');
});

it('navigates to "Personal Files" - [C280409]', async () => {
await page.clickPersonalFiles();
expect(await browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES);
expect(await sidenav.isActive(SIDEBAR_LABELS.PERSONAL_FILES)).toBe(true, 'Personal Files link not active');
});

it('navigates to "Shared Files" - [C213110]', async () => {
await page.clickSharedFiles();
expect(await browser.getCurrentUrl()).toContain(APP_ROUTES.SHARED_FILES);
Expand All @@ -101,51 +103,135 @@ describe('Sidebar', () => {
expect(await sidenav.isActive(SIDEBAR_LABELS.TRASH)).toBe(true, 'Trash link not active');
});

// TODO: incomplete test
it('navigates to "Personal Files" - [C280409]', async () => {
await page.clickPersonalFiles();
expect(await browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES);
expect(await sidenav.isActive(SIDEBAR_LABELS.PERSONAL_FILES)).toBe(true, 'Personal Files link not active');
});

it('Personal Files tooltip - [C217151]', async () => {
await page.clickPersonalFiles();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.PERSONAL_FILES)).toContain('View your Personal Files');

await header.collapseSideNav();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.PERSONAL_FILES)).toContain('View your Personal Files');
});

it('Shared Files tooltip - [C213111]', async () => {
await page.clickSharedFiles();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.SHARED_FILES)).toContain('View files that have been shared');

await header.collapseSideNav();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.SHARED_FILES)).toContain('View files that have been shared');
});

it('Recent Files tooltip - [C213167]', async () => {
await page.clickRecentFiles();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.RECENT_FILES)).toContain('View files you recently edited');

await header.collapseSideNav();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.RECENT_FILES)).toContain('View files you recently edited');
});

it('Favorites tooltip - [C217153]', async () => {
await page.clickFavorites();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.FAVORITES)).toContain('View your favorite files and folders');

await header.collapseSideNav();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.FAVORITES)).toContain('View your favorite files and folders');
});

it('Trash tooltip - [C217154]', async () => {
await page.clickTrash();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.TRASH)).toContain('View deleted files in the trash');

await header.collapseSideNav();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.TRASH)).toContain('View deleted files in the trash');
});

// TODO: incomplete test
it('File Libraries tooltip - [C217152]', async () => {
await page.clickFileLibraries();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.FILE_LIBRARIES)).toContain('File Libraries');

await header.collapseSideNav();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.FILE_LIBRARIES)).toContain('File Libraries');
});

// TODO: incomplete test
it('My Libraries tooltip - [C289916]', async () => {
await page.goToMyLibraries();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.MY_LIBRARIES)).toContain('Access my libraries');

await header.collapseSideNav();
await sidenav.clickLink(SIDEBAR_LABELS.FILE_LIBRARIES);
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.MY_LIBRARIES)).toContain('Access my libraries');
});

// TODO: incomplete test
it('Favorite Libraries tooltip - [C289917]', async () => {
await page.goToFavoriteLibraries();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.FAVORITE_LIBRARIES)).toContain('Access my favorite libraries');

await header.collapseSideNav();
await sidenav.clickLink(SIDEBAR_LABELS.FILE_LIBRARIES);
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.FAVORITE_LIBRARIES)).toContain('Access my favorite libraries');
});

// TODO: incomplete test
it('Shared Files tooltip - [C213111]', async () => {
await page.clickSharedFiles();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.SHARED_FILES)).toContain('View files that have been shared');
it('default state is expanded - [C269095]', async () => {
expect(await header.isExpandedSidenav()).toBe(true, 'Sidebar not expanded');
});

// TODO: incomplete test
it('Recent Files tooltip - [C213167]', async () => {
await page.clickRecentFiles();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.RECENT_FILES)).toContain('View files you recently edited');
it('sidebar toggle - [C269096]', async () => {
await header.collapseSideNav();
expect(await header.isExpandedSidenav()).toBe(false, 'Sidebar not collapsed');

await header.expandSideNav();
expect(await header.isExpandedSidenav()).toBe(true, 'Sidebar not expanded');
});

// TODO: incomplete test
it('Favorites tooltip - [C217153]', async () => {
it('sidebar state is preserved on page refresh - [C269100]', async () => {
expect(await header.isExpandedSidenav()).toBe(true, 'Sidebar not expanded');
await page.refresh();
expect(await header.isExpandedSidenav()).toBe(true, 'Sidebar not expanded');

await header.collapseSideNav();
expect(await header.isExpandedSidenav()).toBe(false, 'Sidebar not collapsed');
await page.refresh();
expect(await header.isExpandedSidenav()).toBe(false, 'Sidebar not collapsed');
});

it('sidebar state is preserved after logout / login - [C269102]', async () => {
await header.collapseSideNav();
await page.signOut();
await loginPage.loginWithAdmin();

expect(await header.isExpandedSidenav()).toBe(false, 'Sidebar not collapsed');
});

it('sidebar is collapsed automatically when Search Results opens - [C277223]', async () => {
await searchInput.clickSearchButton();
/* cspell:disable-next-line */
await searchInput.searchForTextAndCloseSearchOptions('qwertyuiop');
await searchResultsPage.waitForResults();

expect(await header.isExpandedSidenav()).toBe(false, 'Sidebar not collapsed');
});

it('sidenav returns to the default state when navigating away from the Search Results page - [C277224]', async () => {
await searchInput.clickSearchButton();
/* cspell:disable-next-line */
await searchInput.searchForTextAndCloseSearchOptions('qwertyuiop');
await searchResultsPage.waitForResults();
await page.clickFavorites();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.FAVORITES)).toContain('View your favorite files and folders');

expect(await header.isExpandedSidenav()).toBe(true, 'Sidebar not expanded');
});

// TODO: incomplete test
it('Trash tooltip - [C217154]', async () => {
await page.clickTrash();
expect(await sidenav.getLinkTooltip(SIDEBAR_LABELS.TRASH)).toContain('View deleted files in the trash');
it('sidenav can be expanded when search results page is displayed - [C277230]', async () => {
await searchInput.clickSearchButton();
/* cspell:disable-next-line */
await searchInput.searchForTextAndCloseSearchOptions('qwertyuiop');
await searchResultsPage.waitForResults();
await header.expandSideNav();

expect(await header.isExpandedSidenav()).toBe(true, 'Sidebar not expanded');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@
<ng-template let-isMenuMinimized="isMenuMinimized">
<app-sidenav
[showLabel]="!isMenuMinimized()"
[attr.data-automation-id]="
isMenuMinimized() ? 'collapsed' : 'expanded'
"
(swipeleft)="hideMenu($event)"
></app-sidenav>
</ng-template>
</adf-sidenav-layout-navigation>

<adf-sidenav-layout-content>
<ng-template> <router-outlet></router-outlet> </ng-template>
<ng-template>
<router-outlet></router-outlet>
</ng-template>
</adf-sidenav-layout-content>
</adf-sidenav-layout>

Expand Down
Loading

0 comments on commit 6107ca2

Please sign in to comment.