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

fix(ui5-badge): correctly detect if default slot is provided #5334

Merged
merged 1 commit into from
Jun 7, 2022
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
5 changes: 4 additions & 1 deletion packages/base/src/util/isDefaultSlotProvided.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { getSlotName } from "./SlotsHelper.js";

const isDefaultSlotProvided = element => {
return Array.from(element.childNodes).filter(node => {
return node.nodeType !== Node.COMMENT_NODE
&& getSlotName(node) === "default"
&& (node.nodeType !== Node.TEXT_NODE || node.nodeValue.trim().length !== 0);
}).length;
}).length > 0;
};

export default isDefaultSlotProvided;
2 changes: 1 addition & 1 deletion packages/main/test/pages/Badge.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h2>Badges</h2>
<ui5-badge color-scheme="9">Required</ui5-badge><br>
<ui5-badge color-scheme="10">IN WAREHOUSE</ui5-badge><br>

<ui5-badge color-scheme="1">
<ui5-badge id="badgeWithTextAndIcon" color-scheme="1">
<ui5-icon name="accept" slot="icon"></ui5-icon>Done
</ui5-badge>
<ui5-badge id="badgeIconOnly" color-scheme="2">
Expand Down
9 changes: 7 additions & 2 deletions packages/main/test/specs/Badge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ describe("Badge rendering", async () => {
await browser.url(`http://localhost:${PORT}/test-resources/pages/Badge.html`);
});

it("tests label not rendered if not text content", async () => {
it("tests that label is rendered if there is text content", async () => {
const badgeLabel = await browser.$("#badgeWithTextAndIcon").shadow$(".ui5-badge-text");

assert.ok(await badgeLabel.isExisting(), "badge label tag should be rendered.");
});

it("tests that label is NOT rendered if there is only icon", async () => {
const badgeLabel = await browser.$("#badgeIconOnly").shadow$(".ui5-badge-text");

assert.ok(badgeLabel, "bagde label tag not rendered.");
assert.notOk(await badgeLabel.isExisting(), "badge label tag shouldn't be rendered.");
});
});