Skip to content

Commit 63e2523

Browse files
author
Jesse Haigh
committed
tests for line wrapping
1 parent 9f682a1 commit 63e2523

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
@@ -301,4 +301,70 @@ describe('CodeListing', () => {
301301

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

0 commit comments

Comments
 (0)