Skip to content
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

Ion Range test fix #4

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
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
84 changes: 43 additions & 41 deletions cypress/integration/components/range.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,57 @@ const selectorAndValues: Array<{
},
];

selectorAndValues.forEach((selectorAndValue) => {
describe(selectorAndValue.selector, () => {
beforeEach(() => {
cy.visit('./');
});
describe('using valid valid ranges', () => {
beforeEach(() => {
cy.visit('./');
});

it('can be changed by set value', () => {
cy.get(selectorAndValue.selector).should((item$) => {
expect(stringify((<IonRange>item$[0]).value)).not.to.eq(
stringify(selectorAndValue.wantedValue)
selectorAndValues.forEach((selectorAndValue) => {
describe(selectorAndValue.selector, () => {
it('can be changed by set value', () => {
cy.get(selectorAndValue.selector).should((item$) => {
expect(stringify((<IonRange>item$[0]).value)).not.to.eq(
stringify(selectorAndValue.wantedValue)
);
});

ionRangeCypress.setValue(
selectorAndValue.selector,
selectorAndValue.wantedValue
);
});

ionRangeCypress.setValue(
selectorAndValue.selector,
selectorAndValue.wantedValue
);
cy.get(selectorAndValue.selector).should((item$) => {
expect(stringify((<IonRange>item$[0]).value)).to.eq(
stringify(selectorAndValue.wantedValue)
);
});

cy.get(selectorAndValue.selector).should((item$) => {
expect(stringify((<IonRange>item$[0]).value)).to.eq(
stringify(selectorAndValue.wantedValue)
getIonRangeEndSlotElements(selectorAndValue.selector).contains(
selectorAndValue.wantedLabel
);
});

getIonRangeEndSlotElements(selectorAndValue.selector).contains(
selectorAndValue.wantedLabel
);
});
it('can be changed by move value', () => {
cy.get(selectorAndValue.selector).should((item$) => {
expect(stringify((<IonRange>item$[0]).value)).not.to.eq(
stringify(selectorAndValue.wantedValue)
);
});

it('can be changed by move value', () => {
cy.get(selectorAndValue.selector).should((item$) => {
expect(stringify((<IonRange>item$[0]).value)).not.to.eq(
stringify(selectorAndValue.wantedValue)
);
});
ionRangeCypress.moveToValue(selectorAndValue.selector, {
targetValue: selectorAndValue.wantedValue,
});

ionRangeCypress.moveToValue(selectorAndValue.selector, {
targetValue: selectorAndValue.wantedValue,
});
cy.get(selectorAndValue.selector).should((item$) => {
expect(stringify((<IonRange>item$[0]).value)).to.eq(
stringify(selectorAndValue.wantedValue)
);
});

cy.get(selectorAndValue.selector).should((item$) => {
expect(stringify((<IonRange>item$[0]).value)).to.eq(
stringify(selectorAndValue.wantedValue)
getIonRangeEndSlotElements(selectorAndValue.selector).contains(
selectorAndValue.wantedLabel
);
});

getIonRangeEndSlotElements(selectorAndValue.selector).contains(
selectorAndValue.wantedLabel
);
});
});
});
Expand Down Expand Up @@ -122,11 +124,11 @@ describe('using it to values beyond their supported max/min does not hangs', ()
},
];

outOfRangeValues.forEach((selectorAndValue) => {
beforeEach(() => {
cy.visit('./');
});
beforeEach(() => {
cy.visit('./');
});

outOfRangeValues.forEach((selectorAndValue) => {
describe(`${selectorAndValue.selector}, target: ${stringify(
selectorAndValue.outOfRangeValue
)}`, () => {
Expand Down
65 changes: 21 additions & 44 deletions src/components/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,8 @@ class IonRangeCypress
const handle = ionRange.shadowRoot?.querySelector(knobSelector);

if (!handle) {
return cy.wait(100).then(() =>
this.moveToNumberValue({
ionRange,
currentValue,
knobSelector,
options,
})
throw new Error(
'No Handle was found in th shadow root. Is the element hydrated?'
);
}

Expand Down Expand Up @@ -169,51 +164,33 @@ class IonRangeCypress
ionRange: GenericIonRange<IonRangeObjectValue>,
options: IonRangeCypressMoveToValueOptions<IonRangeObjectValue>
): Cypress.Chainable<JQuery<IonRange>> {
const cypressFunctions: Array<() => Cypress.Chainable<JQuery<IonRange>>> =
[];

if (ionRange.value.upper !== options.targetValue.upper) {
cypressFunctions.push(() =>
this.moveToNumberValue({
ionRange,
currentValue: ionRange.value.upper as number,
knobSelector: RangeKnobSelector.Upper,
options: {
...options,
targetValue: options.targetValue.upper,
},
})
);
}

if (ionRange.value.lower !== options.targetValue.lower) {
cypressFunctions.push(() =>
this.moveToNumberValue({
// Move upper
return this.moveToNumberValue({
ionRange,
currentValue: ionRange.value.upper as number,
knobSelector: RangeKnobSelector.Upper,
options: {
...options,
targetValue: options.targetValue.upper,
},
})
.then(() => {
// Move lower
return this.moveToNumberValue({
ionRange,
currentValue: ionRange.value.lower,
knobSelector: RangeKnobSelector.Lower,
options: {
...options,
targetValue: options.targetValue.lower,
},
})
);
}

if (!cypressFunctions.length) {
return cy.wrap(ionRange);
}

const cypressCall: () => Cypress.Chainable<JQuery<IonRange>> =
cypressFunctions.reduce((prev, curr) => {
return () => prev().then(() => curr());
});
})
.then(() => {
cy.log(`ion range new value: ${JSON.stringify(ionRange.value)}`).wrap(
ionRange
);
});

return cypressCall().then(() => {
cy.log(`ion range new value: ${JSON.stringify(ionRange.value)}`).wrap(
ionRange
);
});
}

private getFixTargetValue(
Expand Down