unicloud-db-demo.test.js 4.1 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6
describe('pages/clientDB/unicloud-db-demo/unicloud-db-demo', () => {

	let page
	beforeAll(async () => {
		// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
		page = await program.reLaunch('/pages/clientDB/unicloud-db-demo/unicloud-db-demo')
A
Anne_LXM 已提交
7
		await page.waitFor('view')
study夏羽's avatar
study夏羽 已提交
8
	})
A
Anne_LXM 已提交
9 10
	it("", async () => {
		// expect.assertions(1);
study夏羽's avatar
study夏羽 已提交
11
		const count = await page.data('getcount')
A
Anne_LXM 已提交
12 13 14 15 16
		expect(count).toBeTruthy()
		await page.callMethod('add')
	})
	it("", async () => {
		// const getDataList = await page.data('dataList')
A
Anne_LXM 已提交
17
		// expect(await getDataList.length).toBeGreaterThanOrEqual(1);
A
Anne_LXM 已提交
18
		await page.callMethod('remove')
study夏羽's avatar
study夏羽 已提交
19 20
	})
	it("", async () => {
A
Anne_LXM 已提交
21
		await page.callMethod('update')
study夏羽's avatar
study夏羽 已提交
22 23
	})
	it("", async () => {
A
Anne_LXM 已提交
24
		await page.callMethod('getFn')
study夏羽's avatar
study夏羽 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
	})
	it("只查一条数据", async () => {
		//开启只查一条
		const swGetone = await page.$('.switch-getone')
		await swGetone.tap()
		await page.waitFor(500)
		const getoneBool = await page.data('getone')
		expect.assertions(1);
		expect(getoneBool).toBeTruthy();
		//关闭只查一条
		await swGetone.tap()
		await page.waitFor(500)
	})
	it("数据翻页-replace", async () => {
		expect.assertions(3);
		//判断类型为翻页加载
		const replace = await page.data('pageData')
		expect(replace).toBe('replace')
		//增加当前页码
		const pageCurrentBefore = await page.data('pageCurrent')
		const numBox1 = await page.$('.num-box1')
		const numboxAdd1 = await numBox1.$('.uni-numbox__plus')
		await numboxAdd1.tap()
		await page.waitFor(500)
		//获取增加后的页码
		const pageCurrentAfter = await page.data('pageCurrent')
		expect(pageCurrentAfter).toBeGreaterThanOrEqual(pageCurrentBefore);//大于/toBeGreaterThan
		//增加当前每页数量
		const pageSizeBefore = await page.data('pageSize')
		const numBox2 = await page.$('.num-box2')
		const numboxAdd2 = await numBox2.$('.uni-numbox__plus')
		await numboxAdd2.tap()
		await page.waitFor(500)
		//增加每页数据数量
		const pageSizeAfter = await page.data('pageSize')
		expect(pageSizeAfter).toBeGreaterThanOrEqual(pageSizeBefore);//大于
	})

	it("追加数据-add", async () => {
		//改变分页策略为add
A
Anne_LXM 已提交
65 66
		// const pageCheckbox = await page.$('.page-checkbox')
		await page.setData({"pageData": "add"})
Anne_LXM's avatar
Anne_LXM 已提交
67
		// console.log('pageData---add: ',await page.data('pageData'));
study夏羽's avatar
study夏羽 已提交
68 69 70 71 72 73 74 75 76 77 78
		const isAdd = await page.waitFor(async()=>{
			const addText = await page.data('pageData')
			return addText === 'add'
		})
		if(isAdd){//加载更多
			/* if (process.env.UNI_PLATFORM === "mp-weixin") {
				const toLoadMore = await page.$('.toLoadMore')
				const loadMore = await toLoadMore.$('.loadMore')
				await loadMore.tap()
				await page.waitFor(300)
			} */
A
Anne_LXM 已提交
79
			if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM.startsWith("app")) {
study夏羽's avatar
study夏羽 已提交
80
				const loadMore = await page.$('.loadMore')
Anne_LXM's avatar
Anne_LXM 已提交
81
				// console.log('loadMore: ',loadMore);
A
Anne_LXM 已提交
82
				// await page.waitFor(300)
study夏羽's avatar
study夏羽 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
				await loadMore.tap()
				await page.waitFor(300)
			}
		}
		//每页数据数量减去1
		const pageSizeSubBefore = await page.data('pageSize')
		const numBox2 = await page.$('.num-box2')
		const numboxMin2 = await numBox2.$('.uni-numbox__minus')
		await numboxMin2.tap()
		await page.waitFor(500)
		//减少数据数量,由3页变为2页
		const pageSizeSubAfter = await page.data('pageSize')
		expect(pageSizeSubAfter).toBeLessThanOrEqual(pageSizeSubBefore);//小于
	})
	it("设置排序字段-orderBy", async () => {
		await page.setData({"orderby": 'create_date asc'})
	})
	it("是否查询总数据条数", async () => {
		const swGetcount = await page.$('.switch-getcount')
		await swGetcount.tap()
		await page.waitFor(500)
		const getcountBool = await page.data('getcount')
		expect.assertions(1);
		expect(getcountBool).toBeFalsy();
	})
	it("指定要查询的字段", async () => {
		expect.assertions(1);
		const arr =  [ 'book_id', 'create_date', 'quantity' ] 
		const getFields = await page.data('fields')
		expect(getFields).toEqual(arr);
		//指定字段create_date
		const fieldCheckbox = await page.$('.field-checkbox')
		await fieldCheckbox.setData({
			field: ['create_date'],
		})
	})
})