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-tokenizer): fix token-delete event details #10630

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
51 changes: 51 additions & 0 deletions packages/main/cypress/specs/Tokenizer.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { html } from "lit";
import "../../src/Tokenizer.js";
import "../../src/Token.js";
import type Tokenizer from "../../src/Tokenizer.js";
import type { UI5CustomEvent } from "@ui5/webcomponents-base/dist/index.js";

const onTokenDelete = (event: UI5CustomEvent<Tokenizer, "token-delete">) => {
event.detail.tokens.forEach(token => {
(event.target as Tokenizer).removeChild(token);
});
};

describe("Tokenizer - multi-line and Clear All", () => {
it("'Clear All' link is rendered for multi-line tokenizer and show-clear-all set to true", () => {
Expand Down Expand Up @@ -111,4 +119,47 @@ describe("Tokenizer - multi-line and Clear All", () => {
cy.get("@delete")
.should("have.been.calledOnce");
});

it("tests token removal", () => {
cy.mount(html`
<ui5-tokenizer id="test-token-delete" style="width: 100px">
<ui5-token text="aute"></ui5-token>
<ui5-token text="ad"></ui5-token>
<ui5-token text="exercitation"></ui5-token>
<ui5-token text="esse"></ui5-token>
<ui5-token text="labore"></ui5-token>
<ui5-token text="amet"></ui5-token>
<ui5-token text="excepteur"></ui5-token>
</ui5-tokenizer>`);

cy.get("#test-token-delete")
.then($tokenizer => {
$tokenizer.get(0).addEventListener("token-delete", onTokenDelete as EventListener);
});

cy.get("#test-token-delete")
.find("ui5-token")
.should("have.length", 7);

cy.get("#test-token-delete")
.shadow()
.find(".ui5-tokenizer-more-text")
.realClick();

cy.get("#test-token-delete")
.shadow()
.find("[ui5-responsive-popover]")
.should("be.visible");

cy.get("#test-token-delete")
.shadow()
.find("[ui5-responsive-popover] [ui5-list] [ui5-li]").eq(0)
.shadow()
.find(".ui5-li-deletebtn [ui5-button]")
.realClick();

cy.get("#test-token-delete")
.find("ui5-token")
.should("have.length", 6);
});
});
2 changes: 1 addition & 1 deletion packages/main/src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ class Tokenizer extends UI5Element {
}

getTokenByRefId(refId: string) {
return this.tokens.find(token => token._id === refId)!;
return this._tokens.find(token => token._id === refId)!;
}
}

Expand Down
15 changes: 15 additions & 0 deletions packages/main/test/pages/MultiInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ <h1 class="sample-container-title">Custom Suggestions</h1>
</ui5-multi-input>
</div>


<h1 class="sample-container-title">Token delete</h1>

<ui5-multi-input show-suggestions id="test-token-delete">
<ui5-token slot="tokens" text="Aute"></ui5-token>
<ui5-token slot="tokens" text="ad"></ui5-token>
<ui5-token slot="tokens" text="exercitation"></ui5-token>
<ui5-token slot="tokens" text="esse"></ui5-token>
<ui5-token slot="tokens" text="labore"></ui5-token>
<ui5-token slot="tokens" text="amet"></ui5-token>
<ui5-token slot="tokens" text="aute"></ui5-token>
<ui5-token slot="tokens" text="excepteur"></ui5-token>
</ui5-multi-input>

<script>

var createTokenFromText = function (text) {
Expand Down Expand Up @@ -470,6 +484,7 @@ <h1 class="sample-container-title">Custom Suggestions</h1>
}

document.getElementById("token-unique").addEventListener("ui5-token-delete", handleTokenDelete);
document.getElementById("test-token-delete").addEventListener("ui5-token-delete", handleTokenDelete);
document.getElementById("suggestion-token").addEventListener("ui5-token-delete", handleTokenDelete);
document.getElementById("two-tokens").addEventListener("ui5-token-delete", handleTokenDelete);
document.getElementById("readonly-mi").addEventListener("ui5-token-delete", handleTokenDelete);
Expand Down
Loading