提交 be734f3d 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

refactor: 移除无用文件

上级 90c33bc6
<template>
<view>
<text class="bold">array literal</text>
<button class="array-literal-emit-btn uni-common-mt" @click="emitChange">emit change</button>
</view>
</template>
<script setup>
const emit = defineEmits(['change'])
const emitChange = () => {
emit('change', 1)
}
</script>
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/basic/define-emits/define-emits'
describe('defineEmits', () => {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const handleArrayLiteralChangeRes = await page.$('#handle-array-literal-change-res')
expect((await handleArrayLiteralChangeRes.text()).trim()).toBe('handle array literal comp change result:')
const arrayLiteralEmitBtn = await page.$('.array-literal-emit-btn')
await arrayLiteralEmitBtn.tap()
expect(await handleArrayLiteralChangeRes.text()).toBe(
'handle array literal comp change result: options is 1')
const handleTypeEmits1ChangeRes = await page.$('#handle-type-emits1-change-res')
expect((await handleTypeEmits1ChangeRes.text()).trim()).toBe('handle type emits comp change result:')
const typeEmits1EmitBtn = await page.$('.type-emits1-emit-btn')
await typeEmits1EmitBtn.tap()
expect(await handleTypeEmits1ChangeRes.text()).toBe('handle type emits comp change result: options is 2')
const handleTypeEmits2ChangeRes = await page.$('#handle-type-emits2-change-res')
expect((await handleTypeEmits2ChangeRes.text()).trim()).toBe(
'handle type emits named tuple syntax comp change result:')
const typeEmits2EmitBtn = await page.$('.type-emits2-emit-btn')
await typeEmits2EmitBtn.tap()
expect(await handleTypeEmits2ChangeRes.text()).toBe(
'handle type emits named tuple syntax comp change result: options is 3')
})
})
\ No newline at end of file
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view class="page">
<ArrayLiteral @change='handleArrayLiteralCompChange' />
<text id="handle-array-literal-change-res" class="uni-common-mt">handle array literal comp change result:
{{handleArrayLiteralCompChangeRes}}</text>
<TypeEmits1 @change='handleTypeEmits1CompChange' />
<text id="handle-type-emits1-change-res" class="uni-common-mt">handle type emits comp change result:
{{handleTypeEmits1CompChangeRes}}</text>
<TypeEmits2 @change='handleTypeEmits2CompChange' />
<text id="handle-type-emits2-change-res" class="uni-common-mt">handle type emits named tuple syntax comp change
result: {{handleTypeEmits2CompChangeRes}}</text>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup>
import ArrayLiteral from './array-literal.uvue';
import TypeEmits1 from './type-emits-1.uvue';
import TypeEmits2 from './type-emits-2.uvue';
const handleArrayLiteralCompChangeRes = ref('')
const handleArrayLiteralCompChange = (num : number) => {
handleArrayLiteralCompChangeRes.value = `options is ${num}`
}
const handleTypeEmits1CompChangeRes = ref('')
const handleTypeEmits1CompChange = (num : number) => {
handleTypeEmits1CompChangeRes.value = `options is ${num}`
}
const handleTypeEmits2CompChangeRes = ref('')
const handleTypeEmits2CompChange = (num : number) => {
handleTypeEmits2CompChangeRes.value = `options is ${num}`
}
</script>
\ No newline at end of file
<template>
<view>
<text class="uni-common-mt bold">type emits</text>
<button class="type-emits1-emit-btn uni-common-mt" @click="emitChange">emit change</button>
</view>
</template>
<script setup>
const emit = defineEmits<{
(e : 'change', id : number) : void
}>()
const emitChange = () => {
emit('change', 2)
}
</script>
\ No newline at end of file
<template>
<view>
<text class="uni-common-mt bold">type emits named tuple syntax</text>
<button class="type-emits2-emit-btn uni-common-mt" @click="emitChange">emit change</button>
</view>
</template>
<script setup>
const emit = defineEmits<{
// 具名元组语法
change : [id: number]
}>()
const emitChange = () => {
emit('change', 3)
}
</script>
\ No newline at end of file
<template>
<view>
<text id="model-value-text">modelValue in Foo: {{modelValue}}</text>
<text class='uni-common-mt' id="msg-text">msg in Foo: {{msg}}</text>
<text class='uni-common-mt' id="default-num-text">num: {{defaultNum}}</text>
<button class='uni-common-mt' id="update-value-btn" @click='updateValue'>update value</button>
</view>
</template>
<script setup>
// 在被修改时,触发 "update:modelValue" 事件
const modelValue = defineModel({ type: String })
// 在被修改时,触发 "update:msg" 事件
const msg = defineModel('msg', { type: String, default: 'default msg' })
const defaultNum = defineModel('num', { type: Number, default: 10 })
const updateValue = () => {
modelValue.value += '1'
msg.value += '2'
}
</script>
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/basic/define-model/define-model'
describe('defineModel', () => {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const modelValueText = await page.$('#model-value-text')
expect(await modelValueText.text()).toBe('modelValue in Foo: str')
const modelValueInput = await page.$('#model-value-input')
expect(await modelValueInput.value()).toBe('str')
const msgText = await page.$('#msg-text')
expect(await msgText.text()).toBe('msg in Foo: msg')
const defaultNumText = await page.$('#default-num-text')
expect(await defaultNumText.text()).toBe('num: 10')
const msgInput = await page.$('#msg-input')
expect(await msgInput.value()).toBe('msg')
const updateValueBtn = await page.$('#update-value-btn')
await updateValueBtn.tap()
expect(await modelValueText.text()).toBe('modelValue in Foo: str1')
expect(await modelValueInput.value()).toBe('str1')
expect(await msgText.text()).toBe('msg in Foo: msg2')
expect(await msgInput.value()).toBe('msg2')
})
})
\ No newline at end of file
<template>
<view class="page">
<Foo v-model='str' v-model:msg="msg" @update:modelValue="handleModelValueUpdate" @update:msg="handleMsgUpdate" />
<input class='uni-common-mt input' id="model-value-input" v-model="str" />
<input class='uni-common-mt input' id="msg-input" v-model="msg" />
</view>
</template>
<script setup>
import Foo from './Foo.uvue'
const str = ref('str')
const msg = ref('msg')
const handleModelValueUpdateRes = ref('')
const handleModelValueUpdate = (val : string) => {
handleModelValueUpdateRes.value = `new str value: ${val}`
}
const handleMsgUpdateRes = ref('')
const handleMsgUpdate = (val : string) => {
handleMsgUpdateRes.value = `new msg value: ${val}`
}
</script>
<style>
.input {
padding: 8px 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
</style>
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/basic/define-options/define-options'
describe('defineOptions', () => {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const count = await page.$('#count')
expect(await count.text()).toBe('count: 0')
const doubleCount = await page.$('#double-count')
expect(await doubleCount.text()).toBe('double count: 0')
const total = await page.$('#total')
expect(await total.text()).toBe('total: 0')
const incrementBtn = await page.$('.increment-btn')
await incrementBtn.tap()
expect(await count.text()).toBe('count: 1')
expect(await doubleCount.text()).toBe('double count: 2')
const price = await page.data('price')
expect(await total.text()).toBe(`total: ${1*price}`)
})
})
\ No newline at end of file
<template>
<view class="page">
<text id="count" class='uni-common-mb'>count: {{ count }}</text>
<text id='double-count' class='uni-common-mb'>double count: {{ doubleCount}}</text>
<text id="total" class='uni-common-mb'>total: {{ total}}</text>
<button class="increment-btn" @click="increment">increment</button>
</view>
</template>
<script setup>
defineOptions({
data() {
return {
count: 0,
price: 10,
total: 0
}
},
computed: {
doubleCount() : number {
return this.count * 2
},
},
watch: {
count() {
this.total = this.price * this.count
},
},
methods: {
increment() {
this.count++
}
}
})
</script>
\ No newline at end of file
<template>
<view>
<text class="bold uni-common-mb">array literal</text>
<text class="uni-common-mb" id="array-literal-str">str: {{ str }}</text>
<text class="uni-common-mb" id="array-literal-num">num: {{ num }}</text>
<text class="uni-common-mb" id="array-literal-bool">bool: {{ bool }}</text>
<text class="uni-common-mb" id="array-literal-arr">arr: {{ JSON.stringify(arr) }}</text>
<text class="uni-common-mb" id="array-literal-obj">obj: {{ JSON.stringify(obj) }}</text>
<text class="uni-common-mb" id="array-literal-fn">fn: {{ (fn as () => string)() }}</text>
</view>
</template>
<script setup>
defineProps(['str', 'num', 'bool', 'arr', 'obj', 'fn']);
</script>
const PAGE_PATH = '/pages/composition-api/basic/define-props/define-props'
describe('defineProps', () => {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const arrayLiteralStr = await page.$('#array-literal-str')
expect(await arrayLiteralStr.text()).toBe('str: default str')
const arrayLiteralNum = await page.$('#array-literal-num')
expect(await arrayLiteralNum.text()).toBe('num: 0')
const arrayLiteralBool = await page.$('#array-literal-bool')
expect(await arrayLiteralBool.text()).toBe('bool: false')
const arrayLiteralArr = await page.$('#array-literal-arr')
expect(await arrayLiteralArr.text()).toBe('arr: ["a","b","c"]')
const arrayLiteralObj = await page.$('#array-literal-obj')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await arrayLiteralObj.text()).toBe('obj: {"arr":[1,2,3],"num":0,"str":"obj str"}')
}
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
expect(await arrayLiteralObj.text()).toBe('obj: {"str":"obj str","num":0,"arr":[1,2,3]}')
}
const arrayLiteralFn = await page.$('#array-literal-fn')
expect(await arrayLiteralFn.text()).toBe('fn: fn res')
const objectLiteralStr = await page.$('#object-literal-str')
expect(await objectLiteralStr.text()).toBe('str: default str')
const objectLiteralNum = await page.$('#object-literal-num')
expect(await objectLiteralNum.text()).toBe('num: 0')
const objectLiteralBool = await page.$('#object-literal-bool')
expect(await objectLiteralBool.text()).toBe('bool: false')
const objectLiteralArr = await page.$('#object-literal-arr')
expect(await objectLiteralArr.text()).toBe('arr: ["a","b","c"]')
const objectLiteralObj = await page.$('#object-literal-obj')
expect(await objectLiteralObj.text()).toBe('obj: {"a":1}')
const objectLiteralFn = await page.$('#object-literal-fn')
expect(await objectLiteralFn.text()).toBe('fn: fn res')
const typeStr = await page.$('#type-str')
expect(await typeStr.text()).toBe('str: default str')
const typeNum = await page.$('#type-num')
expect(await typeNum.text()).toBe('num: 0')
const typeBool = await page.$('#type-bool')
expect(await typeBool.text()).toBe('bool: false')
const typeArr = await page.$('#type-arr')
expect(await typeArr.text()).toBe('arr: ["a","b","c"]')
const typeObj = await page.$('#type-obj')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await typeObj.text()).toBe('obj: {"arr":[1,2,3],"num":0,"str":"obj str"}')
}
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
expect(await typeObj.text()).toBe('obj: {"str":"obj str","num":0,"arr":[1,2,3]}')
}
const typeFn = await page.$('#type-fn')
expect(await typeFn.text()).toBe('fn: fn res')
})
})
\ No newline at end of file
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view class="page">
<ArrayLiteral :str="str" :num='num' :bool='bool' :arr='arr' :obj='obj' :fn='fn' />
<ObjectLiteral :str="str" :num='num' :bool='bool' :arr='arr' :fn='fn' />
<TypeProps :str="str" :num='num' :bool='bool' :arr='arr' :obj='obj' :fn='fn' />
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup>
import ArrayLiteral from './array-literal.uvue';
import ObjectLiteral from './object-literal.uvue';
import TypeProps from './type-props.uvue';
const str = ref('default str')
const num = ref(0)
const bool = ref(false)
const arr = reactive(['a', 'b', 'c'])
const obj = reactive({ str: 'obj str', num: 0, arr: [1, 2, 3] })
const fn = () : string => 'fn res'
</script>
\ No newline at end of file
<template>
<view>
<text class="bold uni-common-mt uni-common-mb">object literal</text>
<text class="uni-common-mb" id="object-literal-str">str: {{ str }}</text>
<text class="uni-common-mb" id="object-literal-num">num: {{ num }}</text>
<text class="uni-common-mb" id="object-literal-bool">bool: {{ bool }}</text>
<text class="uni-common-mb" id="object-literal-arr">arr: {{ JSON.stringify(arr) }}</text>
<text class="uni-common-mb" id="object-literal-obj">obj: {{ JSON.stringify(obj) }}</text>
<text class="uni-common-mb" id="object-literal-fn">fn: {{ fn() }}</text>
</view>
</template>
<script setup>
defineProps({
str: String,
num: Number,
bool: {
type: Boolean,
default: true
},
arr: {
type: Array as PropType<string[]>,
default: () : string[] => [] as string[]
},
obj: {
type: Object as PropType<UTSJSONObject>,
default: () : UTSJSONObject => ({ a: 1 })
},
fn: {
type: Function as PropType<() => string>,
default: () : string => ''
}
})
</script>
\ No newline at end of file
<template>
<view>
<text class="bold uni-common-mt uni-common-mb">type props</text>
<text class="uni-common-mb" id="type-str">str: {{ str }}</text>
<text class="uni-common-mb" id="type-num">num: {{ num }}</text>
<text class="uni-common-mb" id="type-bool">bool: {{ bool }}</text>
<text class="uni-common-mb" id="type-arr">arr: {{ JSON.stringify(arr) }}</text>
<text class="uni-common-mb" id="type-obj">obj: {{ JSON.stringify(obj) }}</text>
<text id="type-fn">fn: {{ fn() }}</text>
</view>
</template>
<script setup>
defineProps<{
str : String,
num : Number,
bool : Boolean,
arr : PropType<string[]>,
obj : PropType<UTSJSONObject>,
fn : PropType<() => string>
}>()
</script>
\ No newline at end of file
<template>
<view>
<slot name="header" :msg="msg"></slot>
<slot :num="num"></slot>
<slot name="footer" :arr="arr"></slot>
</view>
</template>
<script setup>
const msg = ref('foo msg')
const num = ref<number>(0)
const arr = ref<string[]>(['a', 'b', 'c'])
defineSlots<{
default(props : { msg : string }) : any,
header(props : { num : string }) : any,
footer(props : { arr : string[] }) : any
}>()
</script>
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/basic/define-slots/define-slots'
describe('defineSlots', () => {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const slotHeader = await page.$('#slot-header')
expect(await slotHeader.text()).toBe('header slot msg: foo msg')
const slotContent = await page.$('#slot-default')
expect(await slotContent.text()).toBe('default slot num: 0')
const slotFooter = await page.$('#slot-footer')
expect(await slotFooter.text()).toBe('footer slot arr: ["a","b","c"]')
})
})
\ No newline at end of file
<template>
<view class="page">
<Foo>
<template #header="{msg}">
<text id="slot-header">header slot msg: {{msg}}</text>
</template>
<template #default="{num}">
<text id="slot-default" class="uni-common-mt">default slot num: {{num}}</text>
</template>
<template #footer="{arr}">
<text id="slot-footer" class="uni-common-mt">footer slot arr: {{JSON.stringify(arr)}}</text>
</template>
</Foo>
</view>
</template>
<script setup>
import Foo from './Foo.uvue'
</script>
\ No newline at end of file
<template>
<view>
<text id="attrs-class">attrs.class: {{attrs['class']}}</text>
<text id="attrs-msg" class='uni-common-mt'>attrs.msg: {{attrs['msg']}}</text>
</view>
</template>
<script setup>
import { useAttrs } from 'vue'
const attrs = useAttrs()
</script>
<style>
.foo {
padding: 10px;
background-color: #09c;
}
</style>
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/basic/use-attrs/use-attrs'
describe('useAttrs', () => {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const attrsClass = await page.$('#attrs-class')
expect(await attrsClass.text()).toBe('attrs.class: foo')
const attrsMsg = await page.$('#attrs-msg')
expect(await attrsMsg.text()).toBe('attrs.msg: msg')
})
})
\ No newline at end of file
<template>
<view class="page">
<Foo class="foo" msg="msg">
</Foo>
</view>
</template>
<script setup>
import Foo from './Foo.uvue'
</script>
\ No newline at end of file
<template>
<view class="page">
<slot name="header" :num="num"></slot>
<slot :msg="msg"></slot>
<slot name="footer" :arr="arr"></slot>
<text id="check-use-slots-res" class="uni-common-mt">check useSlots result: {{ checkUseSlotsRes }}</text>
<button class="check-use-slots-btn uni-common-mt" @click="checkUseSlots">
check useSlots
</button>
</view>
</template>
<script setup>
const num = ref<number>(0);
const msg = ref('default msg');
const arr = ref<string[]>(['a', 'b', 'c']);
const slots = defineSlots<{
default(props : { msg : string }) : any;
header(props : { num : number }) : any;
footer(props : { arr : string[] }) : any;
}>();
const slotsByUseSlots = useSlots();
const checkUseSlotsRes = ref(false);
const checkUseSlots = () => {
checkUseSlotsRes.value =
slots === slotsByUseSlots &&
slotsByUseSlots['default'] !== null &&
slotsByUseSlots['header'] !== null &&
slotsByUseSlots['footer'] !== null;
};
</script>
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/basic/use-slots/use-slots'
describe('useSlots', () => {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const slotHeader = await page.$('#slot-header')
expect(await slotHeader.text()).toBe('header slot num: 0')
const slotContent = await page.$('#slot-default')
expect(await slotContent.text()).toBe('default slot msg: default msg')
const slotFooter = await page.$('#slot-footer')
expect(await slotFooter.text()).toBe('footer slot arr: ["a","b","c"]')
const checkUseSlotsRes = await page.$('#check-use-slots-res')
expect(await checkUseSlotsRes.text()).toBe('check useSlots result: false')
const checkUseSlotsBtn = await page.$('.check-use-slots-btn')
await checkUseSlotsBtn.tap()
expect(await checkUseSlotsRes.text()).toBe('check useSlots result: true')
})
})
\ No newline at end of file
<template>
<Foo>
<template #header="{num}">
<text id="slot-header">header slot num: {{num}}</text>
</template>
<template #default="{msg}">
<text id="slot-default" class="uni-common-mt">default slot msg: {{msg}}</text>
</template>
<template #footer="{arr}">
<text id="slot-footer" class="uni-common-mt">footer slot arr: {{JSON.stringify(arr)}}</text>
</template>
</Foo>
</template>
<script setup>
import Foo from './Foo.uvue'
</script>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册