Skip to content

Commit

Permalink
add unit tests for select panelMaxHeight
Browse files Browse the repository at this point in the history
fix panelMaxHeight description comment
  • Loading branch information
RudolfFrederiksen committed Jun 21, 2019
1 parent 12bba90 commit 7aced88
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dev-app/select/select-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class SelectDemo {
topHeightCtrl = new FormControl(0);
drinksTheme = 'primary';
pokemonTheme = 'primary';
pokemonPanelHeight = 100;
pokemonPanelHeight = 200;
compareByValue = true;
selectFormControl = new FormControl('', Validators.required);

Expand Down
62 changes: 62 additions & 0 deletions src/material/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,41 @@ describe('MatSelect', () => {
}));
});

describe('with custom panel max height', () => {
beforeEach(async(() => configureMatSelectTestingModule([
BasicSelect,
BasicSelectWithCustomHeight,
])));

it('should use default constant SELECT_PANEL_MAX_HEIGHT value', fakeAsync(() => {
const fixture = TestBed.createComponent(BasicSelect);

fixture.detectChanges();
const trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;

trigger.click();
fixture.detectChanges();
flush();

const panel = overlayContainerElement.querySelector('.mat-select-panel') as HTMLElement;
expect(parseInt(panel.style.maxHeight as string)).toBe(256);
}));

it('should set the max-height of select panel', fakeAsync(() => {
const fixture = TestBed.createComponent(BasicSelectWithCustomHeight);

fixture.detectChanges();
const trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;

trigger.click();
fixture.detectChanges();
flush();

const panel = overlayContainerElement.querySelector('.mat-select-panel') as HTMLElement;
expect(parseInt(panel.style.maxHeight as string)).toBe(400);
}));
});

describe('when invalid inside a form', () => {
beforeEach(async(() => configureMatSelectTestingModule([InvalidSelectInForm])));

Expand Down Expand Up @@ -4643,6 +4678,33 @@ class BasicSelectWithTheming {
theme: string;
}

@Component({
selector: 'basic-select-with-custom-height',
template: `
<mat-form-field>
<mat-select [panelMaxHeight]="maxHeight">
<mat-option *ngFor="let food of foods"
[value]="food.value">{{ food.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
`
})
class BasicSelectWithCustomHeight {
@ViewChild(MatSelect, {static: false}) select: MatSelect;
foods: any[] = [
{ value: 'steak-0', viewValue: 'Steak' },
{ value: 'pizza-1', viewValue: 'Pizza' },
{ value: 'tacos-2', viewValue: 'Tacos' },
{ value: 'sandwich-3', viewValue: 'Sandwich' },
{ value: 'chips-4', viewValue: 'Chips' },
{ value: 'eggs-5', viewValue: 'Eggs' },
{ value: 'pasta-6', viewValue: 'Pasta' },
{ value: 'sushi-7', viewValue: 'Sushi' },
];
maxHeight: number = 400;
}

@Component({
selector: 'reset-values-select',
template: `
Expand Down
1 change: 0 additions & 1 deletion src/material/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
}

/** Define select panel maximum height. */
/** The max height of the select's overlay panel */
@Input() panelMaxHeight: number = SELECT_PANEL_MAX_HEIGHT;

/**
Expand Down

0 comments on commit 7aced88

Please sign in to comment.