2017-02-22 13:13:21 -05:00
|
|
|
import { browser, element, by } from 'protractor';
|
|
|
|
|
|
|
|
// Angular E2E Testing Guide:
|
|
|
|
// https://docs.angularjs.org/guide/e2e-testing
|
|
|
|
|
2020-07-30 06:03:13 -04:00
|
|
|
describe('PhoneCat Application', () => {
|
2017-02-22 13:13:21 -05:00
|
|
|
|
|
|
|
// #docregion redirect
|
2020-11-23 13:17:10 -05:00
|
|
|
it('should redirect `index.html` to `index.html#!/phones', async () => {
|
|
|
|
await browser.get('index.html');
|
|
|
|
await browser.waitForAngular();
|
|
|
|
const url = await browser.getCurrentUrl();
|
|
|
|
expect(url.endsWith('/phones')).toBe(true);
|
2017-02-22 13:13:21 -05:00
|
|
|
});
|
|
|
|
// #enddocregion redirect
|
|
|
|
|
2020-07-30 06:03:13 -04:00
|
|
|
describe('View: Phone list', () => {
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
beforeEach(() => browser.get('index.html#!/phones'));
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
it('should filter the phone list as a user types into the search box', async () => {
|
2020-07-30 06:03:19 -04:00
|
|
|
const phoneList = element.all(by.css('.phones li'));
|
|
|
|
const query = element(by.css('input'));
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
expect(await phoneList.count()).toBe(20);
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
await query.sendKeys('nexus');
|
|
|
|
expect(await phoneList.count()).toBe(1);
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
await query.clear();
|
|
|
|
await query.sendKeys('motorola');
|
|
|
|
expect(await phoneList.count()).toBe(8);
|
2017-02-22 13:13:21 -05:00
|
|
|
});
|
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
it('should be possible to control phone order via the drop-down menu', async () => {
|
2020-07-30 06:03:19 -04:00
|
|
|
const queryField = element(by.css('input'));
|
|
|
|
const orderSelect = element(by.css('select'));
|
|
|
|
const nameOption = orderSelect.element(by.css('option[value="name"]'));
|
|
|
|
const phoneNameColumn = element.all(by.css('.phones .name'));
|
2017-02-22 13:13:21 -05:00
|
|
|
|
|
|
|
function getNames() {
|
2020-07-30 06:03:13 -04:00
|
|
|
return phoneNameColumn.map((elem) => elem.getText());
|
2017-02-22 13:13:21 -05:00
|
|
|
}
|
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
await queryField.sendKeys('tablet'); // Let's narrow the dataset to make the assertions shorter
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
expect(await getNames()).toEqual([
|
2017-02-22 13:13:21 -05:00
|
|
|
'Motorola XOOM\u2122 with Wi-Fi',
|
|
|
|
'MOTOROLA XOOM\u2122'
|
|
|
|
]);
|
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
await nameOption.click();
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
expect(await getNames()).toEqual([
|
2017-02-22 13:13:21 -05:00
|
|
|
'MOTOROLA XOOM\u2122',
|
|
|
|
'Motorola XOOM\u2122 with Wi-Fi'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
// #docregion links
|
2020-11-23 13:17:10 -05:00
|
|
|
it('should render phone specific links', async () => {
|
2020-07-30 06:03:19 -04:00
|
|
|
const query = element(by.css('input'));
|
2020-11-23 13:17:10 -05:00
|
|
|
await query.sendKeys('nexus');
|
|
|
|
await element.all(by.css('.phones li a')).first().click();
|
|
|
|
const url = await browser.getCurrentUrl();
|
|
|
|
expect(url.endsWith('/phones/nexus-s')).toBe(true);
|
2017-02-22 13:13:21 -05:00
|
|
|
});
|
|
|
|
// #enddocregion links
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2020-07-30 06:03:13 -04:00
|
|
|
describe('View: Phone detail', () => {
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
beforeEach(() => browser.get('index.html#!/phones/nexus-s'));
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
it('should display the `nexus-s` page', async () => {
|
|
|
|
expect(await element(by.css('h1')).getText()).toBe('Nexus S');
|
2017-02-22 13:13:21 -05:00
|
|
|
});
|
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
it('should display the first phone image as the main phone image', async () => {
|
2020-07-30 06:03:19 -04:00
|
|
|
const mainImage = element(by.css('img.phone.selected'));
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
expect(await mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
|
2017-02-22 13:13:21 -05:00
|
|
|
});
|
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
it('should swap the main image when clicking on a thumbnail image', async () => {
|
2020-07-30 06:03:19 -04:00
|
|
|
const mainImage = element(by.css('img.phone.selected'));
|
|
|
|
const thumbnails = element.all(by.css('.phone-thumbs img'));
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
await thumbnails.get(2).click();
|
|
|
|
expect(await mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.2.jpg/);
|
2017-02-22 13:13:21 -05:00
|
|
|
|
2020-11-23 13:17:10 -05:00
|
|
|
await thumbnails.get(0).click();
|
|
|
|
expect(await mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
|
2017-02-22 13:13:21 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|