mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(editor): Remove i18n and toast usage from setting store (no-changelog) (#16721)
This commit is contained in:
@@ -18,9 +18,10 @@ import { EnterpriseEditionFeature } from '@/constants';
|
|||||||
import { useUIStore } from '@/stores/ui.store';
|
import { useUIStore } from '@/stores/ui.store';
|
||||||
|
|
||||||
const showMessage = vi.fn();
|
const showMessage = vi.fn();
|
||||||
|
const showToast = vi.fn();
|
||||||
|
|
||||||
vi.mock('@/composables/useToast', () => ({
|
vi.mock('@/composables/useToast', () => ({
|
||||||
useToast: () => ({ showMessage }),
|
useToast: () => ({ showMessage, showToast }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('@/stores/users.store', () => ({
|
vi.mock('@/stores/users.store', () => ({
|
||||||
@@ -90,6 +91,23 @@ describe('Init', () => {
|
|||||||
expect(settingsStoreSpy).toHaveBeenCalledTimes(1);
|
expect(settingsStoreSpy).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw an error if settings initialization fails', async () => {
|
||||||
|
const error = new Error('Settings initialization failed');
|
||||||
|
|
||||||
|
vi.spyOn(settingsStore, 'initialize').mockImplementation(() => {
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
|
||||||
|
await initializeCore();
|
||||||
|
|
||||||
|
expect(showToast).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
title: 'Error connecting to n8n',
|
||||||
|
type: 'error',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('should initialize authentication hooks', async () => {
|
it('should initialize authentication hooks', async () => {
|
||||||
const registerLoginHookSpy = vi.spyOn(usersStore, 'registerLoginHook');
|
const registerLoginHookSpy = vi.spyOn(usersStore, 'registerLoginHook');
|
||||||
const registerLogoutHookSpy = vi.spyOn(usersStore, 'registerLogoutHook');
|
const registerLogoutHookSpy = vi.spyOn(usersStore, 'registerLogoutHook');
|
||||||
|
|||||||
@@ -43,13 +43,25 @@ export async function initializeCore() {
|
|||||||
const ssoStore = useSSOStore();
|
const ssoStore = useSSOStore();
|
||||||
const uiStore = useUIStore();
|
const uiStore = useUIStore();
|
||||||
|
|
||||||
|
const toast = useToast();
|
||||||
|
const i18n = useI18n();
|
||||||
|
|
||||||
registerAuthenticationHooks();
|
registerAuthenticationHooks();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize stores
|
* Initialize stores
|
||||||
*/
|
*/
|
||||||
|
|
||||||
await settingsStore.initialize();
|
try {
|
||||||
|
await settingsStore.initialize();
|
||||||
|
} catch (error) {
|
||||||
|
toast.showToast({
|
||||||
|
title: i18n.baseText('startupError'),
|
||||||
|
message: i18n.baseText('startupError.message'),
|
||||||
|
type: 'error',
|
||||||
|
duration: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ssoStore.initialize({
|
ssoStore.initialize({
|
||||||
authenticationMethod: settingsStore.userManagement
|
authenticationMethod: settingsStore.userManagement
|
||||||
|
|||||||
@@ -21,12 +21,9 @@ import type { IDataObject, WorkflowSettings } from 'n8n-workflow';
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { useRootStore } from '@n8n/stores/useRootStore';
|
import { useRootStore } from '@n8n/stores/useRootStore';
|
||||||
import { makeRestApiRequest } from '@n8n/rest-api-client';
|
import { makeRestApiRequest } from '@n8n/rest-api-client';
|
||||||
import { useToast } from '@/composables/useToast';
|
|
||||||
import { useI18n } from '@n8n/i18n';
|
|
||||||
import { useLocalStorage } from '@vueuse/core';
|
import { useLocalStorage } from '@vueuse/core';
|
||||||
|
|
||||||
export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
|
export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
|
||||||
const i18n = useI18n();
|
|
||||||
const initialized = ref(false);
|
const initialized = ref(false);
|
||||||
const settings = ref<FrontendSettings>({} as FrontendSettings);
|
const settings = ref<FrontendSettings>({} as FrontendSettings);
|
||||||
const moduleSettings = ref<FrontendModuleSettings>({});
|
const moduleSettings = ref<FrontendModuleSettings>({});
|
||||||
@@ -265,23 +262,11 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { showToast } = useToast();
|
await getSettings();
|
||||||
try {
|
|
||||||
await getSettings();
|
|
||||||
|
|
||||||
initialized.value = true;
|
initialized.value = true;
|
||||||
|
|
||||||
await getModuleSettings();
|
await getModuleSettings();
|
||||||
} catch (e) {
|
|
||||||
showToast({
|
|
||||||
title: i18n.baseText('startupError'),
|
|
||||||
message: i18n.baseText('startupError.message'),
|
|
||||||
type: 'error',
|
|
||||||
duration: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const stopShowingSetupPage = () => {
|
const stopShowingSetupPage = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user