|
1 |
| -import { TestBed, ComponentFixture } from '@angular/core/testing'; |
| 1 | +import { TestBed, ComponentFixture, async } from '@angular/core/testing'; |
2 | 2 | import { By } from '@angular/platform-browser';
|
3 | 3 | import { Accordion } from './accordion';
|
| 4 | +import { AccordionTab } from './accordion' |
4 | 5 | import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
| 6 | +import { Component, DebugElement, NO_ERRORS_SCHEMA } from '../../../../node_modules/@angular/core'; |
| 7 | + |
| 8 | +@Component({ |
| 9 | + template: `<p-accordion> |
| 10 | + <p-accordionTab header="Godfather I" > |
| 11 | + The story begins as Don Vito Corleone, the head of a New York Mafia family, overseeshis daughter's wedding. His beloved son ichael has just come home from the war, but does not intend to become part of his father's business. T hrough Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family. |
| 12 | + </p-accordionTab> |
| 13 | + <p-accordionTab header="Godfather II" > |
| 14 | + The story begins as Don Vito Corleone, the head of a New York Mafia family, overseeshis daughter's wedding. His beloved son ichael has just come home from the war, but does not intend to become part of his father's business. T hrough Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family. |
| 15 | + </p-accordionTab> |
| 16 | +</p-accordion>` |
| 17 | +}) |
| 18 | +class TestAccordionComponent { |
| 19 | +} |
| 20 | + |
5 | 21 |
|
6 | 22 | describe('Accordion', () => {
|
7 |
| - |
| 23 | + |
8 | 24 | let accordion: Accordion;
|
9 |
| - let fixture: ComponentFixture<Accordion>; |
10 |
| - |
11 |
| - beforeEach(() => { |
| 25 | + let firstAccordionTab: AccordionTab; |
| 26 | + let secondAccordionTab: AccordionTab; |
| 27 | + let fixture: ComponentFixture<TestAccordionComponent>; |
| 28 | + |
| 29 | + beforeEach(async(() => { |
12 | 30 | TestBed.configureTestingModule({
|
| 31 | + schemas: [NO_ERRORS_SCHEMA], |
13 | 32 | imports: [
|
14 | 33 | NoopAnimationsModule
|
15 | 34 | ],
|
16 | 35 | declarations: [
|
17 |
| - Accordion |
18 |
| - ] |
19 |
| - }); |
20 |
| - |
21 |
| - fixture = TestBed.createComponent(Accordion); |
22 |
| - accordion = fixture.componentInstance; |
| 36 | + Accordion, |
| 37 | + AccordionTab, |
| 38 | + TestAccordionComponent |
| 39 | + ], |
| 40 | + }) |
| 41 | + })); |
| 42 | + beforeEach(() => { |
| 43 | + fixture = TestBed.createComponent(TestAccordionComponent); |
| 44 | + accordion = fixture.debugElement.children[0].componentInstance; |
| 45 | + firstAccordionTab = fixture.debugElement.children[0].children[0].children[0].componentInstance; |
| 46 | + secondAccordionTab = fixture.debugElement.children[0].children[0].children[1].componentInstance; |
| 47 | + fixture.detectChanges(); |
| 48 | + }) |
| 49 | + |
| 50 | + it('should have a two accordionTab', () => { |
| 51 | + fixture.detectChanges(); |
| 52 | + |
| 53 | + expect(accordion.tabs.length).toBe(2) |
23 | 54 | });
|
| 55 | + |
| 56 | + it('should be change header', () => { |
| 57 | + firstAccordionTab.header = "Primeng ROCKS"; |
| 58 | + fixture.detectChanges(); |
| 59 | + |
| 60 | + const accordionTabHeaderEl = fixture.debugElement.children[0].children[0].children[0].query(By.css('.ui-accordion-header-text')); |
| 61 | + expect(accordionTabHeaderEl.nativeElement.textContent).toContain("Primeng ROCKS") |
| 62 | + }); |
| 63 | + |
| 64 | + it('should have selected first accordionTab and second accordionTab should be unselected', () => { |
| 65 | + firstAccordionTab.selected = true; |
| 66 | + fixture.detectChanges(); |
| 67 | + |
| 68 | + const firstAccordionTabHeaderEl = fixture.debugElement.children[0].children[0].children[0].query(By.css('.ui-accordion-header')).nativeElement; |
| 69 | + const secondAccordionTabHeaderEl = fixture.debugElement.children[0].children[0].children[1].query(By.css('.ui-accordion-header')).nativeElement; |
| 70 | + expect(firstAccordionTabHeaderEl.className).toContain('ui-state-active'); |
| 71 | + expect(secondAccordionTabHeaderEl.className).not.toContain('ui-state-active'); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should have a multiple select and all accordionTabs should be selected', () => { |
| 75 | + accordion.multiple = true; |
| 76 | + fixture.detectChanges(); |
| 77 | + |
| 78 | + const firstAccordionTabOpenEl = fixture.debugElement.children[0].children[0].children[0].query(By.css('a')).nativeElement; |
| 79 | + const secondAccordionTabOpenEl = fixture.debugElement.children[0].children[0].children[1].query(By.css('a')).nativeElement; |
| 80 | + secondAccordionTabOpenEl.click(); |
| 81 | + firstAccordionTabOpenEl.click(); |
| 82 | + fixture.detectChanges(); |
| 83 | + |
| 84 | + const firstAccordionTabHeaderEl = fixture.debugElement.children[0].children[0].children[0].query(By.css('.ui-accordion-header')).nativeElement; |
| 85 | + const secondAccordionTabHeaderEl = fixture.debugElement.children[0].children[0].children[1].query(By.css('.ui-accordion-header')).nativeElement; |
| 86 | + expect(firstAccordionTabHeaderEl.className).toContain('ui-state-active'); |
| 87 | + expect(secondAccordionTabHeaderEl.className).toContain('ui-state-active'); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should be disabled', () => { |
| 91 | + firstAccordionTab.disabled = true; |
| 92 | + fixture.detectChanges(); |
| 93 | + |
| 94 | + const firstAccordionTabOpenEl = fixture.debugElement.children[0].children[0].children[0].query(By.css('a')).nativeElement; |
| 95 | + const accordionTabHeaderEl = fixture.debugElement.children[0].children[0].children[0].query(By.css('.ui-accordion-header')).nativeElement; |
| 96 | + firstAccordionTabOpenEl.click(); |
| 97 | + expect(accordionTabHeaderEl.className).toContain('ui-state-disabled'); |
| 98 | + expect(accordionTabHeaderEl.className).not.toContain("ui-state-active") |
| 99 | + }); |
| 100 | + |
| 101 | + it('should be change expandIcon and collapseIcon', () => { |
| 102 | + accordion.collapseIcon = "pi pi-fw pi-caret-left"; |
| 103 | + accordion.expandIcon = "pi pi-fw pi-caret-up"; |
| 104 | + fixture.detectChanges(); |
| 105 | + |
| 106 | + const firstAccordionTabOpenEl = fixture.debugElement.children[0].children[0].children[0].query(By.css('.ui-accordion-toggle-icon')).nativeElement; |
| 107 | + expect(firstAccordionTabOpenEl.className).toContain('pi pi-fw pi-caret-up'); |
| 108 | + firstAccordionTab.selected = true; |
| 109 | + fixture.detectChanges(); |
| 110 | + |
| 111 | + expect(firstAccordionTabOpenEl.className).toContain('pi pi-fw pi-caret-left'); |
| 112 | + }); |
| 113 | + |
| 114 | + it('should be get styleClass', () => { |
| 115 | + accordion.styleClass = "alwaysbetonprime" |
| 116 | + fixture.detectChanges(); |
| 117 | + |
| 118 | + const accordionEl = fixture.debugElement.children[0].query(By.css('.ui-accordion')).nativeElement; |
| 119 | + expect(accordionEl.className).toContain('alwaysbetonprime'); |
| 120 | + }); |
| 121 | + |
| 122 | + it('should be get style', () => { |
| 123 | + accordion.style = { "prime": 'Rocks' } |
| 124 | + fixture.detectChanges(); |
| 125 | + |
| 126 | + const accordionEl = fixture.debugElement.children[0].query(By.css('.ui-accordion')).nativeElement; |
| 127 | + expect(accordionEl.style.prime).toContain('Rocks'); |
| 128 | + }); |
| 129 | + |
24 | 130 | });
|
0 commit comments