-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tabs): adds e2e tests for tabs (#650)
closes #549
- Loading branch information
1 parent
bbbc87f
commit 3c74ae0
Showing
8 changed files
with
156 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import ElementArrayFinder = protractor.ElementArrayFinder; | ||
import ElementFinder = protractor.ElementFinder; | ||
|
||
describe('tabs', () => { | ||
describe('basic behavior', () => { | ||
let tabGroup: ElementFinder; | ||
let tabLabels: ElementArrayFinder; | ||
let tabBodies: ElementArrayFinder; | ||
|
||
beforeEach(() => { | ||
browser.get('/tabs'); | ||
tabGroup = element(by.css('md-tab-group')); | ||
tabLabels = element.all(by.css('.md-tab-label')); | ||
tabBodies = element.all(by.css('.md-tab-body')); | ||
}); | ||
|
||
it('should change tabs when the label is clicked', () => { | ||
tabLabels.get(1).click(); | ||
expect(getActiveStates(tabLabels)).toEqual([false, true, false]); | ||
expect(getActiveStates(tabBodies)).toEqual([false, true, false]); | ||
|
||
tabLabels.get(0).click(); | ||
expect(getActiveStates(tabLabels)).toEqual([true, false, false]); | ||
expect(getActiveStates(tabBodies)).toEqual([true, false, false]); | ||
}); | ||
|
||
it('should change focus with keyboard interaction', () => { | ||
tabLabels.get(0).click(); | ||
expect(getFocusStates(tabLabels)).toEqual([true, false, false]); | ||
|
||
pressKey(protractor.Key.RIGHT); | ||
expect(getFocusStates(tabLabels)).toEqual([false, true, false]); | ||
|
||
pressKey(protractor.Key.RIGHT); | ||
expect(getFocusStates(tabLabels)).toEqual([false, false, true]); | ||
|
||
pressKey(protractor.Key.RIGHT); | ||
expect(getFocusStates(tabLabels)).toEqual([false, false, true]); | ||
|
||
pressKey(protractor.Key.LEFT); | ||
expect(getFocusStates(tabLabels)).toEqual([false, true, false]); | ||
|
||
pressKey(protractor.Key.LEFT); | ||
expect(getFocusStates(tabLabels)).toEqual([true, false, false]); | ||
|
||
pressKey(protractor.Key.LEFT); | ||
expect(getFocusStates(tabLabels)).toEqual([true, false, false]); | ||
}); | ||
}); | ||
}); | ||
|
||
/** | ||
* A helper function to perform the sendKey action | ||
* @param key | ||
*/ | ||
function pressKey(key: string) { | ||
browser.actions().sendKeys(key).perform(); | ||
} | ||
|
||
/** | ||
* Returns an array of true/false that represents the focus states of the provided elements | ||
* @param elements | ||
* @returns {webdriver.promise.Promise<Promise<boolean>[]>|webdriver.promise.Promise<T[]>} | ||
*/ | ||
function getFocusStates(elements: ElementArrayFinder) { | ||
return elements.map(element => { | ||
return element.getText().then(elementText => { | ||
return browser.driver.switchTo().activeElement().getText().then(activeText => { | ||
return activeText === elementText; | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Returns an array of true/false that represents the active states for the provided elements | ||
* @param elements | ||
* @returns {webdriver.promise.Promise<Promise<boolean>[]>|webdriver.promise.Promise<T[]>} | ||
*/ | ||
function getActiveStates(elements: ElementArrayFinder) { | ||
return getClassStates(elements, 'md-active'); | ||
} | ||
|
||
/** | ||
* Returns an array of true/false values that represents whether the provided className is on | ||
* each element | ||
* @param elements | ||
* @param className | ||
* @returns {webdriver.promise.Promise<Promise<boolean>[]>|webdriver.promise.Promise<T[]>} | ||
*/ | ||
function getClassStates(elements: ElementArrayFinder, className: string) { | ||
return elements.map(element => { | ||
return element.getAttribute('class').then(classes => { | ||
return classes.split(/ +/g).indexOf(className) >= 0; | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<a md-list-item [routerLink]="['button']">Button</a> | ||
<a md-list-item [routerLink]="['tabs']">Tabs</a> | ||
|
||
<router-outlet></router-outlet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import {provideRouter, RouterConfig} from '@angular/router'; | ||
import {Home} from './e2e-app'; | ||
import {ButtonE2E} from '../button/button-e2e'; | ||
import {BasicTabs} from '../tabs/tabs-e2e'; | ||
|
||
|
||
export const routes: RouterConfig = [ | ||
{path: '', component: Home}, | ||
{path: 'button', component: ButtonE2E}, | ||
{path: 'tabs', component: BasicTabs}, | ||
]; | ||
|
||
export const E2E_APP_ROUTE_PROVIDER = provideRouter(routes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<section> | ||
<md-tab-group> | ||
<md-tab> | ||
<template md-tab-label>One</template> | ||
<template md-tab-content>First tab's content</template> | ||
</md-tab> | ||
<md-tab> | ||
<template md-tab-label>Two</template> | ||
<template md-tab-content>Second tab's content</template> | ||
</md-tab> | ||
<md-tab> | ||
<template md-tab-label>Three</template> | ||
<template md-tab-content>Third tab's content</template> | ||
</md-tab> | ||
</md-tab-group> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Component} from '@angular/core'; | ||
import {MD_TABS_DIRECTIVES} from '@angular2-material/tabs/tabs'; | ||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'tabs-e2e', | ||
templateUrl: 'tabs-e2e.html', | ||
directives: [MD_TABS_DIRECTIVES] | ||
}) | ||
export class BasicTabs {} |