|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Akveo. All Rights Reserved. |
| 4 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 5 | + */ |
| 6 | + |
| 7 | +import { browser, element, by } from 'protractor'; |
| 8 | + |
| 9 | +import { hasClass } from './e2e-helper'; |
| 10 | + |
| 11 | +describe('accordion', () => { |
| 12 | + beforeEach(done => { |
| 13 | + browser.get('#/accordion/accordion-test.component').then(() => done()); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should display the 4 accordion items', () => { |
| 17 | + expect(element.all(by.css('nb-accordion > nb-accordion-item')).count()).toEqual(4); |
| 18 | + |
| 19 | + expect( |
| 20 | + element( |
| 21 | + by.css('nb-accordion > nb-accordion-item:nth-child(1) > nb-accordion-item-header'), |
| 22 | + ).getText(), |
| 23 | + ).toEqual('Accordion #1', 'fist item title'); |
| 24 | + |
| 25 | + expect( |
| 26 | + element( |
| 27 | + by.css('nb-accordion > nb-accordion-item:nth-child(2) > nb-accordion-item-header'), |
| 28 | + ).getText(), |
| 29 | + ).toEqual('Accordion #2', 'second item title'); |
| 30 | + |
| 31 | + expect( |
| 32 | + hasClass(element(by.css('nb-accordion > nb-accordion-item:nth-child(2)')), 'collapsed'), |
| 33 | + ).toBeTruthy('second is collapsed'); |
| 34 | + |
| 35 | + expect( |
| 36 | + element( |
| 37 | + by.css('nb-accordion > nb-accordion-item:nth-child(3) > nb-accordion-item-header'), |
| 38 | + ).getText(), |
| 39 | + ).toEqual('Accordion #3', 'third item title'); |
| 40 | + |
| 41 | + expect( |
| 42 | + hasClass(element(by.css('nb-accordion > nb-accordion-item:nth-child(3)')), 'expanded'), |
| 43 | + ).toBeTruthy('second is expanded'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should expand a first accordion-item', () => { |
| 47 | + element(by.css('nb-accordion > nb-accordion-item:nth-child(1)')).click(); |
| 48 | + |
| 49 | + expect( |
| 50 | + hasClass(element(by.css('nb-accordion > nb-accordion-item:nth-child(1)')), 'expanded'), |
| 51 | + ).toBeTruthy(); |
| 52 | + |
| 53 | + expect( |
| 54 | + hasClass(element(by.css('nb-accordion > nb-accordion-item:nth-child(3)')), 'collapsed'), |
| 55 | + ).toBeTruthy(); |
| 56 | + |
| 57 | + expect( |
| 58 | + element(by.css('nb-accordion > nb-accordion-item:nth-child(1) > nb-accordion-item-header')).getAttribute( |
| 59 | + 'aria-expanded', |
| 60 | + ), |
| 61 | + ).toEqual('true'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should display the tabbable accordion items', () => { |
| 65 | + expect( |
| 66 | + element(by.css('nb-accordion > nb-accordion-item:nth-child(1) > nb-accordion-item-header')).getAttribute( |
| 67 | + 'tabindex', |
| 68 | + ), |
| 69 | + ).toEqual('0'); |
| 70 | + |
| 71 | + expect( |
| 72 | + element(by.css('nb-accordion > nb-accordion-item:nth-child(2) > nb-accordion-item-header')).getAttribute( |
| 73 | + 'tabindex', |
| 74 | + ), |
| 75 | + ).toEqual('0'); |
| 76 | + |
| 77 | + expect( |
| 78 | + element(by.css('nb-accordion > nb-accordion-item:nth-child(4) > nb-accordion-item-header')).getAttribute( |
| 79 | + 'tabindex', |
| 80 | + ), |
| 81 | + ).toEqual('-1'); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should display a disabled accordion item', () => { |
| 85 | + expect( |
| 86 | + element(by.css('nb-accordion > nb-accordion-item:nth-child(4) > nb-accordion-item-header')).getAttribute( |
| 87 | + 'aria-disabled', |
| 88 | + ), |
| 89 | + ).toEqual('true'); |
| 90 | + |
| 91 | + expect( |
| 92 | + hasClass(element(by.css('nb-accordion > nb-accordion-item:nth-child(4)')), 'disabled'), |
| 93 | + ).toBeTruthy(); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should display a disabled accordion with collapsed state after click', () => { |
| 97 | + element(by.css('nb-accordion > nb-accordion-item:nth-child(4)')).click(); |
| 98 | + |
| 99 | + expect( |
| 100 | + hasClass(element(by.css('nb-accordion > nb-accordion-item:nth-child(4)')), 'collapsed'), |
| 101 | + ).toBeTruthy(); |
| 102 | + }); |
| 103 | +}); |
0 commit comments