|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Angular E2E Testing Guide: |
| 4 | +// https://docs.angularjs.org/guide/e2e-testing |
| 5 | + |
| 6 | +describe('PhoneCat Application', function() { |
| 7 | + |
| 8 | + beforeAll(function() { |
| 9 | + browser.baseUrl = 'http://localhost:8080/app/'; |
| 10 | + setProtractorToNg1Mode(); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should redirect `index.html` to `index.html#!/phones', function() { |
| 14 | + browser.get('index.html'); |
| 15 | + expect(browser.getLocationAbsUrl()).toBe('/phones'); |
| 16 | + }); |
| 17 | + |
| 18 | + describe('View: Phone list', function() { |
| 19 | + |
| 20 | + beforeEach(function() { |
| 21 | + browser.get('index.html#!/phones'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should filter the phone list as a user types into the search box', function() { |
| 25 | + var phoneList = element.all(by.repeater('phone in $ctrl.phones')); |
| 26 | + var query = element(by.model('$ctrl.query')); |
| 27 | + |
| 28 | + expect(phoneList.count()).toBe(20); |
| 29 | + |
| 30 | + query.sendKeys('nexus'); |
| 31 | + expect(phoneList.count()).toBe(1); |
| 32 | + |
| 33 | + query.clear(); |
| 34 | + query.sendKeys('motorola'); |
| 35 | + expect(phoneList.count()).toBe(8); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should be possible to control phone order via the drop-down menu', function() { |
| 39 | + var queryField = element(by.model('$ctrl.query')); |
| 40 | + var orderSelect = element(by.model('$ctrl.orderProp')); |
| 41 | + var nameOption = orderSelect.element(by.css('option[value="name"]')); |
| 42 | + var phoneNameColumn = element.all(by.repeater('phone in $ctrl.phones').column('phone.name')); |
| 43 | + |
| 44 | + function getNames() { |
| 45 | + return phoneNameColumn.map(function(elem) { |
| 46 | + return elem.getText(); |
| 47 | + }); |
| 48 | + } |
| 49 | + |
| 50 | + queryField.sendKeys('tablet'); // Let's narrow the dataset to make the assertions shorter |
| 51 | + |
| 52 | + expect(getNames()).toEqual([ |
| 53 | + 'Motorola XOOM\u2122 with Wi-Fi', |
| 54 | + 'MOTOROLA XOOM\u2122' |
| 55 | + ]); |
| 56 | + |
| 57 | + nameOption.click(); |
| 58 | + |
| 59 | + expect(getNames()).toEqual([ |
| 60 | + 'MOTOROLA XOOM\u2122', |
| 61 | + 'Motorola XOOM\u2122 with Wi-Fi' |
| 62 | + ]); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should render phone specific links', function() { |
| 66 | + var query = element(by.model('$ctrl.query')); |
| 67 | + query.sendKeys('nexus'); |
| 68 | + |
| 69 | + element.all(by.css('.phones li a')).first().click(); |
| 70 | + expect(browser.getLocationAbsUrl()).toBe('/phones/nexus-s'); |
| 71 | + }); |
| 72 | + |
| 73 | + }); |
| 74 | + |
| 75 | + describe('View: Phone detail', function() { |
| 76 | + |
| 77 | + beforeEach(function() { |
| 78 | + browser.get('index.html#!/phones/nexus-s'); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should display the `nexus-s` page', function() { |
| 82 | + expect(element(by.binding('$ctrl.phone.name')).getText()).toBe('Nexus S'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should display the first phone image as the main phone image', function() { |
| 86 | + var mainImage = element(by.css('img.phone.selected')); |
| 87 | + |
| 88 | + expect(mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should swap the main image when clicking on a thumbnail image', function() { |
| 92 | + var mainImage = element(by.css('img.phone.selected')); |
| 93 | + var thumbnails = element.all(by.css('.phone-thumbs img')); |
| 94 | + |
| 95 | + thumbnails.get(2).click(); |
| 96 | + expect(mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.2.jpg/); |
| 97 | + |
| 98 | + thumbnails.get(0).click(); |
| 99 | + expect(mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/); |
| 100 | + }); |
| 101 | + |
| 102 | + }); |
| 103 | + |
| 104 | +}); |
0 commit comments