Skip to content

Commit

Permalink
fix(editor): Show v1 banner dismiss button if owner (#7722)
Browse files Browse the repository at this point in the history
Github issue / Community forum post (link here to close automatically):

https://community.n8n.io/t/v1-upgrade-banner-shall-be-dismissed-permanently/32775
  • Loading branch information
mutdmour committed Nov 17, 2023
1 parent ce002a6 commit 44d3b3e
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/editor-ui/src/components/banners/V1Banner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { useUsersStore } from '@/stores/users.store';
import { useUIStore } from '@/stores/ui.store';
const uiStore = useUIStore();
const { isInstanceOwner } = useUsersStore();
const usersStore = useUsersStore();
async function dismissPermanently() {
await uiStore.dismissBanner('V1', 'permanent');
Expand All @@ -18,7 +17,7 @@ async function dismissPermanently() {
<template #mainContent>
<span v-html="locale.baseText('banners.v1.message')"></span>
<a
v-if="isInstanceOwner"
v-if="usersStore.isInstanceOwner"
:class="$style.link"
@click="dismissPermanently"
data-test-id="banner-confirm-v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { render } from '@testing-library/vue';
import V1Banner from '../V1Banner.vue';
import { createPinia, setActivePinia } from 'pinia';
import { useUsersStore } from '@/stores/users.store';

describe('V1 Banner', () => {
let pinia: ReturnType<typeof createPinia>;
let usersStore: ReturnType<typeof useUsersStore>;

beforeEach(async () => {
pinia = createPinia();
setActivePinia(pinia);

usersStore = useUsersStore();
});

it('should render banner', () => {
const { container } = render(V1Banner);
expect(container).toMatchSnapshot();
expect(container.querySelectorAll('a')).toHaveLength(1);
});

it('should render banner with dismiss call if user is owner', () => {
vi.spyOn(usersStore, 'currentUser', 'get').mockReturnValue({
globalRole: {
id: 0,
name: 'owner',
createdAt: '2021-08-09T14:00:00.000Z',
},
});

const { container } = render(V1Banner);
expect(container).toMatchSnapshot();
expect(container.querySelectorAll('a')).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`V1 Banner > should render banner 1`] = `
<div>
<n8n-callout
class="v1container"
data-test-id="banners-V1"
icon="info-circle"
iconsize="medium"
roundcorners="false"
theme="warning"
>
<div
class="mainContent keepSpace"
>
<span>
n8n has been updated to version 1, introducing some breaking changes. Please consult the
<a
href="https://docs.n8n.io/1-0-migration-checklist"
target="_blank"
>
migration guide
</a>
for more information.
</span>
<!--v-if-->
</div>
</n8n-callout>
</div>
`;

exports[`V1 Banner > should render banner if user is not woner 1`] = `
<div>
<n8n-callout
class="v1container"
data-test-id="banners-V1"
icon="info-circle"
iconsize="medium"
roundcorners="false"
theme="warning"
>
<div
class="mainContent keepSpace"
>
<span>
n8n has been updated to version 1, introducing some breaking changes. Please consult the
<a
href="https://docs.n8n.io/1-0-migration-checklist"
target="_blank"
>
migration guide
</a>
for more information.
</span>
<!--v-if-->
</div>
</n8n-callout>
</div>
`;

exports[`V1 Banner > should render banner with dismiss call if user is owner 1`] = `
<div>
<n8n-callout
class="v1container"
data-test-id="banners-V1"
icon="info-circle"
iconsize="medium"
roundcorners="false"
theme="warning"
>
<div
class="mainContent keepSpace"
>
<span>
n8n has been updated to version 1, introducing some breaking changes. Please consult the
<a
href="https://docs.n8n.io/1-0-migration-checklist"
target="_blank"
>
migration guide
</a>
for more information.
</span>
<a
class="link"
data-test-id="banner-confirm-v1"
>
<span>
Don't show again
</span>
</a>
</div>
</n8n-callout>
</div>
`;

0 comments on commit 44d3b3e

Please sign in to comment.