Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardise NodeProcessor.data.ts constant names #2483

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
88 changes: 48 additions & 40 deletions packages/core/test/unit/html/NodeProcessor.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,6 @@ export const PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY_EXPECTED = `

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">
This existing header slot should be preserved in favour over header attribute.
</div>
Header attribute should not be inserted under panel since there is both an alt attribute and header slot,
but should be deleted.
Alt attribute should be inserted under panel as slot.
</panel>
`;

export const PROCESS_PANEL_HEADER_NO_OVERRIDE_EXPECTED = `
<panel><template #_alt><p><strong>strong alt</strong></p>
</template>
<template #header><div>
This existing header slot should be preserved in favour over header attribute.
</div></template>
Header attribute should not be inserted under panel since there is both an alt attribute and header slot,
but should be deleted.
Alt attribute should be inserted under panel as slot.
</panel>
`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted this constant instead of the other one because this also tests for whether the alt attribute is processed correctly, which is tested for in the POST_PROCESS_PANEL_ID_ASSIGNED_USING_HEADER_SLOT test in lines 66 to 76


// Post Process

export const POST_PROCESS_PANEL_ID_ASSIGNED_USING_HEADER_SLOT = `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I'm missing something here, but it doesn't look like this one has an alt slot for it to test for it being inserted under panel as stated in your earlier comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:O You are right - I think I got confused by the text in the constant. Will delete the other constant then

Expand Down Expand Up @@ -92,18 +69,38 @@ export const PROCESS_QUESTION_ATTRIBUTES_EXPECTED = `
</question>
`;

export const PROCESS_QUESTION_ATTRIBUTES_NO_OVERRIDE = `
<question header="**header**" hint="**hint**" answer="**answer**">
export const PROCESS_QUESTION_HEADER_SLOT_TAKES_PRIORITY = `
<question header="**header**">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Since this text is overridden - maybe you can change the overridden text to "lorum ipsum" or something like in the other tests? This was confusing to me because I didn't realise the difference between what was overridden for a while.

Similar for hint & answer below

<template slot="header"></template>
<template slot="hint"></template>
<template slot="answer"></template>
</question>
`;

export const PROCESS_QUESTION_ATTRIBUTES_NO_OVERRIDE_EXPECTED = `
export const PROCESS_QUESTION_HEADER_SLOT_TAKES_PRIORITY_EXPECTED = `
<question>
<template #header></template>
</question>
`;

export const PROCESS_QUESTION_HINT_SLOT_TAKES_PRIORITY = `
<question hint="**hint**">
<template slot="hint"></template>
</question>
`;

export const PROCESS_QUESTION_HINT_SLOT_TAKES_PRIORITY_EXPECTED = `
<question>
<template #hint></template>
</question>
`;

export const PROCESS_QUESTION_ANSWER_SLOT_TAKES_PRIORITY = `
<question answer="**answer**">
<template slot="answer"></template>
</question>
`;

export const PROCESS_QUESTION_ANSWER_SLOT_TAKES_PRIORITY_EXPECTED = `
<question>
<template #answer></template>
</question>
`;
Expand All @@ -119,13 +116,13 @@ export const PROCESS_QOPTION_ATTRIBUTES_EXPECTED = `
</q-option>
`;

export const PROCESS_QOPTION_ATTRIBUTES_NO_OVERRIDE = `
export const PROCESS_QOPTION_REASON_SLOT_TAKES_PRIORITY = `
<q-option reason="**lorem ipsum**">
<template slot="reason"></template>
</q-option>
`;

export const PROCESS_QOPTION_ATTRIBUTES_NO_OVERRIDE_EXPECTED = `
export const PROCESS_QOPTION_REASON_SLOT_TAKES_PRIORITY_EXPECTED = `
<q-option>
<template #reason></template>
</q-option>
Expand All @@ -142,13 +139,13 @@ export const PROCESS_QUIZ_ATTRIBUTES_EXPECTED = `
</quiz>
`;

export const PROCESS_QUIZ_ATTRIBUTES_NO_OVERRIDE = `
export const PROCESS_QUIZ_INTRO_SLOT_TAKES_PRIORITY = `
<quiz intro="**lorem ipsum**">
<template slot="intro"></template>
</quiz>
`;

export const PROCESS_QUIZ_ATTRIBUTES_NO_OVERRIDE_EXPECTED = `
export const PROCESS_QUIZ_INTRO_SLOT_TAKES_PRIORITY_EXPECTED = `
<quiz>
<template #intro></template>
</quiz>
Expand All @@ -171,24 +168,35 @@ export const PROCESS_POPOVER_ATTRIBUTES_EXPECTED = `
</popover>
`;

export const PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE = `
<popover content="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel tellus elit."
header="_Lorem ipsum_">
export const PROCESS_POPOVER_HEADER_SLOT_TAKES_PRIORITY = `
<popover header="_Lorem ipsum_">
<div slot="header">Some header slot content that should not be overwritten</div>
<div slot="content">Some content slot that should not be overwritten</div>
Content and header attributes should not be inserted under panel as slots, but should be deleted.
Header attribute should not be inserted under panel as slot, but should be deleted.
</popover>
`;

export const PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_EXPECTED = `
export const PROCESS_POPOVER_HEADER_SLOT_TAKES_PRIORITY_EXPECTED = `
<popover>
<template #header><div>Some header slot content that should not be overwritten</div></template>
<template #content><div>Some content slot that should not be overwritten</div></template>
Content and header attributes should not be inserted under panel as slots, but should be deleted.
Header attribute should not be inserted under panel as slot, but should be deleted.
</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_CONTENT_SLOT_TAKES_PRIORITY = `
<popover content="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel tellus elit.">
<div slot="content">Some content slot that should not be overwritten</div>
Content attribute should not be inserted under panel as slot, but should be deleted.
</popover>
`;

export const PROCESS_POPOVER_CONTENT_SLOT_TAKES_PRIORITY_EXPECTED = `
<popover>
<template #content><div>Some content slot that should not be overwritten</div></template>
Content attribute should not be inserted under panel as slot, but should be deleted.
</popover>
`;
export const PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_CONTENT_WARN_MSG = "popover has a content slot, 'content' attribute has no effect.";

/*
Expand Down
25 changes: 14 additions & 11 deletions packages/core/test/unit/html/NodeProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,42 @@ test('processNode processes panel attributes and inserts into dom as slots corre
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', () => {
processAndVerifyTemplate(testData.PROCESS_QUESTION_ATTRIBUTES,
testData.PROCESS_QUESTION_ATTRIBUTES_EXPECTED);
processAndVerifyTemplate(testData.PROCESS_QUESTION_ATTRIBUTES_NO_OVERRIDE,
testData.PROCESS_QUESTION_ATTRIBUTES_NO_OVERRIDE_EXPECTED);
processAndVerifyTemplate(testData.PROCESS_QUESTION_HEADER_SLOT_TAKES_PRIORITY,
testData.PROCESS_QUESTION_HEADER_SLOT_TAKES_PRIORITY_EXPECTED);
processAndVerifyTemplate(testData.PROCESS_QUESTION_HINT_SLOT_TAKES_PRIORITY,
testData.PROCESS_QUESTION_HINT_SLOT_TAKES_PRIORITY_EXPECTED);
processAndVerifyTemplate(testData.PROCESS_QUESTION_ANSWER_SLOT_TAKES_PRIORITY,
testData.PROCESS_QUESTION_ANSWER_SLOT_TAKES_PRIORITY_EXPECTED);
});

test('processNode processes q-option attributes and inserts into dom as slots correctly', () => {
processAndVerifyTemplate(testData.PROCESS_QOPTION_ATTRIBUTES,
testData.PROCESS_QOPTION_ATTRIBUTES_EXPECTED);
processAndVerifyTemplate(testData.PROCESS_QOPTION_ATTRIBUTES_NO_OVERRIDE,
testData.PROCESS_QOPTION_ATTRIBUTES_NO_OVERRIDE_EXPECTED);
processAndVerifyTemplate(testData.PROCESS_QOPTION_REASON_SLOT_TAKES_PRIORITY,
testData.PROCESS_QOPTION_REASON_SLOT_TAKES_PRIORITY_EXPECTED);
});

test('processNode processes quiz attributes and inserts into dom as slots correctly', () => {
processAndVerifyTemplate(testData.PROCESS_QUIZ_ATTRIBUTES,
testData.PROCESS_QUIZ_ATTRIBUTES_EXPECTED);
processAndVerifyTemplate(testData.PROCESS_QUIZ_ATTRIBUTES_NO_OVERRIDE,
testData.PROCESS_QUIZ_ATTRIBUTES_NO_OVERRIDE_EXPECTED);
processAndVerifyTemplate(testData.PROCESS_QUIZ_INTRO_SLOT_TAKES_PRIORITY,
testData.PROCESS_QUIZ_INTRO_SLOT_TAKES_PRIORITY_EXPECTED);
});

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);
processAndVerifyTemplate(testData.PROCESS_POPOVER_HEADER_SLOT_TAKES_PRIORITY,
testData.PROCESS_POPOVER_HEADER_SLOT_TAKES_PRIORITY_EXPECTED);
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_HEADER_WARN_MSG);
processAndVerifyTemplate(testData.PROCESS_POPOVER_CONTENT_SLOT_TAKES_PRIORITY,
testData.PROCESS_POPOVER_CONTENT_SLOT_TAKES_PRIORITY_EXPECTED);
expect(warnSpy).toHaveBeenCalledWith(testData.PROCESS_POPOVER_ATTRIBUTES_NO_OVERRIDE_CONTENT_WARN_MSG);
});

Expand Down
Loading