unicloud-db-demo.test.js 4.2 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 9 10 11 12 13 14 15 16 17 18
	})

	it("增-删", async () => {
		const count = await page.data('getcount')
		console.log("count: ",count);
		/* expect.assertions(1);
		const count = await page.data('getcount')
		expect(count).toBeTruthy(); */
		const addData = await page.callMethod('add')
		await page.waitFor(500)
		const getDataList = await page.data('dataList')
A
Anne_LXM 已提交
19 20
		// console.log("getDataList: ",getDataList);
		// expect(await getDataList.length).toBeGreaterThanOrEqual(1);
study夏羽's avatar
study夏羽 已提交
21 22 23 24 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
		const removeData = await page.callMethod('remove')
	})


	it("", async () => {
		const updateData = await page.callMethod('update')
	})

	it("", async () => {
		const getFnData = await page.callMethod('getFn')
	})

	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
		const pageCheckbox = await page.$('.page-checkbox')
		const addSet = await page.setData({"pageData": "add"})
		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 已提交
93
			if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM.startsWith("app")) {
study夏羽's avatar
study夏羽 已提交
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
				const loadMore = await page.$('.loadMore')
				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).toContain('book_id');
		expect(getFields).toEqual(arr);
		//指定字段create_date
		const fieldCheckbox = await page.$('.field-checkbox')
		await fieldCheckbox.setData({
			field: ['create_date'],
		})
	})

})