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