Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/core/test/unit/html/NodeProcessor.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_EXPECTED = `
</panel>
`;

export const PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_WARN_MSG = "panel has a header slot, 'header' attribute has no effect.";

export const PROCESS_PANEL_HEADER_NO_OVERRIDE = `
<panel header="# Lorem ipsum" alt="**strong alt**">
<div slot="header">
Expand Down Expand Up @@ -186,6 +188,9 @@ export const PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_EXPECTED = `
</popover>
`;

export const PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_HEADER_WARN_MSG = "popover has a header slot, 'header' attribute has no effect.";
export const PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_CONTENT_WARN_MSG = "popover has a content slot, 'content' attribute has no effect.";

/*
* Tooltips
*/
Expand Down Expand Up @@ -317,4 +322,6 @@ export const PROCESS_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY_EXPECTED = `
</dropdown>
`;

export const PROCESS_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY_WARN_MSG = "dropdown has a header slot, 'header' attribute has no effect.";

/* eslint-enable max-len */
17 changes: 17 additions & 0 deletions packages/core/test/unit/html/NodeProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ import path from 'path';
import cheerio from 'cheerio';
import htmlparser from 'htmlparser2';
import * as testData from './NodeProcessor.data';
import * as logger from '../../../src/utils/logger';
import { Context } from '../../../src/html/Context';
import { shiftSlotNodeDeeper, transformOldSlotSyntax } from '../../../src/html/vueSlotSyntaxProcessor';
import { getNewDefaultNodeProcessor } from '../utils/utils';
import { MbNode, parseHTML } from '../../../src/utils/node';

jest.mock('../../../src/utils/logger', () => ({
warn: jest.fn(),
}));

beforeEach(() => {
jest.clearAllMocks();
});

/**
* Runs the processNode or postProcessNode method of NodeProcessor on the provided
* template, verifying it with the expected result.
Expand Down Expand Up @@ -42,12 +51,15 @@ const processAndVerifyTemplate = (template: string, expectedTemplate: string, po
};

test('processNode processes panel attributes and inserts into dom as slots correctly', () => {
const warnSpy = jest.spyOn(logger, 'warn');
processAndVerifyTemplate(testData.PROCESS_PANEL_ATTRIBUTES,
testData.PROCESS_PANEL_ATTRIBUTES_EXPECTED);
processAndVerifyTemplate(testData.PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY,
testData.PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_EXPECTED);
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_WARN_MSG);
processAndVerifyTemplate(testData.PROCESS_PANEL_HEADER_NO_OVERRIDE,
testData.PROCESS_PANEL_HEADER_NO_OVERRIDE_EXPECTED);
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_WARN_MSG);
});

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

test('processNode processes popover attributes and inserts into dom as slots correctly', () => {
const warnSpy = jest.spyOn(logger, 'warn');
processAndVerifyTemplate(testData.PROCESS_POPOVER_ATTRIBUTES,
testData.PROCESS_POPOVER_ATTRIBUTES_EXPECTED);
processAndVerifyTemplate(testData.PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE,
testData.PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_EXPECTED);
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_HEADER_WARN_MSG);
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_CONTENT_WARN_MSG);
});

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

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

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