Skip to content

Commit

Permalink
fix(ui5-badge): correctly detect if default slot is provided (#5334)
Browse files Browse the repository at this point in the history
Fixes: #5328
  • Loading branch information
dimovpetar authored Jun 7, 2022
1 parent c2341e8 commit 0dceaf5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
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.");
});
});

0 comments on commit 0dceaf5

Please sign in to comment.