Skip to content

Commit 1321b49

Browse files
committed
Assert behaviour of GroupCtrlSlotProps with max-depth
1 parent 63b3149 commit 1321b49

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

tests/unit/max-depth.spec.ts

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import Sortable, {
66
import QueryBuilder from '@/QueryBuilder.vue';
77
import QueryBuilderGroup from '@/QueryBuilderGroup.vue';
88
import QueryBuilderChild from '@/QueryBuilderChild.vue';
9-
import { RuleSet, QueryBuilderConfig, Rule } from '@/types';
9+
import {
10+
RuleSet, QueryBuilderConfig, Rule, GroupCtrlSlotProps,
11+
} from '@/types';
1012
import Component from '../components/Component.vue';
1113

1214
interface QueryBuilderGroupInstance extends Vue {
1315
depth: number,
1416
maxDepthExeeded: boolean,
1517
dragOptions: SortableOptions,
18+
groupControlSlotProps: GroupCtrlSlotProps,
1619
}
1720

1821
interface GroupOptionsInstance extends GroupOptions {
@@ -150,6 +153,72 @@ describe('Testing max-depth behaviour', () => {
150153
expect(evQueryUpdate).toBeUndefined();
151154
});
152155

156+
it('verifies the behaviour of GroupCtrlSlotProps slot', () => {
157+
const createApp = () => mount(QueryBuilder, {
158+
propsData: {
159+
value: { ...value },
160+
config: { ...config },
161+
},
162+
scopedSlots: {
163+
groupControl: `
164+
<div
165+
slot-scope="props"
166+
class="slot-wrapper"
167+
>
168+
SLOT
169+
<select>
170+
<option
171+
v-for="rule in props.rules"
172+
:key="rule.identifier"
173+
:value="rule.identifier"
174+
v-text="rule.name"
175+
/>
176+
</select>
177+
<button
178+
@click="props.addRule('txt')"
179+
class="slot-new-rule"
180+
>
181+
Add Rule
182+
</button>
183+
<button
184+
v-if="! props.maxDepthExeeded"
185+
@click="props.newGroup"
186+
class="slot-new-group"
187+
>
188+
Add Group
189+
</button>
190+
</div>
191+
`,
192+
},
193+
});
194+
195+
let app = createApp();
196+
let group = app.findAllComponents(QueryBuilderGroup)
197+
.wrappers
198+
.filter(g => g.vm.$props.depth === 3)
199+
.shift() as Wrapper<QueryBuilderGroupInstance, Element>;
200+
expect(group.vm.groupControlSlotProps.maxDepthExeeded).toBeFalsy();
201+
// Assert button is present
202+
let button = group.find('.slot-new-group');
203+
expect(button.exists()).toBeTruthy();
204+
button.trigger('click');
205+
let evQueryUpdate = app.emitted('input');
206+
expect(evQueryUpdate).toHaveLength(1);
207+
208+
// Test leaf group
209+
app = createApp();
210+
group = app.findAllComponents(QueryBuilderGroup)
211+
.wrappers
212+
.filter(g => g.vm.$props.depth === 4)
213+
.shift() as Wrapper<QueryBuilderGroupInstance, Element>;
214+
expect(group.vm.groupControlSlotProps.maxDepthExeeded).toBeTruthy();
215+
// Assert button is absent
216+
button = group.find('.slot-new-group');
217+
expect(button.exists()).toBeFalsy();
218+
evQueryUpdate = app.emitted('input');
219+
expect(evQueryUpdate).toBeUndefined();
220+
});
221+
153222
it('prunes existing branches which are beyond the max-depth setting', async () => {
154223
const app = mount(QueryBuilder, {
155224
propsData: {

0 commit comments

Comments
 (0)