test(Coupon): add test cases (#8231)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`should render CouponCell correctly 1`] = `
|
||||
<div class="van-cell van-cell--clickable van-coupon-cell"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<div class="van-cell__title">
|
||||
<span>
|
||||
Coupon
|
||||
</span>
|
||||
</div>
|
||||
<div class="van-cell__value van-coupon-cell__value">
|
||||
<span>
|
||||
No coupons
|
||||
</span>
|
||||
</div>
|
||||
<i class="van-badge__wrapper van-icon van-icon-arrow van-cell__right-icon">
|
||||
</i>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`should render CouponCell correctly with zero discount 1`] = `
|
||||
<div class="van-cell van-cell--clickable van-coupon-cell"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<div class="van-cell__title">
|
||||
<span>
|
||||
Coupon
|
||||
</span>
|
||||
</div>
|
||||
<div class="van-cell__value van-coupon-cell__value van-coupon-cell__value--selected">
|
||||
<span>
|
||||
-¥ 0.00
|
||||
</span>
|
||||
</div>
|
||||
<i class="van-badge__wrapper van-icon van-icon-arrow van-cell__right-icon">
|
||||
</i>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`should render CouponCell with chosenCoupon correctly 1`] = `
|
||||
<div class="van-cell van-cell--clickable van-coupon-cell"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<div class="van-cell__title">
|
||||
<span>
|
||||
Coupon
|
||||
</span>
|
||||
</div>
|
||||
<div class="van-cell__value van-coupon-cell__value van-coupon-cell__value--selected">
|
||||
<span>
|
||||
-¥ 1.50
|
||||
</span>
|
||||
</div>
|
||||
<i class="van-badge__wrapper van-icon van-icon-arrow van-cell__right-icon">
|
||||
</i>
|
||||
</div>
|
||||
`;
|
||||
@@ -0,0 +1,53 @@
|
||||
import { mount } from '../../../test';
|
||||
import CouponCell from '../index';
|
||||
|
||||
const coupon = {
|
||||
id: 1,
|
||||
discount: 0,
|
||||
denominations: 150,
|
||||
originCondition: 0,
|
||||
reason: '',
|
||||
value: 150,
|
||||
name: 'name',
|
||||
description: 'description',
|
||||
startAt: 1489104000,
|
||||
endAt: 1514592000,
|
||||
};
|
||||
|
||||
test('should render CouponCell correctly', () => {
|
||||
const wrapper = mount(CouponCell);
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should render CouponCell with chosenCoupon correctly', () => {
|
||||
const wrapper = mount(CouponCell, {
|
||||
props: {
|
||||
coupons: [coupon],
|
||||
chosenCoupon: 0,
|
||||
},
|
||||
});
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should render CouponCell correctly with zero discount', () => {
|
||||
const wrapper = mount(CouponCell, {
|
||||
props: {
|
||||
coupons: [{ ...coupon, value: 0, denominations: 150 }],
|
||||
chosenCoupon: 0,
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should click one time when coupon cell is clicked', () => {
|
||||
const onClick = jest.fn();
|
||||
const wrapper = mount(CouponCell, {
|
||||
props: {
|
||||
onClick,
|
||||
},
|
||||
});
|
||||
|
||||
wrapper.trigger('click');
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
Reference in New Issue
Block a user