) => children, // Mocking UISref to render its children directly
+}));
+
+copyAsCustomTestCases.forEach(({ type, expected }) => {
+ test(`copy as custom button should ${
+ expected ? '' : 'not '
+ }be rendered for type ${type}`, () => {
+ const onSelect = vi.fn();
+ const isSelected = false;
+
+ const { queryByText, unmount } = render(
+
+ );
+
+ if (expected) {
+ expect(queryByText('Copy as Custom')).toBeVisible();
+ } else {
+ expect(queryByText('Copy as Custom')).toBeNull();
+ }
+
+ unmount();
+ });
+});
+
+test('should call onSelect when clicked', async () => {
+ const user = userEvent.setup();
+ const template: TemplateViewModel = {
+ Title: 'Test Template',
+ // provide necessary properties for the template object
+ } as TemplateViewModel;
+
+ const onSelect = vi.fn();
+ const isSelected = false;
+
+ const { getByLabelText } = render(
+
+ );
+
+ const button = getByLabelText(template.Title);
+ await user.click(button);
+
+ expect(onSelect).toHaveBeenCalledWith(template);
+});
diff --git a/app/react/portainer/templates/components/TemplateItem.tsx b/app/react/portainer/templates/components/TemplateItem.tsx
index b08191c80..ffb5ac055 100644
--- a/app/react/portainer/templates/components/TemplateItem.tsx
+++ b/app/react/portainer/templates/components/TemplateItem.tsx
@@ -45,6 +45,7 @@ export function TemplateItem({
as={linkParams ? Link : undefined}
to={linkParams?.to}
params={linkParams?.params}
+ aria-label={template.Title}
>
{
expect(nameField).toHaveDisplayValue(newValue);
diff --git a/package.json b/package.json
index 0c4eba2fe..57c0faaff 100644
--- a/package.json
+++ b/package.json
@@ -142,7 +142,7 @@
"@svgr/webpack": "^8.1.0",
"@testing-library/dom": "^9.3.4",
"@testing-library/react": "^12",
- "@testing-library/user-event": "^13.5.0",
+ "@testing-library/user-event": "^14.5.2",
"@types/angular": "^1.8.3",
"@types/file-saver": "^2.0.4",
"@types/filesize-parser": "^1.5.1",
diff --git a/yarn.lock b/yarn.lock
index 709b6b416..2941ed1b9 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5624,12 +5624,10 @@
"@testing-library/dom" "^8.0.0"
"@types/react-dom" "<18.0.0"
-"@testing-library/user-event@^13.5.0":
- version "13.5.0"
- resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-13.5.0.tgz#69d77007f1e124d55314a2b73fd204b333b13295"
- integrity sha512-5Kwtbo3Y/NowpkbRuSepbyMFkZmHgD+vPzYB/RJ4oxt5Gj/avFFBYjhw27cqSVPVw/3a67NK1PbiIr9k4Gwmdg==
- dependencies:
- "@babel/runtime" "^7.12.5"
+"@testing-library/user-event@^14.5.2":
+ version "14.5.2"
+ resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.5.2.tgz#db7257d727c891905947bd1c1a99da20e03c2ebd"
+ integrity sha512-YAh82Wh4TIrxYLmfGcixwD18oIjyC1pFQC2Y01F2lzV2HTMiYrI0nze0FD0ocB//CKS/7jIUgae+adPqxK5yCQ==
"@tippyjs/react@^4.2.6":
version "4.2.6"