Skip to content

Commit f0759d3

Browse files
authored
Test logging calls in NodeProcessor
1 parent 69c8643 commit f0759d3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

packages/core/test/unit/html/NodeProcessor.data.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export const PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_EXPECTED = `
3636
</panel>
3737
`;
3838

39+
export const PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_WARN_MSG = "panel has a header slot, 'header' attribute has no effect.";
40+
3941
export const PROCESS_PANEL_HEADER_NO_OVERRIDE = `
4042
<panel header="# Lorem ipsum" alt="**strong alt**">
4143
<div slot="header">
@@ -186,6 +188,9 @@ export const PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_EXPECTED = `
186188
</popover>
187189
`;
188190

191+
export const PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_HEADER_WARN_MSG = "popover has a header slot, 'header' attribute has no effect.";
192+
export const PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_CONTENT_WARN_MSG = "popover has a content slot, 'content' attribute has no effect.";
193+
189194
/*
190195
* Tooltips
191196
*/
@@ -317,4 +322,6 @@ export const PROCESS_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY_EXPECTED = `
317322
</dropdown>
318323
`;
319324

325+
export const PROCESS_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY_WARN_MSG = "dropdown has a header slot, 'header' attribute has no effect.";
326+
320327
/* eslint-enable max-len */

packages/core/test/unit/html/NodeProcessor.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@ import path from 'path';
22
import cheerio from 'cheerio';
33
import htmlparser from 'htmlparser2';
44
import * as testData from './NodeProcessor.data';
5+
import * as logger from '../../../src/utils/logger';
56
import { Context } from '../../../src/html/Context';
67
import { shiftSlotNodeDeeper, transformOldSlotSyntax } from '../../../src/html/vueSlotSyntaxProcessor';
78
import { getNewDefaultNodeProcessor } from '../utils/utils';
89
import { MbNode, parseHTML } from '../../../src/utils/node';
910

11+
jest.mock('../../../src/utils/logger', () => ({
12+
warn: jest.fn(),
13+
}));
14+
15+
beforeEach(() => {
16+
jest.clearAllMocks();
17+
});
18+
1019
/**
1120
* Runs the processNode or postProcessNode method of NodeProcessor on the provided
1221
* template, verifying it with the expected result.
@@ -42,12 +51,15 @@ const processAndVerifyTemplate = (template: string, expectedTemplate: string, po
4251
};
4352

4453
test('processNode processes panel attributes and inserts into dom as slots correctly', () => {
54+
const warnSpy = jest.spyOn(logger, 'warn');
4555
processAndVerifyTemplate(testData.PROCESS_PANEL_ATTRIBUTES,
4656
testData.PROCESS_PANEL_ATTRIBUTES_EXPECTED);
4757
processAndVerifyTemplate(testData.PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY,
4858
testData.PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_EXPECTED);
59+
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_WARN_MSG);
4960
processAndVerifyTemplate(testData.PROCESS_PANEL_HEADER_NO_OVERRIDE,
5061
testData.PROCESS_PANEL_HEADER_NO_OVERRIDE_EXPECTED);
62+
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_WARN_MSG);
5163
});
5264

5365
test('processNode processes question attributes and inserts into dom as slots correctly', () => {
@@ -72,10 +84,13 @@ test('processNode processes quiz attributes and inserts into dom as slots correc
7284
});
7385

7486
test('processNode processes popover attributes and inserts into dom as slots correctly', () => {
87+
const warnSpy = jest.spyOn(logger, 'warn');
7588
processAndVerifyTemplate(testData.PROCESS_POPOVER_ATTRIBUTES,
7689
testData.PROCESS_POPOVER_ATTRIBUTES_EXPECTED);
7790
processAndVerifyTemplate(testData.PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE,
7891
testData.PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_EXPECTED);
92+
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_HEADER_WARN_MSG);
93+
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_CONTENT_WARN_MSG);
7994
});
8095

8196
test('processNode processes tooltip attributes and inserts into dom as slots correctly', () => {
@@ -118,8 +133,10 @@ test('processNode processes dropdown header attribute and inserts into DOM as he
118133
});
119134

120135
test('processNode processes dropdown with header slot taking priority over header attribute', () => {
136+
const warnSpy = jest.spyOn(logger, 'warn');
121137
processAndVerifyTemplate(testData.PROCESS_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY,
122138
testData.PROCESS_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY_EXPECTED);
139+
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY_WARN_MSG);
123140
});
124141

125142
test('markdown coverts inline colour syntax correctly', async () => {

0 commit comments

Comments
 (0)