Skip to content

Commit

Permalink
fix(select-spec): Update the rtl test to ensure the fixture is stable
Browse files Browse the repository at this point in the history
  • Loading branch information
trshafer committed Mar 1, 2017
1 parent 1a67107 commit 97cc67f
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -976,37 +976,41 @@ describe('MdSelect', () => {
select.style.marginRight = '20px';
});

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

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

// 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(() => {
const triggerLeft = trigger.getBoundingClientRect().left;
const firstOptionLeft =
document.querySelector('.cdk-overlay-pane md-option').getBoundingClientRect().left;

// 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.`);
});
}));

it('should align the trigger and the selected option on the x-axis in rtl', () => {
it('should align the trigger and the selected option on the x-axis in rtl', async(() => {
dir.value = 'rtl';

trigger.click();
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.`);
});
fixture.whenStable().then(() => {
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.`);
});
}));
});

});
Expand Down

0 comments on commit 97cc67f

Please sign in to comment.