Skip to content
Open
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
66 changes: 44 additions & 22 deletions packages/ossa-demo/src/components/swipeCell/__test__/e2e.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
describe("SwipeCell Testing", function () {
context("Stepper Normal Testing", function () {
context("SwipeCell Normal Testing", function () {
before(function () {
cy.viewport("iphone-xr");
// 进入Stepper页
// 进入SwipeCell页
cy.visit("#/components/swipeCell/demo/index");
});

Expand Down Expand Up @@ -33,6 +32,19 @@ describe("SwipeCell Testing", function () {
shiftKey: true,
};
}

// 约等于 误差0.0005
function approximatelyEqual(x, y, epsilon = 0.0005) {
return Math.abs(x - y) < epsilon;
}

function getTranslateX(str) {
let num;
str.replace(/translate3d\((.*?)px,.*?px,.*?px\)/, function (a, b) {
num = +b;
});
return Math.abs(num);
}
// 向左滑动
cy.get(selector)
.trigger("touchstart", getTouchEvent(startPageX, pageY))
Expand All @@ -43,26 +55,36 @@ describe("SwipeCell Testing", function () {
.then(($el) => {
const { width } = $el[0].getBoundingClientRect();
cy.get(selector + " .ossa-swipecell__wrapper").then(($wrap) => {
cy.log($wrap[0].style.transform);
cy.log(width);
// 比较移动位置
expect($wrap[0].style.transform).equal(
isDisabled
? `translate3d(0px, 0px, 0px)`
: `translate3d(-${width.toFixed(4)}px, 0px, 0px)`
);
});
})
.trigger("touchstart", getTouchEvent(startPageX, pageY))
.trigger("touchmove", getTouchEvent(startPageX + 100, pageY))
.trigger("touchend", getTouchEvent(startPageX + 100, pageY))
.wait(300)
.get(selector + " .ossa-swipecell__right")
.then(($el) => {
const { width } = $el[0].getBoundingClientRect();
cy.get(selector + " .ossa-swipecell__wrapper").then(($wrap) => {
// 比较移动位置
expect($wrap[0].style.transform).equal(
`translate3d(0px, 0px, 0px)`
);
expect(
approximatelyEqual(
getTranslateX($wrap[0].style.transform),
isDisabled ? 0 : width
)
).equal(true);

cy.get(selector)
.trigger("touchstart", getTouchEvent(startPageX, pageY))
.trigger("touchmove", getTouchEvent(startPageX + 100, pageY))
.trigger("touchend", getTouchEvent(startPageX + 100, pageY))
.wait(300)
.get(selector + " .ossa-swipecell__right")
.then(($el) => {
const { width } = $el[0].getBoundingClientRect();
cy.get(selector + " .ossa-swipecell__wrapper").then(
($wrap) => {
// 比较移动位置
expect(
approximatelyEqual(
getTranslateX($wrap[0].style.transform),
0
)
).equal(true);
}
);
});
});
});
});
Expand Down