From e760395c389414d166cdc671e330ff4db5632f9a Mon Sep 17 00:00:00 2001 From: Y Date: Mon, 27 May 2024 17:25:01 +0800 Subject: [PATCH] Revert "refactor(message): sfc to tsx (#1398)" This reverts commit edba1a28ebe2e23b34498ac40db9fb99bffdadd7. --- .../__test__/__snapshots__/demo.test.jsx.snap | 20 ++-- src/message/__test__/index.test.jsx | 60 ++++++----- src/message/index.ts | 2 +- src/message/{message.tsx => message.vue} | 101 ++++++++---------- 4 files changed, 90 insertions(+), 93 deletions(-) rename src/message/{message.tsx => message.vue} (80%) diff --git a/src/message/__test__/__snapshots__/demo.test.jsx.snap b/src/message/__test__/__snapshots__/demo.test.jsx.snap index 8f4bac59f..259c96aa1 100644 --- a/src/message/__test__/__snapshots__/demo.test.jsx.snap +++ b/src/message/__test__/__snapshots__/demo.test.jsx.snap @@ -96,15 +96,15 @@ exports[`Message > Message baseVue demo works fine 1`] = ` - + - + - + - + - + `; @@ -276,15 +276,15 @@ exports[`Message > Message mobileVue demo works fine 1`] = ` - + - + - + - + - + diff --git a/src/message/__test__/index.test.jsx b/src/message/__test__/index.test.jsx index a98e205eb..a3ea399da 100644 --- a/src/message/__test__/index.test.jsx +++ b/src/message/__test__/index.test.jsx @@ -2,7 +2,7 @@ import { h } from 'vue'; import { mount } from '@vue/test-utils'; import { describe, it, expect } from 'vitest'; import { nextTick } from 'vue'; -import Message from '../message'; +import Message from '../message.vue'; import { AppIcon, AppIcon as TIconApp } from 'tdesign-icons-vue-next'; const prefix = 't'; const name = `${prefix}-message`; @@ -11,10 +11,10 @@ describe('Message.vue', () => { describe('props', () => { it(': align', () => { ['left', 'center'].map((align) => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(`.${name}`).classes().includes(`${name}-align--${align}`)).toBeTruthy(); }); - }); + }) it(': offset', () => { const offset = [-10, 20]; @@ -26,24 +26,28 @@ describe('Message.vue', () => { }); it(': marquee', async () => { - // const wrapper = mount(); - // expect(wrapper.vm.scroll.marquee).toBe(false); - // const wrapper1 = mount(); - // expect(wrapper1.vm.scroll.marquee).toBe(false); - // const wrapper2 = mount(); - // await nextTick(); - // expect(wrapper2.vm.scroll.marquee).toBe(true); - // const wrapper3 = mount(); - // await nextTick(); - // expect(wrapper3.vm.scroll.marquee).toBe(true); - // wrapper3.vm.handleTransitionend(); - // expect(wrapper3.vm.scroll.loop).toBe(0); - // wrapper3.vm.handleTransitionend(); - // expect(wrapper3.vm.scroll.marquee).toBe(false); - // const wrapper4 = mount(); - // await nextTick(); - // expect(wrapper4.vm.scroll.marquee).toBe(true); - // wrapper4.vm.handleTransitionend(); + const wrapper = mount(); + expect(wrapper.vm.scroll.marquee).toBe(false); + + const wrapper1 = mount(); + expect(wrapper1.vm.scroll.marquee).toBe(false); + + const wrapper2 = mount(); + await nextTick(); + expect(wrapper2.vm.scroll.marquee).toBe(true); + + const wrapper3 = mount(); + await nextTick(); + expect(wrapper3.vm.scroll.marquee).toBe(true); + wrapper3.vm.handleTransitionend(); + expect(wrapper3.vm.scroll.loop).toBe(0); + wrapper3.vm.handleTransitionend(); + expect(wrapper3.vm.scroll.marquee).toBe(false); + + const wrapper4 = mount(); + await nextTick(); + expect(wrapper4.vm.scroll.marquee).toBe(true); + wrapper4.vm.handleTransitionend(); }); it(': duration', () => { @@ -89,18 +93,19 @@ describe('Message.vue', () => { expect(wrapper3.find(`.${name}__icon--left`).findComponent(TIconApp).exists()).toBeTruthy(); }); + it('link', () => { - const wrapper0 = mount(() => ); + const wrapper0 = mount(() => ); expect(wrapper0.find(`.${name}__link`).exists()).toBeFalsy(); // lin is string const wrapper1 = mount(() => ); expect(wrapper1.find(`.${name}__link`).exists()).toBeTruthy(); - expect(wrapper1.find(`.${name}__link`).text()).toEqual('link'); + expect(wrapper1.find(`.${name}__link`).text()).toEqual('link') // link is Object - const wrapper2 = mount(() => ); + const wrapper2 = mount(() => ); expect(wrapper2.find(`.${name}__link`).exists()).toBeTruthy(); - expect(wrapper2.find(`.${name}__link`).text()).toEqual('content'); + expect(wrapper2.find(`.${name}__link`).text()).toEqual('content') // link is function const appIcon = () => h(TIconApp); @@ -116,6 +121,7 @@ describe('Message.vue', () => { expect(wrapper4.find(`.${name}__link`).exists()).toBeTruthy(); expect(wrapper4.find(`.${name}__link`).findComponent(TIconApp).exists()).toBeTruthy(); }); + }); describe('event', () => { @@ -131,7 +137,9 @@ describe('Message.vue', () => { it('onLinkClick', () => { const fn = vi.fn(); - const wrapper = mount(() => ); + const wrapper = mount(() => ( + + )); const _link = wrapper.find(`.${name}__link`); _link.trigger('click'); expect(fn).toBeCalledTimes(1); diff --git a/src/message/index.ts b/src/message/index.ts index a67a6f5e9..05164db18 100644 --- a/src/message/index.ts +++ b/src/message/index.ts @@ -1,5 +1,5 @@ import { createApp, defineComponent, ref, h, VNode, App, nextTick } from 'vue'; -import Message from './message'; +import Message from './message.vue'; import { WithInstallType, isBrowser } from '../shared'; import { TdMessageProps, MessageThemeList } from './type'; diff --git a/src/message/message.tsx b/src/message/message.vue similarity index 80% rename from src/message/message.tsx rename to src/message/message.vue index e69bea1a4..354b027f2 100644 --- a/src/message/message.tsx +++ b/src/message/message.vue @@ -1,3 +1,30 @@ + + +