mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-21 15:24:09 +00:00
110 lines
3.0 KiB
TypeScript
110 lines
3.0 KiB
TypeScript
import { createTestingPinia } from '@pinia/testing'
|
|
import { mount } from '@vue/test-utils'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { computed } from 'vue'
|
|
import { createI18n } from 'vue-i18n'
|
|
|
|
import TopMenuSection from '@/components/TopMenuSection.vue'
|
|
import CurrentUserButton from '@/components/topbar/CurrentUserButton.vue'
|
|
import LoginButton from '@/components/topbar/LoginButton.vue'
|
|
|
|
const mockData = vi.hoisted(() => ({ isLoggedIn: false, isDesktop: false }))
|
|
|
|
vi.mock('@/composables/auth/useCurrentUser', () => ({
|
|
useCurrentUser: () => {
|
|
return {
|
|
isLoggedIn: computed(() => mockData.isLoggedIn)
|
|
}
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/platform/distribution/types', () => ({
|
|
isCloud: false,
|
|
get isDesktop() {
|
|
return mockData.isDesktop
|
|
}
|
|
}))
|
|
vi.mock('@/stores/firebaseAuthStore', () => ({
|
|
useFirebaseAuthStore: vi.fn(() => ({
|
|
currentUser: null,
|
|
loading: false
|
|
}))
|
|
}))
|
|
|
|
function createWrapper() {
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'en',
|
|
messages: {
|
|
en: {
|
|
sideToolbar: {
|
|
queueProgressOverlay: {
|
|
viewJobHistory: 'View job history',
|
|
expandCollapsedQueue: 'Expand collapsed queue'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
return mount(TopMenuSection, {
|
|
global: {
|
|
plugins: [createTestingPinia({ createSpy: vi.fn }), i18n],
|
|
stubs: {
|
|
SubgraphBreadcrumb: true,
|
|
QueueProgressOverlay: true,
|
|
CurrentUserButton: true,
|
|
LoginButton: true
|
|
},
|
|
directives: {
|
|
tooltip: () => {}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
describe('TopMenuSection', () => {
|
|
beforeEach(() => {
|
|
vi.resetAllMocks()
|
|
mockData.isDesktop = false
|
|
mockData.isLoggedIn = false
|
|
})
|
|
|
|
describe('authentication state', () => {
|
|
describe('when user is logged in', () => {
|
|
beforeEach(() => {
|
|
mockData.isLoggedIn = true
|
|
})
|
|
|
|
it('should display CurrentUserButton and not display LoginButton', () => {
|
|
const wrapper = createWrapper()
|
|
expect(wrapper.findComponent(CurrentUserButton).exists()).toBe(true)
|
|
expect(wrapper.findComponent(LoginButton).exists()).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('when user is not logged in', () => {
|
|
beforeEach(() => {
|
|
mockData.isLoggedIn = false
|
|
})
|
|
|
|
describe('on desktop platform', () => {
|
|
it('should display LoginButton and not display CurrentUserButton', () => {
|
|
mockData.isDesktop = true
|
|
const wrapper = createWrapper()
|
|
expect(wrapper.findComponent(LoginButton).exists()).toBe(true)
|
|
expect(wrapper.findComponent(CurrentUserButton).exists()).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('on web platform', () => {
|
|
it('should not display CurrentUserButton and not display LoginButton', () => {
|
|
const wrapper = createWrapper()
|
|
expect(wrapper.findComponent(CurrentUserButton).exists()).toBe(false)
|
|
expect(wrapper.findComponent(LoginButton).exists()).toBe(false)
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|