-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tabs): adds e2e tests for tabs #650
Merged
robertmesserle
merged 1 commit into
angular:master
from
robertmesserle:feat/tabs/e2e-tests
Jul 7, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]); | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing for focus behavior? Keyboard interaction? |
||
}); | ||
|
||
/** | ||
* 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add descriptions explaining what these functions are returning? |
||
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 {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import {ElementArrayFinder} from ...
? etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, this is how WebStorm fixed my code.