|
| 1 | +/// <reference path='../_protractor/e2e.d.ts' /> |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const heroes = [ |
| 5 | + {'id': 11, 'name': 'Mr. Nice'}, |
| 6 | + {'id': 12, 'name': 'Narco'}, |
| 7 | + {'id': 13, 'name': 'Bombasto'}, |
| 8 | + {'id': 14, 'name': 'Celeritas'}, |
| 9 | + {'id': 15, 'name': 'Magneta'}, |
| 10 | + {'id': 16, 'name': 'RubberMan'}, |
| 11 | + {'id': 17, 'name': 'Dynama'}, |
| 12 | + {'id': 18, 'name': 'Dr IQ'}, |
| 13 | + {'id': 19, 'name': 'Magma'}, |
| 14 | + {'id': 20, 'name': 'Tornado'} |
| 15 | +]; |
| 16 | + |
| 17 | +describe('Select box component', function () { |
| 18 | + |
| 19 | + beforeAll(function () { |
| 20 | + browser.get(''); |
| 21 | + }); |
| 22 | + |
| 23 | + describe('Verbose select', function () { |
| 24 | + let verboseComponent: protractor.ElementFinder; |
| 25 | + let firstSelect: protractor.ElementFinder; |
| 26 | + |
| 27 | + beforeEach(function () { |
| 28 | + verboseComponent = element.all(by.tagName('my-select-verbose')).get(0); |
| 29 | + firstSelect = verboseComponent.all(by.tagName('select')).get(0); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should show a selected hero both in the select and outside it', function () { |
| 33 | + firstSelect.getAttribute('value').then(function (hero: any) { |
| 34 | + expect(heroes[hero].name).toEqual('Narco'); |
| 35 | + }); |
| 36 | + |
| 37 | + const heroOnPTag = verboseComponent.all(by.tagName('p')).last().getText(); |
| 38 | + expect(heroOnPTag).toContain('Narco'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should change the selected hero on option change', function () { |
| 42 | + firstSelect.all(by.cssContainingText('option', 'Bombasto')).first().click(); |
| 43 | + |
| 44 | + firstSelect.getAttribute('value').then(function (hero: any) { |
| 45 | + expect(heroes[hero].name).toEqual('Bombasto'); |
| 46 | + }); |
| 47 | + |
| 48 | + const heroOnPTag = verboseComponent.all(by.tagName('p')).last().getText(); |
| 49 | + expect(heroOnPTag).toContain('Bombasto'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should change select collection on button clicks', function () { |
| 53 | + const reloadButton = verboseComponent.all(by.buttonText('Reload')); |
| 54 | + const clearButton = verboseComponent.all(by.buttonText('Clear')); |
| 55 | + const removeButton = verboseComponent.all(by.buttonText('Remove')); |
| 56 | + |
| 57 | + let options = firstSelect.all(by.tagName('option')); |
| 58 | + expect(options.count()).toBe(10); |
| 59 | + |
| 60 | + removeButton.click().then(function () { |
| 61 | + options = firstSelect.all(by.tagName('option')); |
| 62 | + expect(options.count()).toBe(9); |
| 63 | + |
| 64 | + clearButton.click().then(function () { |
| 65 | + options = firstSelect.all(by.tagName('option')); |
| 66 | + expect(options.count()).toBe(0); |
| 67 | + |
| 68 | + reloadButton.click().then(function () { |
| 69 | + options = firstSelect.all(by.tagName('option')); |
| 70 | + expect(options.count()).toBe(10); |
| 71 | + }); |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + describe('First selector', function () { |
| 78 | + let selectorComponent: protractor.ElementFinder; |
| 79 | + let firstSelector: protractor.ElementFinder; |
| 80 | + |
| 81 | + beforeEach(function () { |
| 82 | + selectorComponent = element.all(by.tagName('my-selector-host')).get(0); |
| 83 | + firstSelector = selectorComponent.all(by.tagName('select')).get(0); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should show a selected hero both in the select and outside it', function () { |
| 87 | + firstSelector.getAttribute('value').then(function (hero: any) { |
| 88 | + expect(heroes[hero].name).toEqual('Mr. Nice'); |
| 89 | + }); |
| 90 | + |
| 91 | + const firstSelectorOutput = selectorComponent.all(by.tagName('div')).get(0); |
| 92 | + const heroOnPTag = firstSelectorOutput.all(by.tagName('p')).last().getText(); |
| 93 | + expect(heroOnPTag).toContain('Mr. Nice'); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should change the selected hero on option change', function () { |
| 97 | + firstSelector.all(by.cssContainingText('option', 'Bombasto')).first().click(); |
| 98 | + |
| 99 | + firstSelector.getAttribute('value').then(function (hero: any) { |
| 100 | + expect(heroes[hero].name).toEqual('Bombasto'); |
| 101 | + }); |
| 102 | + |
| 103 | + const firstSelectorOutput = selectorComponent.all(by.tagName('div')).get(0); |
| 104 | + const heroOnPTag = firstSelectorOutput.all(by.tagName('p')).last().getText(); |
| 105 | + expect(heroOnPTag).toContain('Bombasto'); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should change select collection on button clicks', function () { |
| 109 | + const reloadButton = selectorComponent.all(by.buttonText('Reload')); |
| 110 | + const clearButton = selectorComponent.all(by.buttonText('Clear')); |
| 111 | + const removeButton = selectorComponent.all(by.buttonText('Remove')); |
| 112 | + |
| 113 | + let options = firstSelector.all(by.tagName('option')); |
| 114 | + expect(options.count()).toBe(10); |
| 115 | + |
| 116 | + removeButton.click().then(function () { |
| 117 | + options = firstSelector.all(by.tagName('option')); |
| 118 | + expect(options.count()).toBe(9); |
| 119 | + |
| 120 | + clearButton.click().then(function () { |
| 121 | + options = firstSelector.all(by.tagName('option')); |
| 122 | + expect(options.count()).toBe(0); |
| 123 | + |
| 124 | + reloadButton.click().then(function () { |
| 125 | + options = firstSelector.all(by.tagName('option')); |
| 126 | + expect(options.count()).toBe(10); |
| 127 | + }); |
| 128 | + }); |
| 129 | + }); |
| 130 | + }); |
| 131 | + }); |
| 132 | + |
| 133 | + describe('Second selector', function () { |
| 134 | + let selectorComponent: protractor.ElementFinder; |
| 135 | + let secondSelector: protractor.ElementFinder; |
| 136 | + |
| 137 | + beforeEach(function () { |
| 138 | + selectorComponent = element.all(by.tagName('my-selector-host')).get(0); |
| 139 | + secondSelector = selectorComponent.all(by.tagName('select')).get(1); |
| 140 | + }); |
| 141 | + |
| 142 | + it('should show a selected hero both in the select and outside it', function () { |
| 143 | + secondSelector.getAttribute('value').then(function (hero: any) { |
| 144 | + expect(heroes[hero].name).toEqual('Narco'); |
| 145 | + }); |
| 146 | + |
| 147 | + const secondSelectorOutput = selectorComponent.all(by.tagName('div')).get(1); |
| 148 | + const heroOnPTag = secondSelectorOutput.all(by.tagName('p')).last().getText(); |
| 149 | + expect(heroOnPTag).toContain('Narco'); |
| 150 | + }); |
| 151 | + |
| 152 | + it('should change the selected hero on option change', function () { |
| 153 | + secondSelector.all(by.cssContainingText('option', 'Bombasto')).first().click(); |
| 154 | + |
| 155 | + secondSelector.getAttribute('value').then(function (hero: any) { |
| 156 | + expect(heroes[hero].name).toEqual('Bombasto'); |
| 157 | + }); |
| 158 | + |
| 159 | + const secondSelectorOutput = selectorComponent.all(by.tagName('div')).get(1); |
| 160 | + const heroOnPTag = secondSelectorOutput.all(by.tagName('p')).last().getText(); |
| 161 | + expect(heroOnPTag).toContain('Bombasto'); |
| 162 | + }); |
| 163 | + }); |
| 164 | +}); |
0 commit comments