Skip to content

Commit 8aa6b0b

Browse files
feat: DLT-3590 add package support for redesigned docs (#1404)
1 parent 6d043b9 commit 8aa6b0b

16 files changed

Lines changed: 452 additions & 252 deletions

File tree

packages/combinator/src/components/combinator.test.js

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,29 @@ import { expect } from 'vitest';
44
import { shallowMount } from '@vue/test-utils';
55
import { nextTick } from 'vue';
66
import { getSupportedComponents } from '@/src/lib/test/utils_test';
7-
import { DtInput, DtToggle } from '@dialpad/dialtone-vue';
7+
import { DtButton, DtCard, DtInput, DtToggle } from '@dialpad/dialtone-vue';
88
import allDocs from '@/node_modules/@dialpad/dialtone-vue/dist/component-documentation.json';
9+
import variants from '@/src/variants/variants';
910

1011
const documentation = allDocs;
12+
const buttonDoc = allDocs.find(d => d.displayName === 'DtButton');
13+
const cardDoc = allDocs.find(d => d.displayName === 'DtCard');
1114
const toggleDoc = allDocs.find(d => d.displayName === 'DtToggle');
1215
const inputDoc = allDocs.find(d => d.displayName === 'DtInput');
16+
const variantBank = variants();
17+
18+
function shallowMountCombinator (options) {
19+
return shallowMount(DtcCombinator, {
20+
...options,
21+
global: {
22+
...options.global,
23+
stubs: {
24+
...options.global?.stubs,
25+
teleport: false,
26+
},
27+
},
28+
});
29+
}
1330

1431
describe('combinator.vue test', function () {
1532
const testComponents = getSupportedComponents();
@@ -24,7 +41,7 @@ describe('combinator.vue test', function () {
2441
testComponents.forEach(component => {
2542
describe(`When mounted with component '${component.name}'`, function () {
2643
beforeEach(function () {
27-
wrapper = shallowMount(DtcCombinator, {
44+
wrapper = shallowMountCombinator({
2845
props: {
2946
component,
3047
documentation,
@@ -47,7 +64,7 @@ describe('combinator.vue test', function () {
4764
describe('v-model writeback', function () {
4865
describe('boolean modelValue (DtToggle)', function () {
4966
beforeEach(function () {
50-
wrapper = shallowMount(DtcCombinator, {
67+
wrapper = shallowMountCombinator({
5168
props: {
5269
component: DtToggle,
5370
documentation: toggleDoc,
@@ -83,7 +100,7 @@ describe('combinator.vue test', function () {
83100

84101
describe('string modelValue (DtInput)', function () {
85102
beforeEach(function () {
86-
wrapper = shallowMount(DtcCombinator, {
103+
wrapper = shallowMountCombinator({
87104
props: {
88105
component: DtInput,
89106
documentation: inputDoc,
@@ -118,9 +135,93 @@ describe('combinator.vue test', function () {
118135
});
119136
});
120137

138+
describe('component changes', function () {
139+
beforeEach(function () {
140+
wrapper = shallowMountCombinator({
141+
props: {
142+
component: DtButton,
143+
documentation: buttonDoc,
144+
variants: variantBank.DtButton,
145+
},
146+
});
147+
});
148+
149+
afterEach(function () {
150+
wrapper.unmount();
151+
});
152+
153+
it('resets the active preset and options when the target component changes', async function () {
154+
wrapper.vm.updateVariant('icon only');
155+
await nextTick();
156+
157+
await wrapper.setProps({
158+
component: DtCard,
159+
documentation: cardDoc,
160+
variants: variantBank.DtCard,
161+
});
162+
await nextTick();
163+
164+
const renderer = wrapper.findComponent({ name: 'DtcRenderer' });
165+
166+
expect(wrapper.vm.selectedVariant).toBe('default');
167+
expect(renderer.props('options').slots.content).toBe(
168+
variantBank.DtCard.default.slots.content.initialValue,
169+
);
170+
});
171+
});
172+
173+
describe('fullscreen layout', function () {
174+
let host;
175+
176+
beforeEach(function () {
177+
document.documentElement.setAttribute('data-overlayscrollbars', '');
178+
host = document.createElement('div');
179+
document.body.appendChild(host);
180+
wrapper = shallowMountCombinator({
181+
attachTo: host,
182+
props: {
183+
component: DtButton,
184+
documentation: buttonDoc,
185+
fullScreen: true,
186+
variants: {},
187+
},
188+
});
189+
});
190+
191+
afterEach(function () {
192+
wrapper.unmount();
193+
host.remove();
194+
document.documentElement.removeAttribute('data-overlayscrollbars');
195+
document.documentElement.classList.remove('d-scrollbar-disabled', 'd-of-hidden');
196+
});
197+
198+
it('teleports the fullscreen playground to the document body', function () {
199+
const fullscreenPlayground = Array.from(document.body.children).find(child => {
200+
return child.classList.contains('dialtone-playground--fullscreen');
201+
});
202+
203+
expect(fullscreenPlayground).toBeTruthy();
204+
expect(host.querySelector('.dialtone-playground--fullscreen')).toBeNull();
205+
});
206+
207+
it('keeps the fullscreen shell below modal popover layers', function () {
208+
const fullscreenPlayground = document.body.querySelector('.dialtone-playground--fullscreen');
209+
210+
expect(fullscreenPlayground.classList.contains('d-zi-popover')).toBe(true);
211+
});
212+
213+
it('locks the OverlayScrollbars root while fullscreen', async function () {
214+
expect(document.documentElement.classList.contains('d-scrollbar-disabled')).toBe(true);
215+
216+
await wrapper.setProps({ fullScreen: false });
217+
218+
expect(document.documentElement.classList.contains('d-scrollbar-disabled')).toBe(false);
219+
});
220+
});
221+
121222
describe('control display settings', function () {
122223
beforeEach(function () {
123-
wrapper = shallowMount(DtcCombinator, {
224+
wrapper = shallowMountCombinator({
124225
props: {
125226
component: DtToggle,
126227
documentation: toggleDoc,
@@ -145,7 +246,7 @@ describe('combinator.vue test', function () {
145246

146247
expect(window.localStorage.getItem('dialtoneCombinatorControlsHideDeprecated')).toBe('false');
147248

148-
const nextWrapper = shallowMount(DtcCombinator, {
249+
const nextWrapper = shallowMountCombinator({
149250
props: {
150251
component: DtInput,
151252
documentation: inputDoc,

0 commit comments

Comments
 (0)