+
{{
@@ -307,6 +309,7 @@ const refreshBranches = async () => {
size="medium"
filterable
@input="onSelect"
+ data-test-id="version-control-branch-select"
>
{
square
:class="$style.refreshBranches"
@click="refreshBranches"
+ data-test-id="version-control-refresh-branches-button"
/>
@@ -358,6 +362,7 @@ const refreshBranches = async () => {
@click="onSave"
size="large"
:disabled="!versionControlStore.preferences.branchName"
+ data-test-id="version-control-save-settings-button"
>{{ locale.baseText('settings.versionControl.button.save') }}
diff --git a/packages/editor-ui/src/views/__tests__/SettingsVersionControl.test.ts b/packages/editor-ui/src/views/__tests__/SettingsVersionControl.test.ts
index 73123d13d1..55fa1027de 100644
--- a/packages/editor-ui/src/views/__tests__/SettingsVersionControl.test.ts
+++ b/packages/editor-ui/src/views/__tests__/SettingsVersionControl.test.ts
@@ -1,14 +1,16 @@
-import { PiniaVuePlugin } from 'pinia';
-import { render } from '@testing-library/vue';
-import { createTestingPinia } from '@pinia/testing';
+import { vi } from 'vitest';
+import { screen, render, waitFor, within } from '@testing-library/vue';
+import userEvent from '@testing-library/user-event';
+import { createPinia, setActivePinia, PiniaVuePlugin } from 'pinia';
import { merge } from 'lodash-es';
-import { STORES } from '@/constants';
-import { SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils';
-import { i18n } from '@/plugins/i18n';
+import { setupServer } from '@/__tests__/server';
+import { i18nInstance } from '@/plugins/i18n';
+import { useSettingsStore, useVersionControlStore } from '@/stores';
import SettingsVersionControl from '@/views/SettingsVersionControl.vue';
-import { useVersionControlStore } from '@/stores/versionControl.store';
-let pinia: ReturnType
;
+let pinia: ReturnType;
+let server: ReturnType;
+let settingsStore: ReturnType;
let versionControlStore: ReturnType;
const renderComponent = (renderOptions: Parameters[1] = {}) =>
@@ -17,7 +19,7 @@ const renderComponent = (renderOptions: Parameters[1] = {}) =>
merge(
{
pinia,
- i18n,
+ i18n: i18nInstance,
},
renderOptions,
),
@@ -27,22 +29,28 @@ const renderComponent = (renderOptions: Parameters[1] = {}) =>
);
describe('SettingsVersionControl', () => {
+ beforeAll(() => {
+ server = setupServer();
+ });
+
beforeEach(() => {
- pinia = createTestingPinia({
- initialState: {
- [STORES.SETTINGS]: {
- settings: merge({}, SETTINGS_STORE_DEFAULT_STATE.settings),
- },
- },
- });
- versionControlStore = useVersionControlStore(pinia);
+ pinia = createPinia();
+ setActivePinia(pinia);
+ settingsStore = useSettingsStore();
+ versionControlStore = useVersionControlStore();
});
afterEach(() => {
vi.clearAllMocks();
});
+ afterAll(() => {
+ server.shutdown();
+ });
+
it('should render paywall state when there is no license', () => {
+ vi.spyOn(settingsStore, 'isEnterpriseFeatureEnabled').mockReturnValue(false);
+
const { getByTestId, queryByTestId } = renderComponent();
expect(queryByTestId('version-control-content-licensed')).not.toBeInTheDocument();
@@ -50,11 +58,86 @@ describe('SettingsVersionControl', () => {
});
it('should render licensed content', () => {
- vi.spyOn(versionControlStore, 'isEnterpriseVersionControlEnabled', 'get').mockReturnValue(true);
+ vi.spyOn(settingsStore, 'isEnterpriseFeatureEnabled').mockReturnValue(true);
const { getByTestId, queryByTestId } = renderComponent();
expect(getByTestId('version-control-content-licensed')).toBeInTheDocument();
expect(queryByTestId('version-control-content-unlicensed')).not.toBeInTheDocument();
+ expect(queryByTestId('version-control-connected-content')).not.toBeInTheDocument();
+ });
+
+ it('should render user flow happy path', async () => {
+ vi.spyOn(settingsStore, 'isEnterpriseFeatureEnabled').mockReturnValue(true);
+ const updatePreferencesSpy = vi.spyOn(versionControlStore, 'updatePreferences');
+
+ const { container, getByTestId, queryByTestId, getByRole } = renderComponent();
+
+ const connectButton = getByTestId('version-control-connect-button');
+ expect(connectButton).toBeDisabled();
+
+ const repoUrlInput = container.querySelector('input[name="repoUrl"]')!;
+ const authorName = container.querySelector('input[name="authorName"]')!;
+ const authorEmail = container.querySelector('input[name="authorEmail"]')!;
+
+ await userEvent.click(repoUrlInput);
+ await userEvent.type(repoUrlInput, 'git@github');
+ await userEvent.tab();
+ expect(connectButton).toBeDisabled();
+
+ await userEvent.click(repoUrlInput);
+ await userEvent.type(repoUrlInput, '.com:john/n8n-data.git');
+ await userEvent.tab();
+ expect(connectButton).toBeDisabled();
+
+ await userEvent.click(authorName);
+ await userEvent.type(authorName, 'John Doe');
+ await userEvent.tab();
+ expect(connectButton).toBeDisabled();
+
+ await userEvent.click(authorEmail);
+ await userEvent.type(authorEmail, 'john@example.');
+ await userEvent.tab();
+ expect(connectButton).toBeDisabled();
+
+ await userEvent.click(authorEmail);
+ await userEvent.type(authorEmail, 'com');
+ await userEvent.tab();
+
+ expect(connectButton).toBeEnabled();
+ expect(queryByTestId('version-control-save-settings-button')).not.toBeInTheDocument();
+
+ await userEvent.click(connectButton);
+ await waitFor(() => expect(getByTestId('version-control-connected-content')).toBeVisible());
+
+ const saveSettingsButton = getByTestId('version-control-save-settings-button');
+ expect(saveSettingsButton).toBeInTheDocument();
+ expect(saveSettingsButton).toBeDisabled();
+
+ const branchSelect = getByTestId('version-control-branch-select');
+ await userEvent.click(within(branchSelect).getByRole('textbox'));
+
+ await waitFor(() => expect(within(branchSelect).getByText('main')).toBeVisible());
+ await userEvent.click(within(branchSelect).getByText('main'));
+
+ await waitFor(() => expect(saveSettingsButton).toBeEnabled());
+ await userEvent.click(saveSettingsButton);
+
+ expect(updatePreferencesSpy).toHaveBeenCalledWith({
+ branchName: 'main',
+ branchReadOnly: false,
+ branchColor: '#1d6acb',
+ });
+ await waitFor(() => expect(screen.getByText('Settings successfully saved')).toBeVisible());
+
+ await userEvent.click(getByTestId('version-control-disconnect-button'));
+ const disconnectDialog = getByRole('dialog');
+ await waitFor(() => expect(disconnectDialog).toBeVisible());
+
+ await userEvent.click(within(disconnectDialog).getAllByRole('button')[1]);
+ await waitFor(() => expect(disconnectDialog).not.toBeVisible());
+ await waitFor(() =>
+ expect(queryByTestId('version-control-connected-content')).not.toBeInTheDocument(),
+ );
});
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 379e77e174..08392b8c47 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -142,7 +142,7 @@ importers:
dependencies:
axios:
specifier: ^0.21.1
- version: 0.21.4(debug@4.3.2)
+ version: 0.21.4
packages/@n8n_io/eslint-config:
devDependencies:
@@ -223,7 +223,7 @@ importers:
version: 7.28.1
axios:
specifier: ^0.21.1
- version: 0.21.4(debug@4.3.2)
+ version: 0.21.4
basic-auth:
specifier: ^2.0.1
version: 2.0.1
@@ -656,7 +656,7 @@ importers:
version: link:../@n8n/client-oauth2
axios:
specifier: ^0.21.1
- version: 0.21.4(debug@4.3.2)
+ version: 0.21.4
concat-stream:
specifier: ^2.0.0
version: 2.0.0
@@ -803,6 +803,9 @@ importers:
'@testing-library/jest-dom':
specifier: ^5.16.5
version: 5.16.5
+ '@testing-library/user-event':
+ specifier: ^14.4.3
+ version: 14.4.3(@testing-library/dom@7.31.2)
'@testing-library/vue':
specifier: ^5.8.3
version: 5.8.3(vue-template-compiler@2.7.14)(vue@2.7.14)
@@ -904,7 +907,7 @@ importers:
version: 5.13.2
axios:
specifier: ^0.21.1
- version: 0.21.4(debug@4.3.2)
+ version: 0.21.4
codemirror-lang-html-n8n:
specifier: ^1.0.0
version: 1.0.0
@@ -5631,6 +5634,38 @@ packages:
dev: false
optional: true
+ /@oclif/command@1.8.18(@oclif/config@1.18.2):
+ resolution: {integrity: sha512-qTad+jtiriMMbkw6ArtcUY89cwLwmwDnD4KSGT+OQiZKYtegp3NUCM9JN8lfj/aKC+0kvSitJM4ULzbgiVTKQQ==}
+ engines: {node: '>=12.0.0'}
+ peerDependencies:
+ '@oclif/config': ^1
+ dependencies:
+ '@oclif/config': 1.18.2
+ '@oclif/errors': 1.3.6
+ '@oclif/help': 1.0.3(supports-color@8.1.1)
+ '@oclif/parser': 3.8.8
+ debug: 4.3.4(supports-color@8.1.1)
+ semver: 7.3.8
+ transitivePeerDependencies:
+ - supports-color
+ dev: true
+
+ /@oclif/command@1.8.18(@oclif/config@1.18.5):
+ resolution: {integrity: sha512-qTad+jtiriMMbkw6ArtcUY89cwLwmwDnD4KSGT+OQiZKYtegp3NUCM9JN8lfj/aKC+0kvSitJM4ULzbgiVTKQQ==}
+ engines: {node: '>=12.0.0'}
+ peerDependencies:
+ '@oclif/config': ^1
+ dependencies:
+ '@oclif/config': 1.18.5(supports-color@8.1.1)
+ '@oclif/errors': 1.3.6
+ '@oclif/help': 1.0.3(supports-color@8.1.1)
+ '@oclif/parser': 3.8.8
+ debug: 4.3.4(supports-color@8.1.1)
+ semver: 7.3.8
+ transitivePeerDependencies:
+ - supports-color
+ dev: true
+
/@oclif/command@1.8.18(@oclif/config@1.18.5)(supports-color@8.1.1):
resolution: {integrity: sha512-qTad+jtiriMMbkw6ArtcUY89cwLwmwDnD4KSGT+OQiZKYtegp3NUCM9JN8lfj/aKC+0kvSitJM4ULzbgiVTKQQ==}
engines: {node: '>=12.0.0'}
@@ -5712,7 +5747,7 @@ packages:
engines: {node: '>=8.10.0'}
hasBin: true
dependencies:
- '@oclif/command': 1.8.18(@oclif/config@1.18.5)(supports-color@8.1.1)
+ '@oclif/command': 1.8.18(@oclif/config@1.18.5)
'@oclif/config': 1.18.5(supports-color@8.1.1)
'@oclif/errors': 1.3.6
'@oclif/plugin-help': 3.2.18
@@ -5782,7 +5817,7 @@ packages:
resolution: {integrity: sha512-5n5Pkz4L0duknIvFwx2Ko9Xda3miT6RZP8bgaaK3Q/9fzVBrhi4bOM0u05/OThI6V+3NsSdxYS2o1NLcXToWDg==}
engines: {node: '>=8.0.0'}
dependencies:
- '@oclif/command': 1.8.18(@oclif/config@1.18.5)(supports-color@8.1.1)
+ '@oclif/command': 1.8.18(@oclif/config@1.18.2)
'@oclif/config': 1.18.2
'@oclif/errors': 1.3.5
'@oclif/help': 1.0.3(supports-color@8.1.1)
@@ -5842,7 +5877,7 @@ packages:
dependencies:
'@segment/loosely-validate-event': 2.0.0
auto-changelog: 1.16.4
- axios: 0.21.4(debug@4.3.2)
+ axios: 0.21.4
axios-retry: 3.3.1
bull: 3.29.3
lodash.clonedeep: 4.5.0
@@ -9673,6 +9708,14 @@ packages:
is-retry-allowed: 2.2.0
dev: false
+ /axios@0.21.4:
+ resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==}
+ dependencies:
+ follow-redirects: 1.15.2(debug@3.2.7)
+ transitivePeerDependencies:
+ - debug
+ dev: false
+
/axios@0.21.4(debug@4.3.2):
resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==}
dependencies:
@@ -10998,6 +11041,7 @@ packages:
/consolidate@0.15.1(react-dom@18.2.0)(react@17.0.2):
resolution: {integrity: sha512-DW46nrsMJgy9kqAbPt5rKaCr7uFtpo4mSUvLHIUbJEjm0vo+aY5QLwBUq3FK4tRnJr/X0Psc0C4jf/h+HtXSMw==}
engines: {node: '>= 0.10.0'}
+ deprecated: Please upgrade to consolidate v1.0.0+ as it has been modernized with several long-awaited fixes implemented. Maintenance is supported by Forward Email at https://forwardemail.net ; follow/watch https://github.com/ladjs/consolidate for updates and release changelog
peerDependencies:
arc-templates: ^0.5.3
atpl: '>=0.7.6'