Skip to content

Commit 5f9790e

Browse files
author
Jesse Haigh
committed
tests for line wrapping
1 parent f61d179 commit 5f9790e

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tests/unit/components/ContentNode/CodeListing.spec.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,70 @@ describe('CodeListing', () => {
302302

303303
expect(wrapper.classes()).toContain('single-line');
304304
});
305+
306+
it('does not wrap when wrap=0', async () => {
307+
const wrapper = shallowMount(CodeListing, {
308+
propsData: {
309+
syntax: 'swift',
310+
content: ['let foo = "bar"'],
311+
wrap: 0,
312+
},
313+
});
314+
await flushPromises();
315+
316+
expect(wrapper.classes()).not.toContain('is-wrapped');
317+
318+
const style = wrapper.attributes('style') || '';
319+
expect(style).not.toMatch(/--wrap-ch:\s*\d+/);
320+
});
321+
322+
it('wraps when wrap>0 and exposes the width in style', async () => {
323+
const wrapper = shallowMount(CodeListing, {
324+
propsData: {
325+
syntax: 'swift',
326+
content: ['let foo = "bar"'],
327+
wrap: 80,
328+
},
329+
});
330+
await flushPromises();
331+
332+
expect(wrapper.classes()).toContain('is-wrapped');
333+
334+
const style = wrapper.attributes('style') || '';
335+
expect(style).toMatch(/--wrap-ch:\s*80\b/);
336+
});
337+
338+
it('reacts when wrap changes', async () => {
339+
const wrapper = shallowMount(CodeListing, {
340+
propsData: {
341+
syntax: 'swift',
342+
content: ['let foo = "bar"'],
343+
wrap: 80,
344+
},
345+
});
346+
await flushPromises();
347+
348+
expect(wrapper.classes()).toContain('is-wrapped');
349+
350+
let style = wrapper.attributes('style') || '';
351+
expect(style).toMatch(/--wrap-ch:\s*80\b/);
352+
353+
await wrapper.setProps({ wrap: 0 });
354+
style = wrapper.attributes('style') || '';
355+
expect(wrapper.classes()).not.toContain('is-wrapped');
356+
expect(style).not.toMatch(/--wrap-ch:\s*\d+/);
357+
});
358+
359+
it('treats negative wrap as no-wrap', async () => {
360+
const wrapper = shallowMount(CodeListing, {
361+
propsData: {
362+
syntax: 'swift',
363+
content: ['let foo = "bar"'],
364+
wrap: -5,
365+
},
366+
});
367+
await flushPromises();
368+
369+
expect(wrapper.classes()).not.toContain('is-wrapped');
370+
});
305371
});

0 commit comments

Comments
 (0)