Files
schemas-app/app/components/__tests__/OrganizationSwitcher.spec.ts
T

49 lines
1.7 KiB
TypeScript
Raw Normal View History

import { mount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ref } from 'vue'
const mockSelectOrganization = vi.fn()
const mockOrganizations = [
{ id: '1', name: 'Org 1', apiKeys: [{ name: 'key1' }, { name: 'key2' }] },
{ id: '2', name: 'Org 2', apiKeys: [{ name: 'key3' }] },
{ id: '3', name: 'Org 3', apiKeys: [] },
]
// TODO: Add more comprehensive component tests once vitest module mocking issues are resolved
// For now, the component is indirectly tested through useOrganizationSelector tests
// and manual testing shows it works correctly
// vi.mock is hoisted above the imports and the factory runs once, on the first
// import of the mocked module -- it was never re-applied per test despite sitting
// in beforeEach. vitest 5 rejects the nested call outright rather than silently
// hoisting it, so declare it where it actually executes.
vi.mock('~/composables/useOrganizationSelector', () => ({
useOrganizationSelector: () => ({
organizations: ref([mockOrganizations[0]]),
selectedOrganization: ref(mockOrganizations[0]),
selectedOrgId: ref('1'),
selectOrganization: mockSelectOrganization,
}),
}))
describe('OrganizationSwitcher - Single Organization', () => {
beforeEach(() => {
vi.resetModules()
mockSelectOrganization.mockClear()
})
it('should show a chip for single organization', async () => {
const module = await import('../OrganizationSwitcher.vue')
const wrapper = mount(module.default)
const html = wrapper.html()
// Should show chip
expect(html).toContain('v-chip')
expect(html).toContain('Org 1')
// Menu should not exist
expect(html).not.toContain('v-menu')
})
})