|
@@ -0,0 +1,104 @@
|
|
|
|
|
+import assert from 'node:assert/strict';
|
|
|
|
|
+import { readFileSync } from 'node:fs';
|
|
|
|
|
+import test from 'node:test';
|
|
|
|
|
+import { computed, reactive, ref, toRefs } from 'vue';
|
|
|
|
|
+
|
|
|
|
|
+// 执行页面本身的筛选逻辑,避免测试副本与实际请求参数脱节。
|
|
|
|
|
+const source = readFileSync(new URL('../src/views/subSystem/pipeNetwork/assetInfo/equipmentBase/index.vue', import.meta.url), 'utf8');
|
|
|
|
|
+const script = source.match(/<script setup>([\s\S]*?)<\/script>/)[1]
|
|
|
|
|
+ .replace(/^import[\s\S]*?from\s+["'][^"']+["'];?/gm, '')
|
|
|
|
|
+ .replace(/import\.meta\.env\.VITE_APP_BASE_API/g, '"/test-api"');
|
|
|
|
|
+
|
|
|
|
|
+const types = [
|
|
|
|
|
+ { id: 1, parentId: 0, typeName: '供水设备' },
|
|
|
|
|
+ { id: 2, parentId: 0, typeName: '排水设备' },
|
|
|
|
|
+ { id: 3, parentId: 0, typeName: '空大类' },
|
|
|
|
|
+ { id: 11, parentId: 1, typeName: '流量计' },
|
|
|
|
|
+ { id: 12, parentId: 1, typeName: '压力计' },
|
|
|
|
|
+ { id: 16, parentId: 2, typeName: '液位计' },
|
|
|
|
|
+ { id: 99, parentId: 90, typeName: '孤立类型' }
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
|
|
+function createPage(rootTypeId) {
|
|
|
|
|
+ const calls = [];
|
|
|
|
|
+ let page;
|
|
|
|
|
+ const bindings = {
|
|
|
|
|
+ computed, reactive, ref, toRefs,
|
|
|
|
|
+ onMounted() {},
|
|
|
|
|
+ getCurrentInstance: () => ({ proxy: { resetForm() {
|
|
|
|
|
+ Object.assign(page.queryParams.value, { equipmentCode: undefined, equipmentName: undefined, onlineStatus: undefined });
|
|
|
|
|
+ } } }),
|
|
|
|
|
+ useRoute: () => ({ query: { rootTypeId } }),
|
|
|
|
|
+ listEquipment: async (query) => { calls.push(query); return { records: [], total: 0 }; }
|
|
|
|
|
+ };
|
|
|
|
|
+ page = new Function(...Object.keys(bindings), `${script}
|
|
|
|
|
+ return { allTypeList, equipmentTypeTree, equipmentSubtypes, selectedCategoryId, queryParams, alarmOnly, selectCategory, selectEquipmentType, resetQuery, getList };`
|
|
|
|
|
+ )(...Object.values(bindings));
|
|
|
|
|
+ page.allTypeList.value = types;
|
|
|
|
|
+ return { page, calls };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+test('初始全部不限制设备类型,二级为空', async () => {
|
|
|
|
|
+ const { page, calls } = createPage();
|
|
|
|
|
+ await page.getList();
|
|
|
|
|
+ assert.equal(calls[0].equipmentTypeIds, undefined);
|
|
|
|
|
+ assert.equal(calls[0].equipmentTypeId, undefined);
|
|
|
|
|
+ assert.deepEqual(page.equipmentSubtypes.value, []);
|
|
|
|
|
+ assert.match(source, /type-category/);
|
|
|
|
|
+ assert.match(source, /type-chip/);
|
|
|
|
|
+ assert.doesNotMatch(source.split('<script setup>')[0], /v-model="queryParams.equipmentTypeId"/);
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+test('选择大类和二级立即查询,后端分页前过滤,保留其他条件', () => {
|
|
|
|
|
+ const { page, calls } = createPage();
|
|
|
|
|
+ Object.assign(page.queryParams.value, { pageNum: 5, equipmentName: '测试', onlineStatus: 0 });
|
|
|
|
|
+ page.alarmOnly.value = true;
|
|
|
|
|
+ page.selectCategory(1);
|
|
|
|
|
+ assert.deepEqual(page.equipmentSubtypes.value.map(item => item.id), [11, 12]);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeIds, '11,12');
|
|
|
|
|
+ assert.equal(calls.at(-1).pageNum, 1);
|
|
|
|
|
+ page.selectEquipmentType(12);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeId, 12);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentName, '测试');
|
|
|
|
|
+ assert.equal(calls.at(-1).onlineStatus, 0);
|
|
|
|
|
+ assert.equal(calls.at(-1).alarmStatus, 1);
|
|
|
|
|
+ page.selectEquipmentType(undefined);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeId, undefined);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeIds, '11,12');
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+test('切换一级清空旧二级,一级全部取消分类限制', () => {
|
|
|
|
|
+ const { page, calls } = createPage();
|
|
|
|
|
+ page.selectCategory(1);
|
|
|
|
|
+ page.selectEquipmentType(12);
|
|
|
|
|
+ page.selectCategory(2);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeId, undefined);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeIds, '16');
|
|
|
|
|
+ page.selectCategory(undefined);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeIds, undefined);
|
|
|
|
|
+ assert.deepEqual(page.equipmentSubtypes.value, []);
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+test('菜单范围始终保留,重置同时清空两级、常规条件和报警', () => {
|
|
|
|
|
+ const { page, calls } = createPage('1');
|
|
|
|
|
+ assert.deepEqual(page.equipmentTypeTree.value.map(item => item.id), [1]);
|
|
|
|
|
+ page.selectCategory(1);
|
|
|
|
|
+ page.selectEquipmentType(11);
|
|
|
|
|
+ page.queryParams.value.equipmentCode = 'TEST';
|
|
|
|
|
+ page.alarmOnly.value = true;
|
|
|
|
|
+ page.resetQuery();
|
|
|
|
|
+ assert.equal(page.selectedCategoryId.value, undefined);
|
|
|
|
|
+ assert.equal(calls.at(-1).rootTypeId, 1);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeIds, undefined);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeId, undefined);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentCode, undefined);
|
|
|
|
|
+ assert.equal(calls.at(-1).alarmStatus, undefined);
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+test('未分类按真实类型ID查询,空大类不能退化为全部数据', () => {
|
|
|
|
|
+ const { page, calls } = createPage();
|
|
|
|
|
+ page.selectCategory('__other__');
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeIds, '99');
|
|
|
|
|
+ page.selectCategory(3);
|
|
|
|
|
+ assert.equal(calls.at(-1).equipmentTypeIds, '-1');
|
|
|
|
|
+});
|