2016-12-19 20:17:23 +02:00
|
|
|
import {browser, Key, protractor} from 'protractor';
|
|
|
|
|
import {MenuPage} from './menu-page';
|
2016-07-22 13:27:17 -07:00
|
|
|
|
|
|
|
|
describe('menu', () => {
|
|
|
|
|
let page: MenuPage;
|
|
|
|
|
|
2016-07-21 15:45:53 -07:00
|
|
|
beforeEach(function() {
|
2016-07-22 13:27:17 -07:00
|
|
|
page = new MenuPage();
|
2016-07-21 15:45:53 -07:00
|
|
|
});
|
|
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
it('should open menu when the trigger is clicked', () => {
|
|
|
|
|
page.expectMenuPresent(false);
|
|
|
|
|
page.trigger().click();
|
2016-07-21 15:45:53 -07:00
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
page.expectMenuPresent(true);
|
2016-12-06 07:46:15 +01:00
|
|
|
expect(page.menu().getText()).toEqual('One\nTwo\nThree\nFour');
|
2016-07-21 15:45:53 -07:00
|
|
|
});
|
|
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
it('should close menu when menu item is clicked', () => {
|
|
|
|
|
page.trigger().click();
|
|
|
|
|
page.items(0).click();
|
|
|
|
|
page.expectMenuPresent(false);
|
2016-07-21 15:45:53 -07:00
|
|
|
});
|
|
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
it('should run click handlers on regular menu items', () => {
|
|
|
|
|
page.trigger().click();
|
|
|
|
|
page.items(0).click();
|
|
|
|
|
expect(page.getResultText()).toEqual('one');
|
|
|
|
|
|
|
|
|
|
page.trigger().click();
|
|
|
|
|
page.items(1).click();
|
|
|
|
|
expect(page.getResultText()).toEqual('two');
|
2016-07-21 15:45:53 -07:00
|
|
|
});
|
|
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
it('should run not run click handlers on disabled menu items', () => {
|
|
|
|
|
page.trigger().click();
|
|
|
|
|
page.items(2).click();
|
|
|
|
|
expect(page.getResultText()).toEqual('');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should support multiple triggers opening the same menu', () => {
|
|
|
|
|
page.triggerTwo().click();
|
2016-12-06 07:46:15 +01:00
|
|
|
expect(page.menu().getText()).toEqual('One\nTwo\nThree\nFour');
|
2016-07-22 13:27:17 -07:00
|
|
|
page.expectMenuAlignedWith(page.menu(), 'trigger-two');
|
|
|
|
|
|
2016-11-03 15:55:34 -07:00
|
|
|
page.backdrop().click();
|
2016-07-22 13:27:17 -07:00
|
|
|
page.expectMenuPresent(false);
|
|
|
|
|
|
|
|
|
|
page.trigger().click();
|
2016-12-06 07:46:15 +01:00
|
|
|
expect(page.menu().getText()).toEqual('One\nTwo\nThree\nFour');
|
2016-07-22 13:27:17 -07:00
|
|
|
page.expectMenuAlignedWith(page.menu(), 'trigger');
|
2016-07-21 15:45:53 -07:00
|
|
|
|
2016-11-03 15:55:34 -07:00
|
|
|
page.backdrop().click();
|
2016-07-22 13:27:17 -07:00
|
|
|
page.expectMenuPresent(false);
|
2016-07-21 15:45:53 -07:00
|
|
|
});
|
|
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
it('should mirror classes on host to menu template in overlay', () => {
|
|
|
|
|
page.trigger().click();
|
2016-12-19 20:17:23 +02:00
|
|
|
page.menu().getAttribute('class').then((classes: string) => {
|
2016-11-03 15:55:34 -07:00
|
|
|
expect(classes).toContain('md-menu-panel custom');
|
2016-07-22 13:27:17 -07:00
|
|
|
});
|
2016-07-21 15:45:53 -07:00
|
|
|
});
|
|
|
|
|
|
2016-09-01 11:56:08 -07:00
|
|
|
describe('keyboard events', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
// click start button to avoid tabbing past navigation
|
|
|
|
|
page.start().click();
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.TAB);
|
2016-09-01 11:56:08 -07:00
|
|
|
});
|
|
|
|
|
|
2016-10-19 15:36:54 -07:00
|
|
|
it('should auto-focus the first item when opened with ENTER', () => {
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.ENTER);
|
2016-09-01 11:56:08 -07:00
|
|
|
page.expectFocusOn(page.items(0));
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-19 15:36:54 -07:00
|
|
|
it('should auto-focus the first item when opened with SPACE', () => {
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.SPACE);
|
2016-10-19 15:36:54 -07:00
|
|
|
page.expectFocusOn(page.items(0));
|
|
|
|
|
});
|
|
|
|
|
|
2016-09-01 11:56:08 -07:00
|
|
|
it('should not focus the first item when opened with mouse', () => {
|
|
|
|
|
page.trigger().click();
|
|
|
|
|
page.expectFocusOn(page.trigger());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should focus subsequent items when down arrow is pressed', () => {
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.ENTER);
|
|
|
|
|
page.pressKey(Key.DOWN);
|
2016-09-01 11:56:08 -07:00
|
|
|
page.expectFocusOn(page.items(1));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should focus previous items when up arrow is pressed', () => {
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.ENTER);
|
|
|
|
|
page.pressKey(Key.DOWN);
|
|
|
|
|
page.pressKey(Key.UP);
|
2016-09-01 11:56:08 -07:00
|
|
|
page.expectFocusOn(page.items(0));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should skip disabled items using arrow keys', () => {
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.ENTER);
|
|
|
|
|
page.pressKey(Key.DOWN);
|
|
|
|
|
page.pressKey(Key.DOWN);
|
2016-09-01 11:56:08 -07:00
|
|
|
page.expectFocusOn(page.items(3));
|
|
|
|
|
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.UP);
|
2016-09-01 11:56:08 -07:00
|
|
|
page.expectFocusOn(page.items(1));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should close the menu when tabbing past items', () => {
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.ENTER);
|
|
|
|
|
page.pressKey(Key.TAB);
|
2016-09-01 11:56:08 -07:00
|
|
|
page.expectMenuPresent(false);
|
|
|
|
|
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.TAB);
|
|
|
|
|
page.pressKey(Key.ENTER);
|
2016-11-03 15:55:34 -07:00
|
|
|
page.expectMenuPresent(true);
|
|
|
|
|
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(protractor.Key.chord(Key.SHIFT, Key.TAB));
|
2016-09-01 11:56:08 -07:00
|
|
|
page.expectMenuPresent(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should wrap back to menu when arrow keying past items', () => {
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.ENTER);
|
|
|
|
|
page.pressKey(Key.DOWN);
|
|
|
|
|
page.pressKey(Key.DOWN);
|
|
|
|
|
page.pressKey(Key.DOWN);
|
2016-09-01 11:56:08 -07:00
|
|
|
page.expectFocusOn(page.items(0));
|
|
|
|
|
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.UP);
|
2016-09-01 11:56:08 -07:00
|
|
|
page.expectFocusOn(page.items(3));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should focus before and after trigger when tabbing past items', () => {
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.ENTER);
|
|
|
|
|
page.pressKey(Key.TAB);
|
2016-09-01 11:56:08 -07:00
|
|
|
page.expectFocusOn(page.triggerTwo());
|
|
|
|
|
|
|
|
|
|
// navigate back to trigger
|
|
|
|
|
page.pressKey(protractor.Key.chord(protractor.Key.SHIFT, protractor.Key.TAB));
|
2016-12-19 20:17:23 +02:00
|
|
|
page.pressKey(Key.ENTER);
|
2016-09-01 11:56:08 -07:00
|
|
|
|
|
|
|
|
page.pressKey(protractor.Key.chord(protractor.Key.SHIFT, protractor.Key.TAB));
|
|
|
|
|
page.expectFocusOn(page.start());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
describe('position - ', () => {
|
2016-07-21 15:45:53 -07:00
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
it('should default menu alignment to "after below" when not set', () => {
|
|
|
|
|
page.trigger().click();
|
2016-07-21 15:45:53 -07:00
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
// menu.x should equal trigger.x, menu.y should equal trigger.y
|
|
|
|
|
page.expectMenuAlignedWith(page.menu(), 'trigger');
|
|
|
|
|
});
|
2016-07-21 15:45:53 -07:00
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
it('should align overlay end to origin end when x-position is "before"', () => {
|
|
|
|
|
page.beforeTrigger().click();
|
2016-12-06 07:46:15 +01:00
|
|
|
page.beforeTrigger().getLocation().then(trigger => {
|
2016-07-21 15:45:53 -07:00
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
// the menu's right corner must be attached to the trigger's right corner.
|
|
|
|
|
// menu = 112px wide. trigger = 60px wide. 112 - 60 = 52px of menu to the left of trigger.
|
|
|
|
|
// trigger.x (left corner) - 52px (menu left of trigger) = expected menu.x (left corner)
|
|
|
|
|
// menu.y should equal trigger.y because only x position has changed.
|
|
|
|
|
page.expectMenuLocation(page.beforeMenu(), {x: trigger.x - 52, y: trigger.y});
|
|
|
|
|
});
|
2016-07-21 15:45:53 -07:00
|
|
|
});
|
|
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
it('should align overlay bottom to origin bottom when y-position is "above"', () => {
|
|
|
|
|
page.aboveTrigger().click();
|
2016-12-06 07:46:15 +01:00
|
|
|
page.aboveTrigger().getLocation().then(trigger => {
|
2016-07-22 13:27:17 -07:00
|
|
|
|
|
|
|
|
// the menu's bottom corner must be attached to the trigger's bottom corner.
|
|
|
|
|
// menu.x should equal trigger.x because only y position has changed.
|
|
|
|
|
// menu = 64px high. trigger = 20px high. 64 - 20 = 44px of menu extending up past trigger.
|
|
|
|
|
// trigger.y (top corner) - 44px (menu above trigger) = expected menu.y (top corner)
|
|
|
|
|
page.expectMenuLocation(page.aboveMenu(), {x: trigger.x, y: trigger.y - 44});
|
|
|
|
|
});
|
2016-07-21 15:45:53 -07:00
|
|
|
});
|
|
|
|
|
|
2016-07-22 13:27:17 -07:00
|
|
|
it('should align menu to top left of trigger when "below" and "above"', () => {
|
|
|
|
|
page.combinedTrigger().click();
|
2016-12-06 07:46:15 +01:00
|
|
|
page.combinedTrigger().getLocation().then(trigger => {
|
2016-07-22 13:27:17 -07:00
|
|
|
|
|
|
|
|
// trigger.x (left corner) - 52px (menu left of trigger) = expected menu.x
|
|
|
|
|
// trigger.y (top corner) - 44px (menu above trigger) = expected menu.y
|
|
|
|
|
page.expectMenuLocation(page.combinedMenu(), {x: trigger.x - 52, y: trigger.y - 44});
|
|
|
|
|
});
|
2016-07-21 15:45:53 -07:00
|
|
|
});
|
2016-07-22 13:27:17 -07:00
|
|
|
|
|
|
|
|
});
|
2016-07-21 15:45:53 -07:00
|
|
|
});
|