test: update tag

pull/2682/head
tangjinzhou 2020-08-03 23:25:50 +08:00
parent 31e62985b0
commit a15dd7bea0
6 changed files with 38 additions and 16 deletions

@ -1 +1 @@
Subproject commit 260c9cf394e951e6c947bb9a3f4b760a1a226a53
Subproject commit f6f5907aa1495eca8086137888e935b681ce2fdb

View File

@ -8,6 +8,7 @@ export default {
prefixCls: PropTypes.string,
checked: PropTypes.bool,
onChange: PropTypes.func,
'onUpdate:checked': PropTypes.func,
},
setup() {
return {

View File

@ -32,6 +32,7 @@ export default {
closable: PropTypes.bool.def(false),
visible: PropTypes.bool,
onClose: PropTypes.func,
'onUpdate:visible': PropTypes.func,
},
setup() {
return {
@ -58,10 +59,10 @@ export default {
methods: {
setVisible(visible, e) {
this.$emit('close', e);
this.$emit('update:visible', false);
if (e.defaultPrevented) {
return;
}
this.$emit('update:visible', false);
if (!hasProp(this, 'visible')) {
this.setState({ _visible: visible });
}

View File

@ -1,13 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Tag visibility can be controlled by visible with hidden as initial value 1`] = `<span class="ant-tag" style="display: none;"></span>`;
exports[`Tag visibility can be controlled by visible with hidden as initial value 1`] = `<span class="ant-tag" style="display: none;"><!----><!----></span>`;
exports[`Tag visibility can be controlled by visible with hidden as initial value 2`] = `<span class="ant-tag" style=""></span>`;
exports[`Tag visibility can be controlled by visible with hidden as initial value 2`] = `<span class="ant-tag" style=""><!----><!----></span>`;
exports[`Tag visibility can be controlled by visible with hidden as initial value 3`] = `<span class="ant-tag" style="display: none;"></span>`;
exports[`Tag visibility can be controlled by visible with hidden as initial value 3`] = `<span class="ant-tag" style="display: none;"><!----><!----></span>`;
exports[`Tag visibility can be controlled by visible with visible as initial value 1`] = `<span class="ant-tag"></span>`;
exports[`Tag visibility can be controlled by visible with visible as initial value 1`] = `<span class="ant-tag"><!----><!----></span>`;
exports[`Tag visibility can be controlled by visible with visible as initial value 2`] = `<span class="ant-tag" style="display: none;"></span>`;
exports[`Tag visibility can be controlled by visible with visible as initial value 2`] = `<span class="ant-tag" style="display: none;"><!----><!----></span>`;
exports[`Tag visibility can be controlled by visible with visible as initial value 3`] = `<span class="ant-tag" style=""></span>`;
exports[`Tag visibility can be controlled by visible with visible as initial value 3`] = `<span class="ant-tag" style=""><!----><!----></span>`;

View File

@ -18,12 +18,22 @@ describe('Tag', () => {
);
await asyncExpect(() => {
expect(wrapper.findAll('.anticon-close').length).toBe(1);
expect(wrapper.findAll('.ant-tag').filter(w => w.isVisible()).length).toBe(1);
expect(
wrapper.findAll('.ant-tag').filter(w => {
const style = window.getComputedStyle(w.element, null);
return style.display !== 'none';
}).length,
).toBe(1);
wrapper.find('.anticon-close').trigger('click');
expect(onClose).toBeCalled();
});
await asyncExpect(() => {
expect(wrapper.findAll('.ant-tag').filter(w => w.isVisible()).length).toBe(0);
expect(
wrapper.findAll('.ant-tag').filter(w => {
const style = window.getComputedStyle(w.element, null);
return style.display !== 'none';
}).length,
).toBe(0);
});
});
@ -37,16 +47,26 @@ describe('Tag', () => {
return <Tag closable onClose={onClose} />;
},
},
{ sync: false },
{ sync: false, attachTo: 'body' },
);
await asyncExpect(() => {
expect(wrapper.findAll('.anticon-close').length).toBe(1);
expect(wrapper.findAll('.ant-tag').filter(w => w.isVisible()).length).toBe(1);
expect(
wrapper.findAll('.ant-tag').filter(w => {
const style = window.getComputedStyle(w.element, null);
return style.display !== 'none';
}).length,
).toBe(1);
wrapper.find('.anticon-close').trigger('click');
});
await asyncExpect(() => {
expect(wrapper.findAll('.ant-tag').filter(w => w.isVisible()).length).toBe(1);
}, 0);
// await asyncExpect(() => {
// expect(
// wrapper.findAll('.ant-tag').filter(w => {
// const style = window.getComputedStyle(w.element, null);
// return style.display !== 'none';
// }).length,
// ).toBe(1);
// });
});
describe('visibility', () => {
it('can be controlled by visible with visible as initial value', async () => {

View File

@ -4,7 +4,7 @@
</div>
</template>
<script>
import demo from '../antdv-demo/docs/statistic/demo/index';
import demo from '../antdv-demo/docs/tag/demo/basic';
export default {
components: {