提交 1bd26566 编写于 作者: 雪洛's avatar 雪洛

test: 测试与示例适配小程序

上级 33fa5acf
...@@ -76,7 +76,10 @@ describe('nodes-info', () => { ...@@ -76,7 +76,10 @@ describe('nodes-info', () => {
// #endif // #endif
it('test filelds', async () => { it('test filelds', async () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) { if (
process.env.uniTestPlatformInfo.startsWith('web') ||
process.env.uniTestPlatformInfo.startsWith('mp')
) {
expect(true).toBe(true) expect(true).toBe(true)
} else { } else {
const pageData = await page.data() const pageData = await page.data()
...@@ -85,7 +88,10 @@ describe('nodes-info', () => { ...@@ -85,7 +88,10 @@ describe('nodes-info', () => {
}) })
it('test node', async () => { it('test node', async () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) { if (
process.env.uniTestPlatformInfo.startsWith('web') ||
process.env.uniTestPlatformInfo.startsWith('mp')
) {
expect(true).toBe(true) expect(true).toBe(true)
} else { } else {
const pageData = await page.data() const pageData = await page.data()
......
...@@ -12,7 +12,9 @@ describe("getElementByIdForMultipleRootNode", () => { ...@@ -12,7 +12,9 @@ describe("getElementByIdForMultipleRootNode", () => {
expect(res).toBe(null); expect(res).toBe(null);
}); });
it("changeStyle", async () => { it("changeStyle", async () => {
if (!process.env.uniTestPlatformInfo.startsWith('mp')) {
await page.callMethod("changePageHeadBackgroundColor"); await page.callMethod("changePageHeadBackgroundColor");
}
await page.callMethod("changeTextColor"); await page.callMethod("changeTextColor");
await page.callMethod("changeViewStyle"); await page.callMethod("changeViewStyle");
await page.waitFor(500); await page.waitFor(500);
......
...@@ -11,7 +11,9 @@ describe("getElementById", () => { ...@@ -11,7 +11,9 @@ describe("getElementById", () => {
expect(res).toBe(null); expect(res).toBe(null);
}); });
it("changeStyle", async () => { it("changeStyle", async () => {
if (!process.env.uniTestPlatformInfo.startsWith('mp')) {
await page.callMethod("changePageHeadBackgroundColor"); await page.callMethod("changePageHeadBackgroundColor");
}
await page.callMethod("changeTextColor"); await page.callMethod("changeTextColor");
await page.callMethod("changeViewStyle"); await page.callMethod("changeViewStyle");
await page.waitFor(500); await page.waitFor(500);
......
...@@ -9,14 +9,12 @@ describe('ExtApi-UploadFile', () => { ...@@ -9,14 +9,12 @@ describe('ExtApi-UploadFile', () => {
return return
} }
const isUploadProjectFileSupported = !process.env.uniTestPlatformInfo.startsWith('mp')
let page; let page;
let res; let res;
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
await page.callMethod('jest_uploadFile');
await page.waitFor(2000);
res = await page.data('jest_result');
}); });
beforeEach(async () => { beforeEach(async () => {
...@@ -25,7 +23,12 @@ describe('ExtApi-UploadFile', () => { ...@@ -25,7 +23,12 @@ describe('ExtApi-UploadFile', () => {
}) })
}); });
if(isUploadProjectFileSupported) {
it('Check ', async () => { it('Check ', async () => {
await page.waitFor(600);
await page.callMethod('jest_uploadFile');
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true); expect(res).toBe(true);
}); });
...@@ -35,6 +38,7 @@ describe('ExtApi-UploadFile', () => { ...@@ -35,6 +38,7 @@ describe('ExtApi-UploadFile', () => {
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true) expect(res).toBe(true)
}); });
}
it('Check uni.env', async () => { it('Check uni.env', async () => {
await page.callMethod('jest_uploadFile_with_uni_env'); await page.callMethod('jest_uploadFile_with_uni_env');
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<text v-else class="uni-hello-addfile" @click="chooseImage">+ 选择图片</text> <text v-else class="uni-hello-addfile" @click="chooseImage">+ 选择图片</text>
</view> </view>
</view> </view>
<button @click="jest_uploadFile_with_uni_env">jest_uploadFile_with_uni_env</button>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
...@@ -105,7 +106,10 @@ ...@@ -105,7 +106,10 @@
}) })
}, },
jest_uploadFile_with_uni_env() { jest_uploadFile_with_uni_env() {
const filePath = `${uni.env.CACHE_PATH}/download/uni-app.png` /**
* 微信小程序只支持USER_DATA_PATH,且子目录未创建的情况下不能直接下载到子目录内
*/
const filePath = `${uni.env.USER_DATA_PATH}/uni-app.png`
uni.downloadFile({ uni.downloadFile({
url: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png", url: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
filePath: filePath, filePath: filePath,
......
...@@ -79,7 +79,7 @@ describe('Button.uvue', () => { ...@@ -79,7 +79,7 @@ describe('Button.uvue', () => {
}) })
it("checkUniButtonElement", async () => { it("checkUniButtonElement", async () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) { if (process.env.uniTestPlatformInfo.startsWith('mp')) {
expect(1).toBe(1) expect(1).toBe(1)
return return
} }
......
...@@ -14,18 +14,23 @@ beforeAll(async () => { ...@@ -14,18 +14,23 @@ beforeAll(async () => {
}) })
describe('Checkbox.uvue', () => { describe('Checkbox.uvue', () => {
const isMP = process.env.uniTestPlatformInfo.startsWith('mp')
it('change', async () => { it('change', async () => {
expect(await getData('value')).toEqual([]) expect(await getData('value')).toEqual([])
const cb1 = await page.$('.cb1') const cb1 = await page.$('.cb1')
await cb1.tap() await cb1.tap()
await page.waitFor(100)
expect(await getData('value')).toEqual(['cb', 'cb1']) expect(await getData('value')).toEqual(['cb', 'cb1'])
const cb = await page.$('.cb') const cb = await page.$('.cb')
await cb.tap() await cb.tap()
await page.waitFor(100)
expect(await getData('value')).toEqual(['cb1']) expect(await getData('value')).toEqual(['cb1'])
const cb2 = await page.$('.cb2') const cb2 = await page.$('.cb2')
await cb2.tap() await cb2.tap()
await page.waitFor(100)
expect(await getData('value')).toEqual(['cb1']) expect(await getData('value')).toEqual(['cb1'])
await cb1.tap() await cb1.tap()
await page.waitFor(100)
expect(await getData('value')).toEqual([]) expect(await getData('value')).toEqual([])
}) })
it('length', async () => { it('length', async () => {
...@@ -42,6 +47,29 @@ describe('Checkbox.uvue', () => { ...@@ -42,6 +47,29 @@ describe('Checkbox.uvue', () => {
}) })
expect(await cb.text()).toEqual('not selected') expect(await cb.text()).toEqual('not selected')
}) })
if(isMP) {
it('disabled', async () => {
const cb = await page.$('.cb2')
const disabled1 = await cb.property('disabled')
expect(disabled1).toBe(true)
await page.setData({
disabled: false,
})
const disabled2 = await cb.property('disabled')
expect(disabled2).toBe(false)
})
} else {
it('disabled', async () => {
const cb = await page.$('.cb2')
const disabled1 = await cb.attribute('disabled')
expect(disabled1).toBe(true + '')
await page.setData({
disabled: false,
})
const disabled2 = await cb.attribute('disabled')
expect(disabled2).toBe(false + '')
})
}
it('checked', async () => { it('checked', async () => {
const cb = await page.$('.cb') const cb = await page.$('.cb')
// TODO // TODO
...@@ -54,6 +82,7 @@ describe('Checkbox.uvue', () => { ...@@ -54,6 +82,7 @@ describe('Checkbox.uvue', () => {
const newValue2 = await cb.property('checked') const newValue2 = await cb.property('checked')
expect(newValue2.toString()).toBe(false + '') expect(newValue2.toString()).toBe(false + '')
}) })
if(!isMP) {
it('color', async () => { it('color', async () => {
const cb = await page.$('.cb') const cb = await page.$('.cb')
expect(await cb.attribute('color')).toBe('#007aff') expect(await cb.attribute('color')).toBe('#007aff')
...@@ -79,14 +108,6 @@ describe('Checkbox.uvue', () => { ...@@ -79,14 +108,6 @@ describe('Checkbox.uvue', () => {
}) })
expect(await cb.attribute('foreColor')).toBe('#63acfe') expect(await cb.attribute('foreColor')).toBe('#63acfe')
}) })
it('disabled', async () => {
const cb = await page.$('.cb2')
expect(await cb.attribute('disabled')).toBe(true + '')
await page.setData({
disabled: false,
})
expect(await cb.attribute('disabled')).toBe(false + '')
})
it('trigger UniCheckboxGroupChangeEvent', async () => { it('trigger UniCheckboxGroupChangeEvent', async () => {
const element = await page.$('.checkbox-item-0') const element = await page.$('.checkbox-item-0')
await element.tap() await element.tap()
...@@ -94,4 +115,5 @@ describe('Checkbox.uvue', () => { ...@@ -94,4 +115,5 @@ describe('Checkbox.uvue', () => {
const { testEvent } = await page.data() const { testEvent } = await page.data()
expect(testEvent).toBe(true) expect(testEvent).toBe(true)
}) })
}
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册