diff --git a/packages/design-system/src/components/N8nRoute/Route.vue b/packages/design-system/src/components/N8nRoute/Route.vue index 89f9f924b..397cff994 100644 --- a/packages/design-system/src/components/N8nRoute/Route.vue +++ b/packages/design-system/src/components/N8nRoute/Route.vue @@ -17,7 +17,7 @@ interface RouteProps { } defineOptions({ name: 'N8nRoute' }); -const props = withDefaults(defineProps(), {}); +const props = defineProps(); const useRouterLink = computed(() => { if (props.newWindow) { @@ -32,14 +32,5 @@ const useRouterLink = computed(() => { return props.to !== undefined; }); -const openNewWindow = computed(() => { - if (props.newWindow !== undefined) { - return props.newWindow; - } - - if (typeof props.to === 'string') { - return !props.to.startsWith('/'); - } - return true; -}); +const openNewWindow = computed(() => !useRouterLink.value); diff --git a/packages/design-system/src/components/N8nRoute/__tests__/Route.spec.ts b/packages/design-system/src/components/N8nRoute/__tests__/Route.spec.ts new file mode 100644 index 000000000..fb5c16b1e --- /dev/null +++ b/packages/design-system/src/components/N8nRoute/__tests__/Route.spec.ts @@ -0,0 +1,32 @@ +import { render } from '@testing-library/vue'; +import N8nRoute from '../Route.vue'; + +describe('N8nRoute', () => { + it('should render internal router links', () => { + const wrapper = render(N8nRoute, { + props: { + to: '/test', + }, + }); + expect(wrapper.html()).toMatchSnapshot(); + }); + + it('should render internal links with newWindow=true', () => { + const wrapper = render(N8nRoute, { + props: { + to: '/test', + newWindow: true, + }, + }); + expect(wrapper.html()).toMatchSnapshot(); + }); + + it('should render external links', () => { + const wrapper = render(N8nRoute, { + props: { + to: 'https://example.com/', + }, + }); + expect(wrapper.html()).toMatchSnapshot(); + }); +}); diff --git a/packages/design-system/src/components/N8nRoute/__tests__/__snapshots__/Route.spec.ts.snap b/packages/design-system/src/components/N8nRoute/__tests__/__snapshots__/Route.spec.ts.snap new file mode 100644 index 000000000..c9e658ff2 --- /dev/null +++ b/packages/design-system/src/components/N8nRoute/__tests__/__snapshots__/Route.spec.ts.snap @@ -0,0 +1,7 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`N8nRoute > should render external links 1`] = `""`; + +exports[`N8nRoute > should render internal links with newWindow=true 1`] = `""`; + +exports[`N8nRoute > should render internal router links 1`] = `""`;