|
| 1 | +import { MenuPage } from './menu-page'; |
| 2 | + |
| 3 | +describe('menu', () => { |
| 4 | + let page: MenuPage; |
| 5 | + |
| 6 | + beforeEach(function() { |
| 7 | + page = new MenuPage(); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should open menu when the trigger is clicked', () => { |
| 11 | + page.expectMenuPresent(false); |
| 12 | + page.trigger().click(); |
| 13 | + |
| 14 | + page.expectMenuPresent(true); |
| 15 | + expect(page.menu().getText()).toEqual("One\nTwo\nThree"); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should close menu when area outside menu is clicked', () => { |
| 19 | + page.trigger().click(); |
| 20 | + page.body().click(); |
| 21 | + page.expectMenuPresent(false); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should close menu when menu item is clicked', () => { |
| 25 | + page.trigger().click(); |
| 26 | + page.items(0).click(); |
| 27 | + page.expectMenuPresent(false); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should run click handlers on regular menu items', () => { |
| 31 | + page.trigger().click(); |
| 32 | + page.items(0).click(); |
| 33 | + expect(page.getResultText()).toEqual('one'); |
| 34 | + |
| 35 | + page.trigger().click(); |
| 36 | + page.items(1).click(); |
| 37 | + expect(page.getResultText()).toEqual('two'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should run not run click handlers on disabled menu items', () => { |
| 41 | + page.trigger().click(); |
| 42 | + page.items(2).click(); |
| 43 | + expect(page.getResultText()).toEqual(''); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should support multiple triggers opening the same menu', () => { |
| 47 | + page.triggerTwo().click(); |
| 48 | + expect(page.menu().getText()).toEqual("One\nTwo\nThree"); |
| 49 | + page.expectMenuAlignedWith(page.menu(), 'trigger-two'); |
| 50 | + |
| 51 | + page.body().click(); |
| 52 | + page.expectMenuPresent(false); |
| 53 | + |
| 54 | + page.trigger().click(); |
| 55 | + expect(page.menu().getText()).toEqual("One\nTwo\nThree"); |
| 56 | + page.expectMenuAlignedWith(page.menu(), 'trigger'); |
| 57 | + |
| 58 | + page.body().click(); |
| 59 | + page.expectMenuPresent(false); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should mirror classes on host to menu template in overlay', () => { |
| 63 | + page.trigger().click(); |
| 64 | + page.menu().getAttribute('class').then((classes) => { |
| 65 | + expect(classes).toEqual('md-menu custom'); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + describe('position - ', () => { |
| 70 | + |
| 71 | + it('should default menu alignment to "after below" when not set', () => { |
| 72 | + page.trigger().click(); |
| 73 | + |
| 74 | + // menu.x should equal trigger.x, menu.y should equal trigger.y |
| 75 | + page.expectMenuAlignedWith(page.menu(), 'trigger'); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should align overlay end to origin end when x-position is "before"', () => { |
| 79 | + page.beforeTrigger().click(); |
| 80 | + page.beforeTrigger().getLocation().then((trigger) => { |
| 81 | + |
| 82 | + // the menu's right corner must be attached to the trigger's right corner. |
| 83 | + // menu = 112px wide. trigger = 60px wide. 112 - 60 = 52px of menu to the left of trigger. |
| 84 | + // trigger.x (left corner) - 52px (menu left of trigger) = expected menu.x (left corner) |
| 85 | + // menu.y should equal trigger.y because only x position has changed. |
| 86 | + page.expectMenuLocation(page.beforeMenu(), {x: trigger.x - 52, y: trigger.y}); |
| 87 | + }); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should align overlay bottom to origin bottom when y-position is "above"', () => { |
| 91 | + page.aboveTrigger().click(); |
| 92 | + page.aboveTrigger().getLocation().then((trigger) => { |
| 93 | + |
| 94 | + // the menu's bottom corner must be attached to the trigger's bottom corner. |
| 95 | + // menu.x should equal trigger.x because only y position has changed. |
| 96 | + // menu = 64px high. trigger = 20px high. 64 - 20 = 44px of menu extending up past trigger. |
| 97 | + // trigger.y (top corner) - 44px (menu above trigger) = expected menu.y (top corner) |
| 98 | + page.expectMenuLocation(page.aboveMenu(), {x: trigger.x, y: trigger.y - 44}); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should align menu to top left of trigger when "below" and "above"', () => { |
| 103 | + page.combinedTrigger().click(); |
| 104 | + page.combinedTrigger().getLocation().then((trigger) => { |
| 105 | + |
| 106 | + // trigger.x (left corner) - 52px (menu left of trigger) = expected menu.x |
| 107 | + // trigger.y (top corner) - 44px (menu above trigger) = expected menu.y |
| 108 | + page.expectMenuLocation(page.combinedMenu(), {x: trigger.x - 52, y: trigger.y - 44}); |
| 109 | + }); |
| 110 | + }); |
| 111 | + |
| 112 | + }); |
| 113 | +}); |
0 commit comments