mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
fix(editor): Fix a link routing regression in N8nRoute, and add tests (no-changelog) (#8911)
This commit is contained in:
parent
33ab781aef
commit
1cb1de8c87
|
@ -17,7 +17,7 @@ interface RouteProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
defineOptions({ name: 'N8nRoute' });
|
defineOptions({ name: 'N8nRoute' });
|
||||||
const props = withDefaults(defineProps<RouteProps>(), {});
|
const props = defineProps<RouteProps>();
|
||||||
|
|
||||||
const useRouterLink = computed(() => {
|
const useRouterLink = computed(() => {
|
||||||
if (props.newWindow) {
|
if (props.newWindow) {
|
||||||
|
@ -32,14 +32,5 @@ const useRouterLink = computed(() => {
|
||||||
return props.to !== undefined;
|
return props.to !== undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
const openNewWindow = computed(() => {
|
const openNewWindow = computed(() => !useRouterLink.value);
|
||||||
if (props.newWindow !== undefined) {
|
|
||||||
return props.newWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof props.to === 'string') {
|
|
||||||
return !props.to.startsWith('/');
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
|
@ -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>"`;
|
Loading…
Reference in a new issue