-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(material-experimental/mdc-card): add DI token for configuring ap…
…pearance (#23302) Adds a new DI token to the MDC-based card that allows consumers to set the default appearance. Also sets up unit tests for the card. Fixes #23298.
- Loading branch information
Showing
3 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {Component, Provider, Type, ViewChild} from '@angular/core'; | ||
import {MatCardModule} from './module'; | ||
import {MatCard, MAT_CARD_CONFIG} from './card'; | ||
|
||
|
||
describe('MDC-based MatCard', () => { | ||
function createComponent<T>(component: Type<T>, providers: Provider[] = []): ComponentFixture<T> { | ||
TestBed.configureTestingModule({ | ||
imports: [MatCardModule], | ||
declarations: [component], | ||
providers | ||
}).compileComponents(); | ||
|
||
return TestBed.createComponent<T>(component); | ||
} | ||
|
||
it('should default the card to the `raised` appearance', () => { | ||
const fixture = createComponent(BasicCard); | ||
fixture.detectChanges(); | ||
const card = fixture.nativeElement.querySelector('.mat-mdc-card'); | ||
expect(card.classList).not.toContain('mdc-card--outlined'); | ||
}); | ||
|
||
it('should be able to change the card appearance', () => { | ||
const fixture = createComponent(BasicCard); | ||
fixture.detectChanges(); | ||
const card = fixture.nativeElement.querySelector('.mat-mdc-card'); | ||
|
||
expect(card.classList).not.toContain('mdc-card--outlined'); | ||
|
||
fixture.componentInstance.card.appearance = 'outlined'; | ||
fixture.detectChanges(); | ||
|
||
expect(card.classList).toContain('mdc-card--outlined'); | ||
}); | ||
|
||
it('should be able to change the default card appearance using DI', () => { | ||
const fixture = createComponent(BasicCard, [{ | ||
provide: MAT_CARD_CONFIG, | ||
useValue: {appearance: 'outlined'} | ||
}]); | ||
fixture.detectChanges(); | ||
const card = fixture.nativeElement.querySelector('.mat-mdc-card'); | ||
expect(card.classList).toContain('mdc-card--outlined'); | ||
}); | ||
|
||
}); | ||
|
||
@Component({ | ||
template: '<mat-card></mat-card>' | ||
}) | ||
class BasicCard { | ||
@ViewChild(MatCard) card: MatCard; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters