web: can't add a tag that's a substring of another tag (fixes #1002)

This commit is contained in:
Abdullah Atta
2022-09-19 17:02:16 +05:00
parent 0f44ca49a9
commit a0b8262fb6
2 changed files with 33 additions and 3 deletions

View File

@@ -17,5 +17,26 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { test } from "@playwright/test"; import { expect, test } from "@playwright/test";
import { AppModel } from "./models/app.model";
import { NOTE } from "./utils";
test.skip("TODO: make sure jump to group works", () => {}); test.skip("TODO: make sure jump to group works", () => {});
test("#1002 Can't add a tag that's a substring of an existing tag", async ({
page
}) => {
const tags = ["chromeos-105", "chromeos"];
const app = new AppModel(page);
await app.goto();
const tagsView = await app.goToTags();
await tagsView.createItem({ title: "chromeos-105" });
const notes = await app.goToNotes();
await notes.createNote(NOTE);
await notes.editor.setTags(tags);
await page.waitForTimeout(200);
const noteTags = await notes.editor.getTags();
expect(noteTags).toHaveLength(tags.length);
expect(noteTags.every((t, i) => t === tags[i])).toBe(true);
});

View File

@@ -110,14 +110,21 @@ function Autosuggest({
if (filterText.length <= 0 && filtered.length <= 0) { if (filterText.length <= 0 && filtered.length <= 0) {
closeMenu(); closeMenu();
return; return;
} else if (filterText.length > 0 && filtered.length <= 0) { }
if (
filterText.length > 0 &&
filtered.every((item) => item.title !== filterText)
) {
items.push({ items.push({
key: "new", key: "new",
title: () => `Create "${filterText}" tag`, title: () => `Create "${filterText}" tag`,
icon: Icon.Plus, icon: Icon.Plus,
onClick: () => onAction("add", filterText) onClick: () => onAction("add", filterText)
}); });
} else { }
if (filtered.length > 0) {
items.push( items.push(
...filtered.map((tag) => ({ ...filtered.map((tag) => ({
key: tag.id, key: tag.id,
@@ -177,6 +184,8 @@ function Autosuggest({
const text = getInputValue(); const text = getInputValue();
if (e.key === "Enter" && !!text && !filtered.length) { if (e.key === "Enter" && !!text && !filtered.length) {
onAction("add", text); onAction("add", text);
} else if (e.key === "Enter" && !!text && !!filtered.length) {
onAction("select", filtered[0]);
} else if (!text && e.key === "Backspace") { } else if (!text && e.key === "Backspace") {
onRemove(); onRemove();
setFiltered([]); setFiltered([]);