|
| 1 | +import {verifyNoBrowserErrors} from 'angular2/src/test_lib/e2e_util'; |
| 2 | + |
| 3 | +function waitForElement(selector) { |
| 4 | + var EC = (<any>protractor).ExpectedConditions; |
| 5 | + // Waits for the element with id 'abc' to be present on the dom. |
| 6 | + browser.wait(EC.presenceOf($(selector)), 10000); |
| 7 | +} |
| 8 | + |
| 9 | +describe('routing inbox-app', function() { |
| 10 | + |
| 11 | + afterEach(verifyNoBrowserErrors); |
| 12 | + |
| 13 | + describe('index view', function() { |
| 14 | + var URL = 'examples/src/routing/'; |
| 15 | + |
| 16 | + it('should list out the current collection of items', function() { |
| 17 | + browser.get(URL); |
| 18 | + waitForElement('.inbox-item-record'); |
| 19 | + expect(element.all(by.css('.inbox-item-record')).count()).toEqual(200); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should build a link which points to the detail page', function() { |
| 23 | + browser.get(URL); |
| 24 | + waitForElement('#item-15'); |
| 25 | + expect(element(by.css('#item-15')).getAttribute('href')).toMatch(/\/detail\/15$/); |
| 26 | + element(by.css('#item-15')).click(); |
| 27 | + waitForElement('#record-id'); |
| 28 | + expect(browser.getCurrentUrl()).toMatch(/\/detail\/15$/); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + |
| 33 | + describe('drafts view', function() { |
| 34 | + var URL = 'examples/src/routing/#/drafts'; |
| 35 | + |
| 36 | + it('should navigate to the drafts view when the drafts link is clicked', function() { |
| 37 | + browser.get(URL); |
| 38 | + waitForElement('.inbox-item-record'); |
| 39 | + element(by.linkText('Drafts')).click(); |
| 40 | + waitForElement('.page-title'); |
| 41 | + expect(element(by.css('.page-title')).getText()).toEqual('Drafts'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should navigate to email details', function() { |
| 45 | + browser.get(URL); |
| 46 | + element(by.linkText('Drafts')).click(); |
| 47 | + waitForElement('.inbox-item-record'); |
| 48 | + expect(element.all(by.css('.inbox-item-record')).count()).toEqual(2); |
| 49 | + expect(element(by.css('#item-201')).getAttribute('href')).toMatch(/\/detail\/201$/); |
| 50 | + element(by.css('#item-201')).click(); |
| 51 | + waitForElement('#record-id'); |
| 52 | + expect(browser.getCurrentUrl()).toMatch(/\/detail\/201$/); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + |
| 57 | + describe('detail view', function() { |
| 58 | + var URL = 'examples/src/routing/'; |
| 59 | + |
| 60 | + it('should navigate to the detail view when an email is clicked', function() { |
| 61 | + browser.get(URL); |
| 62 | + waitForElement('#item-10'); |
| 63 | + element(by.css('#item-10')).click(); |
| 64 | + waitForElement('#record-id'); |
| 65 | + expect(element(by.css('#record-id')).getText()).toEqual('ID: 10'); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should navigate back to the email inbox page when the back button is clicked', function() { |
| 69 | + browser.get(URL); |
| 70 | + waitForElement('#item-10'); |
| 71 | + element(by.css('#item-10')).click(); |
| 72 | + waitForElement('.back-button'); |
| 73 | + element(by.css('.back-button')).click(); |
| 74 | + expect(browser.getCurrentUrl()).toMatch('/#'); |
| 75 | + }); |
| 76 | + }) |
| 77 | +}); |
0 commit comments