clientDB-api.test.js 3.7 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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 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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
describe('pages/clientDB/clientDB-api/clientDB-api.nvue', () => {

	let page
	beforeAll(async () => {
		// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
		page = await program.reLaunch('/pages/clientDB/clientDB-api/clientDB-api')
		if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
			await page.waitFor(1000)
		}
		if (process.env.UNI_PLATFORM === "mp-weixin") {
			await page.waitFor(1000);//微信等待
		}
		page = await program.currentPage()
	})
	
	beforeEach(async()=>{
		jest.setTimeout(30000)
		return false
	})

	it('查图书book表的数据', async () => {
		expect.assertions(1);
		const bookData = await page.callMethod('getData', 'book')
		expect(bookData.length).toBe(4)
	})

	it('查订单order表的数据', async () => {
		expect.assertions(1);
		const orderData = await page.callMethod('getData', 'order')
		expect(orderData.length).not.toBeUndefined();
	})

	it('分页查图书book表的数据', async () => {
		//expect.assertions(1);
		//获取页码
		const numBox1 = await page.$('.num-box1')
		
		const pageSize = await numBox1.property('value')
		console.log("pageSize: ",pageSize);
		//获取当前页
		const numBox2 = await page.$('.num-box2')
		const pageCurrent = await numBox2.property('value')
		console.log("pageCurrent: ",pageCurrent);

		if (pageSize === 1 && pageCurrent == 2) {
			const orderData = await page.callMethod('getPageData', 'order')
			expect(orderData.length).toBe(2)
		}
		
		
		//增加页码
		const numBox1Add = await numBox1.$('.uni-numbox__plus')
		await numBox1Add.tap()
		await page.waitFor(1000)
		const pageSizeAfter = await page.data('pageSize')
		
		//增加每页查询数量
		const numBox2Add = await numBox2.$('.uni-numbox__plus')
		await numBox2Add.tap()
		await page.waitFor(1000)
		const pageCurrentAfter = await page.data('pageCurrent')
		
		const bookData = await page.callMethod('getPageData')
		
	})


	it('联表查询订单和图书', async () => {
		expect.assertions(1);
		const orderBookData = await page.callMethod('getOrder')
		expect(orderBookData.length).not.toBeUndefined();
	})

	it('查询一本图书数据', async () => {
		const getOneBook = await page.callMethod('getOneBook')
		expect(getOneBook).toEqual({
			"_id": "1",
			"author": "吴承恩",
			"title": "西游记"
		});
	})

	it('查询结果返回总数', async () => {
		const getBookHasCount = await page.callMethod('getBookHasCount')
		expect(getBookHasCount.count).toEqual(4)
	})

	it('仅查询图书数据的书名', async () => {
		const getBookTitle = await page.callMethod('getBookTitle')
		const aTitleRecord = {
			_id: '1',
			title: '西游记'
		};
		expect(getBookTitle).toContainEqual(aTitleRecord);
	})

	it('获得被设置别名的数据', async () => {
		const getBookAs = await page.callMethod('getBookAs')
		const aBookAsRecord = {
			_id: '1',
			title: '西游记',
			book_author: '吴承恩'
		};
		expect(getBookAs).toContainEqual(aBookAsRecord);
	})

	it('按质量升序', async () => {
		await page.waitFor(500)
		const quantityData = await page.callMethod('getOrderOrderBy',
			'quantity asc')
		expect(quantityData.length).not.toBeUndefined();
	})

	it('按创建时间降序', async () => {
		const createDateData = await page.callMethod('getOrderOrderBy',
			'create_date desc')
		expect(createDateData.length).not.toBeUndefined();
	})

	it('质量相同时,按创建时间降序', async () => {
		const resData = await page.callMethod(
			'getOrderOrderBy',
			'quantity asc, create_date desc'
		)
		expect(resData.length).not.toBeUndefined();
	})
	
	it('查询树形数据', async () => {
		const treeData = await page.callMethod('getTreeFn')
		const children = treeData[0].children
		expect(children).not.toBeUndefined();
	})


})