Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix steps component unit tests #15553

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/app/components/steps/steps.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Steps, StepsModule } from './steps';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Component, NO_ERRORS_SCHEMA, ViewEncapsulation } from '@angular/core';
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
import { Toast } from 'primeng/toast';
import { RouterTestingModule } from '@angular/router/testing';
import { MenuItem } from 'primeng/api';

@Component({
template: `<p-steps [model]="items"></p-steps> `
})
class TestStpesComponent {
class TestStepsComponent {
items: MenuItem[];

activeIndex: number = 1;
Expand Down Expand Up @@ -49,17 +49,17 @@ class TestStpesComponent {

describe('Steps', () => {
let steps: Steps;
let testComponent: TestStpesComponent;
let fixture: ComponentFixture<TestStpesComponent>;
let testComponent: TestStepsComponent;
let fixture: ComponentFixture<TestStepsComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
schemas: [NO_ERRORS_SCHEMA],
imports: [NoopAnimationsModule, RouterTestingModule, StepsModule],
declarations: [Toast, TestStpesComponent]
declarations: [Toast, TestStepsComponent]
});

fixture = TestBed.createComponent(TestStpesComponent);
fixture = TestBed.createComponent(TestStepsComponent);
steps = fixture.debugElement.children[0].componentInstance;
testComponent = fixture.debugElement.componentInstance;
});
Expand All @@ -69,7 +69,7 @@ describe('Steps', () => {
steps.styleClass = 'Primeng ROCKS!';
fixture.detectChanges();

const stepsEl = fixture.debugElement.children[0].query(By.css('div')).nativeElement;
const stepsEl = fixture.debugElement.children[0].query(By.css('nav')).nativeElement;
expect(stepsEl.className).toContain('Primeng ROCKS!');
expect(stepsEl.style.height).toContain('300px');
});
Expand All @@ -89,7 +89,7 @@ describe('Steps', () => {
steps.readonly = false;
fixture.detectChanges();

const stepsEl = fixture.debugElement.children[0].query(By.css('div')).nativeElement;
const stepsEl = fixture.debugElement.children[0].query(By.css('nav')).nativeElement;
const items = fixture.debugElement.children[0].queryAll(By.css('li'));
expect(stepsEl.className).not.toContain('p-steps-readonly');
for (let x = 0; x < testComponent.items.length; x++) {
Expand All @@ -100,7 +100,6 @@ describe('Steps', () => {
it('should show the step number', () => {
fixture.detectChanges();

const stepsEl = fixture.debugElement.children[0].query(By.css('div')).nativeElement;
const items = fixture.debugElement.children[0].queryAll(By.css('li'));
for (let x = 0; x < testComponent.items.length; x++) {
expect(items[x].query(By.css('.p-steps-number')).nativeElement.textContent).toEqual((x + 1).toString());
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/steps/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { Subscription } from 'rxjs';
[skipLocationChange]="item.skipLocationChange"
[replaceUrl]="item.replaceUrl"
[state]="item.state"
[ariaCurrentWhenActive]="exact ? 'step' : undefined"
[attr.ariaCurrentWhenActive]="exact ? 'step' : undefined"
>
<span class="p-steps-number">{{ i + 1 }}</span>
<span class="p-steps-title" *ngIf="item.escape !== false; else htmlLabel">{{ item.label }}</span>
Expand All @@ -65,7 +65,7 @@ import { Subscription } from 'rxjs';
[attr.tabindex]="getItemTabIndex(item, i)"
[attr.aria-expanded]="i === activeIndex"
[attr.aria-disabled]="item.disabled || (readonly && i !== activeIndex)"
[ariaCurrentWhenActive]="exact && (!item.disabled || readonly) ? 'step' : undefined"
[attr.ariaCurrentWhenActive]="exact && (!item.disabled || readonly) ? 'step' : undefined"
>
<span class="p-steps-number">{{ i + 1 }}</span>
<span class="p-steps-title" *ngIf="item.escape !== false; else htmlRouteLabel">{{ item.label }}</span>
Expand Down
Loading