From 55c93003ea39d0825ad255e1aeeeff6c147b05e5 Mon Sep 17 00:00:00 2001 From: Rudolf Tucek Date: Thu, 28 Oct 2021 20:17:46 +0200 Subject: [PATCH] Add tests for QueryBuilderChild --- tests/unit/query-builder-child.spec.ts | 86 ++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/unit/query-builder-child.spec.ts diff --git a/tests/unit/query-builder-child.spec.ts b/tests/unit/query-builder-child.spec.ts new file mode 100644 index 0000000..5193b8e --- /dev/null +++ b/tests/unit/query-builder-child.spec.ts @@ -0,0 +1,86 @@ +import { shallowMount } from '@vue/test-utils'; +import Vue, { Component as VueComponent } from 'vue'; +import QueryBuilderChild from '@/QueryBuilderChild.vue'; +import { + QueryBuilderConfig, Rule, RuleDefinition, RuleSet, +} from '@/types'; +import Component from '../components/Component.vue'; + +interface QueryBuilderChildInterface extends Vue { + component: VueComponent, + definition: RuleDefinition | null, + ruleDefinition: RuleDefinition | null, +} + +describe('Testing QueryBuilderChild', () => { + const config: QueryBuilderConfig = { + operators: [ + { + name: 'AND', + identifier: 'AND', + }, + { + name: 'OR', + identifier: 'OR', + }, + ], + rules: [ + { + identifier: 'txt', + name: 'Text Selection', + component: Component, + initialValue: '', + }, + { + identifier: 'num', + name: 'Number Selection', + component: Component, + initialValue: 10, + }, + ], + dragging: { + animation: 300, + disabled: false, + ghostClass: 'ghost', + }, + }; + + it('tests if QueryBuilderChild handles rule query', () => { + const query: Rule = { + identifier: 'txt', + value: 'A', + }; + + const child = shallowMount(QueryBuilderChild, { + propsData: { + config: { ...config }, + query: { ...query }, + }, + }); + + expect((child.vm as QueryBuilderChildInterface).component.name).toBe('QueryBuilderRule'); + expect((child.vm as QueryBuilderChildInterface).definition).not.toBeNull(); + expect((child.vm as QueryBuilderChildInterface).ruleDefinition).not.toBeNull(); + }); + + it('tests if QueryBuilderChild handles group query', () => { + const query: RuleSet = { + operatorIdentifier: 'AND', + children: [{ + identifier: 'txt', + value: 'X', + }], + }; + + const child = shallowMount(QueryBuilderChild, { + propsData: { + config: { ...config }, + query: { ...query }, + }, + }); + + expect((child.vm as QueryBuilderChildInterface).component.name).toBe('QueryBuilderGroup'); + expect((child.vm as QueryBuilderChildInterface).definition).toBeNull(); + expect((child.vm as QueryBuilderChildInterface).ruleDefinition).toBeNull(); + }); +});