|
| 1 | +describe('tab array', function () { |
| 2 | + it('form should exist', function () { |
| 3 | + browser.get('http://localhost:8080/examples/bootstrap-example.html'); |
| 4 | + |
| 5 | + element(by.css('#selectTest')).all(by.cssContainingText('option', 'Tab Array')).first().click().then(function() { |
| 6 | + expect(element(by.css('form.ng-valid-schema-form')).getInnerHtml()).not.toEqual(''); |
| 7 | + }); |
| 8 | + }); |
| 9 | + |
| 10 | + it('add link should be hidden', function () { |
| 11 | + browser.get('http://localhost:8080/examples/bootstrap-example.html'); |
| 12 | + |
| 13 | + /* select the add disabled example */ |
| 14 | + element(by.css('#selectTest')).element(by.cssContainingText('option', 'Tab Array: Add Disabled')).click().then(function() { |
| 15 | + |
| 16 | + /* Add link should not be displayed */ |
| 17 | + var tabs = element.all(by.css('.nav-tabs li')); |
| 18 | + expect(tabs.get(0).isDisplayed()).toBeTruthy(); |
| 19 | + expect(tabs.get(1).isDisplayed()).toBeFalsy(); |
| 20 | + |
| 21 | + var addLink = element.all(by.partialLinkText('Add')); |
| 22 | + expect(addLink.count()).toBe(0); |
| 23 | + |
| 24 | + /*** control tests ***/ |
| 25 | + /* Remove button should be displayed */ |
| 26 | + var removeButton = element.all(by.partialButtonText('Remove')).get(0); |
| 27 | + expect(removeButton.isDisplayed()).toBeTruthy(); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + it('remove button should be hidden', function () { |
| 32 | + browser.get('http://localhost:8080/examples/bootstrap-example.html'); |
| 33 | + |
| 34 | + /* select the remove disabled example */ |
| 35 | + element(by.css('#selectTest')).element(by.cssContainingText('option', 'Tab Array: Remove Disabled')).click().then(function() { |
| 36 | + |
| 37 | + /* Remove button should not be displayed */ |
| 38 | + var removeButton = element.all(by.partialButtonText('Remove')).get(0); |
| 39 | + expect(removeButton.isDisplayed()).toBeFalsy(); |
| 40 | + |
| 41 | + /*** control tests ***/ |
| 42 | + /* Add link should not be displayed */ |
| 43 | + var tabs = element.all(by.css('.nav-tabs li')); |
| 44 | + expect(tabs.get(0).isDisplayed()).toBeTruthy(); |
| 45 | + expect(tabs.get(1).isDisplayed()).toBeTruthy(); |
| 46 | + |
| 47 | + var addLink = element.all(by.partialLinkText('Add')); |
| 48 | + expect(addLink.count()).toBe(1); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should be able order elements in array by dragging the tabs', function () { |
| 53 | + browser.get('http://localhost:8080/examples/bootstrap-example.html'); |
| 54 | + |
| 55 | + function checkDragDrop(i) { |
| 56 | + browser.driver.wait(protractor.until.elementLocated(by.xpath("//ol/li[1]/a[text()='My name is: Name " + (i + 1) +"']")), 10000); |
| 57 | + expect(element.all(by.css('.nav-tabs li a')).get(0).getText()).toBe('My name is: Name ' + (i + 1)); |
| 58 | + } |
| 59 | + |
| 60 | + function populateTab(i) { |
| 61 | + browser.driver.wait(protractor.until.elementLocated(by.css('.tab-pane.active.index' + i)), 5000); |
| 62 | + |
| 63 | + browser.driver.wait(protractor.until.elementLocated(by.css('.tab-pane.index' + i + ' div.nickField > input')), 5000); |
| 64 | + input = element.all(by.css('.tab-pane.index' + i + ' div.nickField > input')).first(); |
| 65 | + input.sendKeys('Nickname ' + i); |
| 66 | + |
| 67 | + browser.driver.wait(protractor.until.elementLocated(by.css('.tab-pane.index' + i + ' div.nameField > input')), 5000); |
| 68 | + input = element.all(by.css('.tab-pane.index' + i + ' div.nameField > input')).first(); |
| 69 | + input.sendKeys('Name ' + i); |
| 70 | + |
| 71 | + browser.driver.wait(protractor.until.elementLocated(by.linkText('My name is: Name ' + i)), 10000); |
| 72 | + } |
| 73 | + |
| 74 | + /* select the sortable example */ |
| 75 | + element(by.css('#selectTest')).element(by.cssContainingText('option', 'Tab Array: Sortable')).click().then(function() { |
| 76 | + |
| 77 | + var i; |
| 78 | + var elementsToAdd = 9; |
| 79 | + |
| 80 | + /* the array starts with 1 element, populate the first element */ |
| 81 | + populateTab(0); |
| 82 | + |
| 83 | + /* add elements and populate */ |
| 84 | + for (i = 1; i <= elementsToAdd; i++) { |
| 85 | + var tabLink = element.all(by.css('.glyphicon-plus')); |
| 86 | + tabLink.click().then(populateTab(i)); |
| 87 | + } |
| 88 | + |
| 89 | + /* continue when all tabs have been populated*/ |
| 90 | + browser.driver.wait(protractor.until.elementLocated(by.linkText('My name is: Name ' + elementsToAdd)), 10000); |
| 91 | + |
| 92 | + /* check the number of tabs */ |
| 93 | + var tabs = element.all(by.css('.nav-tabs li')); |
| 94 | + expect(tabs.count()).toBe(elementsToAdd + 2); //Extra 1 for the "+ Add" link |
| 95 | + |
| 96 | + /* drag the tabs into reverse order (descending) */ |
| 97 | + for (i = 0; i < elementsToAdd; i++) { |
| 98 | + var draggable_element = element.all(by.css('.nav-tabs li')).get(0); |
| 99 | + var target_element = element.all(by.css('.nav-tabs li')).get(elementsToAdd - i); |
| 100 | + expect(draggable_element.isPresent()).toEqual(true); |
| 101 | + expect(target_element.isPresent()).toEqual(true); |
| 102 | + browser.actions().dragAndDrop(draggable_element, target_element).perform().then(checkDragDrop(i)); |
| 103 | + } |
| 104 | + |
| 105 | + /* final check of the reverse ordered tabs */ |
| 106 | + for (i = 0; i <= elementsToAdd; i++) { |
| 107 | + expect(element.all(by.css('.nav-tabs li a')).get(i).getText()).toBe('My name is: Name ' + (elementsToAdd - i)); |
| 108 | + } |
| 109 | + }); |
| 110 | + }); |
| 111 | +}); |
0 commit comments