badge.spec.ts (material2-7.3.3) | : | badge.spec.ts (material2-7.3.4) | ||
---|---|---|---|---|
skipping to change at line 14 | skipping to change at line 14 | |||
import {MatBadge, MatBadgeModule} from './index'; | import {MatBadge, MatBadgeModule} from './index'; | |||
import {ThemePalette} from '@angular/material/core'; | import {ThemePalette} from '@angular/material/core'; | |||
describe('MatBadge', () => { | describe('MatBadge', () => { | |||
let fixture: ComponentFixture<any>; | let fixture: ComponentFixture<any>; | |||
let testComponent: BadgeTestApp; | let testComponent: BadgeTestApp; | |||
let badgeNativeElement: HTMLElement; | let badgeNativeElement: HTMLElement; | |||
let badgeDebugElement: DebugElement; | let badgeDebugElement: DebugElement; | |||
beforeEach(fakeAsync(() => { | beforeEach(fakeAsync(() => { | |||
TestBed.configureTestingModule({ | TestBed | |||
imports: [MatBadgeModule], | .configureTestingModule({ | |||
declarations: [BadgeTestApp], | imports: [MatBadgeModule], | |||
}).compileComponents(); | declarations: [BadgeTestApp, PreExistingBadge, NestedBadge], | |||
}) | ||||
.compileComponents(); | ||||
fixture = TestBed.createComponent(BadgeTestApp); | fixture = TestBed.createComponent(BadgeTestApp); | |||
testComponent = fixture.debugElement.componentInstance; | testComponent = fixture.debugElement.componentInstance; | |||
fixture.detectChanges(); | fixture.detectChanges(); | |||
badgeDebugElement = fixture.debugElement.query(By.directive(MatBadge)); | badgeDebugElement = fixture.debugElement.query(By.directive(MatBadge)); | |||
badgeNativeElement = badgeDebugElement.nativeElement; | badgeNativeElement = badgeDebugElement.nativeElement; | |||
})); | })); | |||
it('should update the badge based on attribute', () => { | it('should update the badge based on attribute', () => { | |||
skipping to change at line 187 | skipping to change at line 189 | |||
fixture.detectChanges(); | fixture.detectChanges(); | |||
expect(badgeContent.getAttribute('aria-label')).toBe('changed content'); | expect(badgeContent.getAttribute('aria-label')).toBe('changed content'); | |||
fixture.componentInstance.badgeDescription = ''; | fixture.componentInstance.badgeDescription = ''; | |||
fixture.detectChanges(); | fixture.detectChanges(); | |||
expect(badgeContent.hasAttribute('aria-label')).toBe(false); | expect(badgeContent.hasAttribute('aria-label')).toBe(false); | |||
}); | }); | |||
it('should clear any pre-existing badges', () => { | ||||
const preExistingFixture = TestBed.createComponent(PreExistingBadge); | ||||
preExistingFixture.detectChanges(); | ||||
expect(preExistingFixture.nativeElement.querySelectorAll('.mat-badge-content | ||||
').length).toBe(1); | ||||
}); | ||||
it('should not clear badge content from child elements', () => { | ||||
const preExistingFixture = TestBed.createComponent(NestedBadge); | ||||
preExistingFixture.detectChanges(); | ||||
expect(preExistingFixture.nativeElement.querySelectorAll('.mat-badge-content | ||||
').length).toBe(2); | ||||
}); | ||||
}); | }); | |||
/** Test component that contains a MatBadge. */ | /** Test component that contains a MatBadge. */ | |||
@Component({ | @Component({ | |||
// Explicitly set the view encapsulation since we have a test that checks for it. | // Explicitly set the view encapsulation since we have a test that checks for it. | |||
encapsulation: ViewEncapsulation.Emulated, | encapsulation: ViewEncapsulation.Emulated, | |||
styles: ['span { color: hotpink; }'], | styles: ['span { color: hotpink; }'], | |||
template: ` | template: ` | |||
<span [matBadge]="badgeContent" | <span [matBadge]="badgeContent" | |||
[matBadgeColor]="badgeColor" | [matBadgeColor]="badgeColor" | |||
skipping to change at line 217 | skipping to change at line 233 | |||
class BadgeTestApp { | class BadgeTestApp { | |||
badgeColor: ThemePalette; | badgeColor: ThemePalette; | |||
badgeContent: string | number = '1'; | badgeContent: string | number = '1'; | |||
badgeDirection = 'above after'; | badgeDirection = 'above after'; | |||
badgeHidden = false; | badgeHidden = false; | |||
badgeSize = 'medium'; | badgeSize = 'medium'; | |||
badgeOverlap = false; | badgeOverlap = false; | |||
badgeDescription: string; | badgeDescription: string; | |||
badgeDisabled = false; | badgeDisabled = false; | |||
} | } | |||
@Component({ | ||||
template: ` | ||||
<span matBadge="Hello"> | ||||
home | ||||
<div class="mat-badge-content">Pre-existing badge</div> | ||||
</span> | ||||
` | ||||
}) | ||||
class PreExistingBadge { | ||||
} | ||||
@Component({ | ||||
template: ` | ||||
<span matBadge="Hello"> | ||||
home | ||||
<span matBadge="Hi">Something</span> | ||||
</span> | ||||
` | ||||
}) | ||||
class NestedBadge { | ||||
} | ||||
End of changes. 3 change blocks. | ||||
4 lines changed or deleted | 22 lines changed or added |