1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-09-11 13:15:28 +03:00

fix(editor): Fix a link routing regression in N8nRoute, and add tests (no-changelog) (#8911)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-03-19 11:04:22 +01:00 committed by GitHub
parent 33ab781aef
commit 1cb1de8c87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 11 deletions

View File

@ -17,7 +17,7 @@ interface RouteProps {
}
defineOptions({ name: 'N8nRoute' });
const props = withDefaults(defineProps<RouteProps>(), {});
const props = defineProps<RouteProps>();
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);
</script>

View File

@ -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();
});
});

View File

@ -0,0 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`N8nRoute > should render external links 1`] = `"<a href="https://example.com/" target="_blank"></a>"`;
exports[`N8nRoute > should render internal links with newWindow=true 1`] = `"<a href="/test" target="_blank"></a>"`;
exports[`N8nRoute > should render internal router links 1`] = `"<router-link to="/test"></router-link>"`;