-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
281 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { App } from 'vue' | ||
import type { Router } from 'vue-router' | ||
import { BASE_INTERFACE_LANGUAGE, BASE_INTERFACE_LANGUAGE_NAME } from '@/const/BaseInterfaceLanguage' | ||
|
||
|
||
export async function setupI18n(router: Router, app: App) {} | ||
|
||
export const useI18n = () => { | ||
return { | ||
t: (tKey: string) => tKey, | ||
locale: BASE_INTERFACE_LANGUAGE_NAME, | ||
availableLocales: [BASE_INTERFACE_LANGUAGE], | ||
setLocaleMessage: () => {}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/services/authentication/firebase/__mocks__/FirebaseAuthentication.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { IAuthentication } from '@/services/authentication/common/IAuthentication' | ||
|
||
export class FirebaseAuthentication implements IAuthentication { | ||
private static instance: FirebaseAuthentication | ||
|
||
public static getInstance(): IAuthentication { | ||
if (!FirebaseAuthentication.instance) { | ||
FirebaseAuthentication.instance = new FirebaseAuthentication() | ||
} | ||
|
||
return FirebaseAuthentication.instance | ||
} | ||
|
||
public createUserWithEmailAndPassword = async () => {} | ||
|
||
public signInWithEmailAndPassword = async () => {} | ||
|
||
private signInWithAuthProvider = async () => {} | ||
|
||
public signInWithProvider = async () => {} | ||
|
||
public signOut = async () => {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { IConfig } from '@/services/configuration/common/IConfig' | ||
import type { IConfigService } from '@/services/configuration/common/IConfigService' | ||
import { BASE_INTERFACE_LANGUAGE, BASE_INTERFACE_LANGUAGE_NAME } from '@/const/BaseInterfaceLanguage' | ||
|
||
export class Config implements IConfigService { | ||
private static instance: Config | ||
|
||
public static getInstance(): IConfigService { | ||
if (!Config.instance) { | ||
Config.instance = new Config() | ||
} | ||
|
||
return Config.instance | ||
} | ||
|
||
public async setup(): Promise<void> {} | ||
|
||
public getConfig(): IConfig { | ||
return { | ||
languages: { | ||
[BASE_INTERFACE_LANGUAGE]: BASE_INTERFACE_LANGUAGE_NAME, | ||
}, | ||
languagesAvailableForLearning: [BASE_INTERFACE_LANGUAGE], | ||
interfaceLanguages: [BASE_INTERFACE_LANGUAGE], | ||
} satisfies IConfig | ||
} | ||
|
||
public getBaseConfig() { | ||
return { | ||
languages: {}, | ||
languagesAvailableForLearning: [], | ||
interfaceLanguages: [], | ||
} satisfies IConfig | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { beforeEach, vi } from 'vitest' | ||
import type { Router } from 'vue-router' | ||
import { createAppRouter } from '@/router' | ||
import { BASE_INTERFACE_LANGUAGE_NAME } from '@/const/BaseInterfaceLanguage' | ||
|
||
// type FakeFirestore = { onSnapshot(this: void): void } | ||
// vi.mock('firebase/firestore', async (getModule) => { | ||
// const original: FakeFirestore = await getModule() | ||
// | ||
// return { | ||
// ...original, | ||
// onSnapshot: vi.fn().mockImplementation(original.onSnapshot), | ||
// } | ||
// }) | ||
|
||
export const useMocks = () => { | ||
const mockServices = () => { | ||
vi.mock('@/services/authentication/firebase/FirebaseAuthentication') | ||
vi.mock('@/services/dbstore/firestore/UserFirestoreCollection') | ||
vi.mock('@/services/dbstore/firestore/TranslationsFirestoreCollection') | ||
vi.mock('@/services/configuration/firebase/Config') | ||
} | ||
|
||
const mockI18n = () => { | ||
vi.mock('@/plugins/i18n') | ||
} | ||
|
||
const mockNotifications = async () => { | ||
vi.mock('naive-ui', async (importOriginal) => { | ||
return { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
...await importOriginal(), | ||
useNotification: () => ({ | ||
create: () => {}, | ||
info: () => {}, | ||
success: () => {}, | ||
warning: () => {}, | ||
error: () => {}, | ||
open: () => {}, | ||
destroyAll: () => {}, | ||
}), | ||
} | ||
}) | ||
} | ||
|
||
const routerBeforeEach = async () => { | ||
const router = createAppRouter() | ||
router.push({ params: { lang: BASE_INTERFACE_LANGUAGE_NAME } }) | ||
await router.isReady() | ||
|
||
return router | ||
} | ||
|
||
return { | ||
mockServices, | ||
mockI18n, | ||
routerBeforeEach, | ||
mockNotifications, | ||
} | ||
} |
138 changes: 48 additions & 90 deletions
138
tests/modules/landing/components/LandingHeader.hdom.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,78 @@ | ||
import { | ||
afterEach, | ||
beforeAll, | ||
beforeEach, | ||
describe, | ||
expect, | ||
it, | ||
} from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import { | ||
type Router, | ||
createRouter, | ||
createWebHistory, | ||
} from 'vue-router' | ||
import { testApp } from '@@/tests/common/testApp' | ||
import { type Router } from 'vue-router' | ||
import { createTestingPinia } from '@pinia/testing' | ||
import { vi } from 'vitest' | ||
import { useMocks } from '@@/tests/common/useMocks' | ||
import LandingHeader from '@/modules/landing/components/LandingHeader/LandingHeader.vue' | ||
import { routes } from '@/router' | ||
import { BASE_INTERFACE_LANGUAGE_NAME } from '@/const/BaseInterfaceLanguage' | ||
import { useInterfaceLanguageStore } from '@/store/modules/interfaceLanguage' | ||
import { useUserStore } from '@/store/modules/user' | ||
|
||
// const useTestRouter = async () => { | ||
// const router = createRouter({ | ||
// history: createWebHistory(), | ||
// routes: routes, | ||
// }) | ||
// | ||
// router.push({ params: { lang: BASE_INTERFACE_LANGUAGE_NAME } }) | ||
// await router.isReady() | ||
// | ||
// return router | ||
// } | ||
import { EAuthenticateModalType } from '@/modules/landing/modules/authenticate/components/AuthenticateModal/EAuthenticateModalType' | ||
|
||
// type FakeFirestore = { onSnapshot(this: void): void } | ||
// vi.mock('firebase/firestore', async (getModule) => { | ||
// const original: FakeFirestore = await getModule() | ||
// | ||
// return { | ||
// ...original, | ||
// onSnapshot: vi.fn().mockImplementation(original.onSnapshot), | ||
// } | ||
// }) | ||
// | ||
// vi.mock('@/plugins/services', () => { | ||
// return { | ||
// useDbStore: () => ({ | ||
// userCollection: undefined, | ||
// translationCollection: undefined, | ||
// }), | ||
// } | ||
// }) | ||
// | ||
// vi.mock('@/store/modules/interfaceLanguage', () => { | ||
// return { | ||
// useInterfaceLanguageStore: () => ({ | ||
// interfaceLanguageId: 0, | ||
// setInterfaceLanguage: () => {}, | ||
// }), | ||
// } | ||
// }) | ||
vi.mock('@/store/modules/user') | ||
const { mockServices, mockI18n, routerBeforeEach } = useMocks() | ||
mockI18n() | ||
mockServices() | ||
|
||
describe('modules/landing/components/LandingHeader', () => { | ||
let router: Router | ||
beforeEach(async () => { | ||
router = createRouter({ | ||
history: createWebHistory(), | ||
routes: routes, | ||
}) | ||
|
||
|
||
router.push({ params: { lang: BASE_INTERFACE_LANGUAGE_NAME } }) | ||
await router.isReady() | ||
router = await routerBeforeEach() | ||
}) | ||
|
||
const getWrapper = (isLoggedIn: boolean) => { | ||
return mount(LandingHeader, { | ||
global: { | ||
stubs: { AuthenticateModal: true }, | ||
plugins: [ | ||
router, | ||
createTestingPinia({ | ||
createSpy: vi.fn, | ||
initialState: { | ||
user: { | ||
profileData: isLoggedIn ? {} : undefined, | ||
}, | ||
}, | ||
}), | ||
], | ||
}, | ||
}) | ||
} | ||
|
||
describe('authorized user', () => { | ||
it('template', async () => { | ||
const wrapper = mount(LandingHeader, { | ||
global: { | ||
plugins: [ | ||
router, | ||
createTestingPinia({ | ||
createSpy: vi.fn, | ||
initialState: { | ||
user: { | ||
isLoggedIn: true, | ||
}, | ||
}, | ||
}), | ||
], | ||
}, | ||
}) | ||
const wrapper = getWrapper(true) | ||
expect(wrapper.text()).toContain('go_to_workspace') | ||
}) | ||
}) | ||
|
||
describe('unauthorized user', () => { | ||
it('template', async () => { | ||
const wrapper = mount(LandingHeader, { | ||
global: { | ||
plugins: [ | ||
router, | ||
createTestingPinia({ | ||
createSpy: vi.fn, | ||
initialState: { | ||
user: { | ||
isLoggedIn: false, | ||
}, | ||
}, | ||
}), | ||
], | ||
}, | ||
}) | ||
const wrapper = getWrapper(false) | ||
expect(wrapper.text()).toContain('sign_in') | ||
expect(wrapper.text()).toContain('sign_up') | ||
}) | ||
|
||
it('openSignInModal', async () => { | ||
const wrapper = getWrapper(false) | ||
await wrapper.find('button').trigger('click') | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
const { setupState } = wrapper.getCurrentComponent() | ||
expect(setupState.isNeededToShowAuthenticateModal).toBe(true) | ||
expect(setupState.authenticateModalType).toBe(EAuthenticateModalType.SIGNIN) | ||
}) | ||
|
||
it('openSignUpModal', async () => { | ||
const wrapper = getWrapper(false) | ||
await wrapper.findAll('button')[1].trigger('click') | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
const { setupState } = wrapper.getCurrentComponent() | ||
expect(setupState.isNeededToShowAuthenticateModal).toBe(true) | ||
expect(setupState.authenticateModalType).toBe(EAuthenticateModalType.SIGNUP) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.