Skip to content

Commit

Permalink
feat: prevent updating slices and custom types with reserved name
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan Imiela committed Dec 13, 2024
1 parent fe248b6 commit f9f5cdb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export const RenameCustomTypeModal: React.FC<RenameCustomTypeModalProps> = ({
})} name is already taken.`;
}

if (["update", "insert"].includes(newName.toLowerCase())) {
errors.customTypeName = `Name "${newName}" is reserved for Slice Machine use.`;
}

return Object.keys(errors).length > 0 ? errors : undefined;
}}
>
Expand Down
8 changes: 2 additions & 6 deletions playwright/tests/customTypes/customTypesTable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,11 @@ test("I cannot create a custom type with a name update or insert", async ({
await customTypesTablePage.openCreateDialog();

await expect(customTypesTablePage.createTypeDialog.title).toBeVisible();
await customTypesTablePage.createTypeDialog.nameInput.fill(
"update",
);
await customTypesTablePage.createTypeDialog.nameInput.fill("update");
await expect(
customTypesTablePage.createTypeDialog.submitButton,
).toBeDisabled();
await customTypesTablePage.createTypeDialog.nameInput.fill(
"insert",
);
await customTypesTablePage.createTypeDialog.nameInput.fill("insert");
await expect(
customTypesTablePage.createTypeDialog.submitButton,
).toBeDisabled();
Expand Down
8 changes: 2 additions & 6 deletions playwright/tests/pageTypes/pageTypesTable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,9 @@ test("I cannot create a page type with a name update or insert", async ({
await pageTypesTablePage.openCreateDialog();

await expect(pageTypesTablePage.createTypeDialog.title).toBeVisible();
await pageTypesTablePage.createTypeDialog.nameInput.fill(
"update",
);
await pageTypesTablePage.createTypeDialog.nameInput.fill("update");
await expect(pageTypesTablePage.createTypeDialog.submitButton).toBeDisabled();
await pageTypesTablePage.createTypeDialog.nameInput.fill(
"insert",
);
await pageTypesTablePage.createTypeDialog.nameInput.fill("insert");
await expect(pageTypesTablePage.createTypeDialog.submitButton).toBeDisabled();
});

Expand Down
1 change: 0 additions & 1 deletion playwright/tests/slices/slicesList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ test("I cannot create a slice with a restricted name ", async ({
await expect(submitButton).toBeDisabled();
await nameInput.fill("insert");
await expect(submitButton).toBeDisabled();

});

test("I cannot create two slices with the same name", async ({
Expand Down

0 comments on commit f9f5cdb

Please sign in to comment.