Skip to content

test(select): make rtl test async #3866

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

Closed
wants to merge 3 commits into from
Closed
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
74 changes: 43 additions & 31 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,37 +988,49 @@ describe('MdSelect', () => {
select.style.marginRight = '30px';
});

it('should align the trigger and the selected option on the x-axis in ltr', () => {
trigger.click();
fixture.detectChanges();
it('should align the trigger and the selected option on the x-axis in ltr', async(() => {
fixture.whenStable().then(() => {
fixture.detectChanges();

const triggerLeft = trigger.getBoundingClientRect().left;
const firstOptionLeft =
document.querySelector('.cdk-overlay-pane md-option').getBoundingClientRect().left;
trigger.click();
fixture.detectChanges();

// Each option is 32px wider than the trigger, so it must be adjusted 16px
// to ensure the text overlaps correctly.
expect(firstOptionLeft.toFixed(2))
.toEqual((triggerLeft - 16).toFixed(2),
`Expected trigger to align with the selected option on the x-axis in LTR.`);
});
fixture.whenStable().then(() => {
fixture.detectChanges();

it('should align the trigger and the selected option on the x-axis in rtl', () => {
dir.value = 'rtl';
const triggerLeft = trigger.getBoundingClientRect().left;
const firstOptionLeft = document.querySelector('.cdk-overlay-pane md-option').getBoundingClientRect().left;

trigger.click();
fixture.detectChanges();
// Each option is 32px wider than the trigger, so it must be adjusted 16px
// to ensure the text overlaps correctly.
expect(firstOptionLeft.toFixed(2))
.toEqual((triggerLeft - 16).toFixed(2), `Expected trigger to align with the selected option on the x-axis in LTR.`);
});
});
}));

const triggerRight = trigger.getBoundingClientRect().right;
const firstOptionRight =
document.querySelector('.cdk-overlay-pane md-option').getBoundingClientRect().right;
it('should align the trigger and the selected option on the x-axis in rtl', async(() => {
dir.value = 'rtl';
fixture.whenStable().then(() => {
fixture.detectChanges();

// Each option is 32px wider than the trigger, so it must be adjusted 16px
// to ensure the text overlaps correctly.
expect(firstOptionRight.toFixed(2))
.toEqual((triggerRight + 16).toFixed(2),
`Expected trigger to align with the selected option on the x-axis in RTL.`);
});
trigger.click();
fixture.detectChanges();

fixture.whenStable().then(() => {
fixture.detectChanges();
const triggerRight = trigger.getBoundingClientRect().right;
const firstOptionRight =
document.querySelector('.cdk-overlay-pane md-option').getBoundingClientRect().right;

// Each option is 32px wider than the trigger, so it must be adjusted 16px
// to ensure the text overlaps correctly.
expect(firstOptionRight.toFixed(2))
.toEqual((triggerRight + 16).toFixed(2),
`Expected trigger to align with the selected option on the x-axis in RTL.`);
});
});
}));
});

describe('x-axis positioning in multi select mode', () => {
Expand Down Expand Up @@ -1450,13 +1462,13 @@ describe('MdSelect', () => {
let testInstance: MultiSelect;
let trigger: HTMLElement;

beforeEach(() => {
beforeEach(async(() => {
fixture = TestBed.createComponent(MultiSelect);
testInstance = fixture.componentInstance;
fixture.detectChanges();

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

it('should be able to select multiple values', () => {
trigger.click();
Expand Down Expand Up @@ -1616,17 +1628,17 @@ describe('MdSelect', () => {
expect(trigger.textContent).toContain('Tacos, Pizza, Steak');
});

it('should throw an exception when trying to set a non-array value', () => {
it('should throw an exception when trying to set a non-array value', async(() => {
expect(() => {
testInstance.control.setValue('not-an-array');
}).toThrowError(wrappedErrorMessage(new MdSelectNonArrayValueError()));
});
}));

it('should throw an exception when trying to change multiple mode after init', () => {
it('should throw an exception when trying to change multiple mode after init', async(() => {
expect(() => {
testInstance.select.multiple = false;
}).toThrowError(wrappedErrorMessage(new MdSelectDynamicMultipleError()));
});
}));

it('should pass the `multiple` value to all of the option instances', async(() => {
trigger.click();
Expand Down