This commit is contained in:
MeghdadFadaee committed 2026-09-09 16:33:18 +03:30
commit aafddfb146
64 files changed
+17178

No files matched your search

+84
View File
@@ -0,0 +1,84 @@
import { flushPromises, mount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import NovaTenancyPage from '../resources/js/pages/NovaTenancy.vue'
describe('NovaTenancy page', () => {
let get
let post
beforeEach(() => {
get = vi.fn().mockResolvedValue({
data: {
data: [
{
key: 2,
title: 'Beta',
logoUrl: null,
description: 'A focused workspace',
badge: 'Pro',
accent: '#2563eb',
},
],
currentKey: 1,
meta: { currentPage: 1, lastPage: 1, perPage: 12, total: 1 },
},
})
post = vi.fn().mockResolvedValue({
data: {
current: { key: 2, title: 'Beta' },
redirectTo: '/dashboards/main',
},
})
globalThis.Nova = {
config: key =>
key === 'novaTenancy'
? {
current: { key: 1, title: 'Alpha' },
apiBase: '/nova-vendor/nova-tenancy',
searchDebounce: 1,
copy: {
pageTitle: 'Choose workspace',
pageKicker: 'Tenant context',
pageDescription: 'Choose where to work.',
currentTenant: 'Current',
search: 'Search',
searchPlaceholder: 'Search…',
select: 'Open',
selected: 'Selected',
emptyTitle: 'Empty',
emptyDescription: 'No results',
error: 'Error',
retry: 'Retry',
previous: 'Previous',
next: 'Next',
},
}
: null,
request: () => ({ get, post }),
visit: vi.fn(),
$emit: vi.fn(),
}
})
it('loads an authorized page and switches tenant through Nova navigation', async () => {
const wrapper = mount(NovaTenancyPage, {
global: { stubs: { Head: true } },
})
await flushPromises()
expect(wrapper.text()).toContain('Beta')
expect(wrapper.text()).toContain('A focused workspace')
await wrapper.get('.nova-tenancy-select').trigger('click')
await flushPromises()
expect(post).toHaveBeenCalledWith('/nova-vendor/nova-tenancy/current', {
tenant: '2',
})
expect(Nova.$emit).toHaveBeenCalledWith(
'nova-tenancy:changed',
expect.objectContaining({ current: { key: 2, title: 'Beta' } })
)
expect(Nova.visit).toHaveBeenCalledWith('/dashboards/main')
})
})
+54
View File
@@ -0,0 +1,54 @@
import { flushPromises, mount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import TenantAppLogo from '../resources/js/components/TenantAppLogo.vue'
describe('TenantAppLogo', () => {
let listeners
beforeEach(() => {
listeners = {}
globalThis.Nova = {
config: key =>
key === 'novaTenancy'
? {
current: { key: 1, title: 'Alpha' },
apiBase: '/nova-vendor/nova-tenancy',
selectorPath: '/nova-tenancy',
branding: { show_logo: true, show_title: true, link: 'selector' },
copy: { selectTenant: 'Select tenant' },
}
: null,
request: () => ({
get: vi.fn().mockResolvedValue({
data: { current: { key: 1, title: 'Alpha' } },
}),
}),
visit: vi.fn(),
$on: vi.fn((event, callback) => {
listeners[event] = callback
}),
$off: vi.fn(),
}
})
it('renders and reactively updates the selected tenant brand', async () => {
const wrapper = mount(TenantAppLogo)
await flushPromises()
expect(wrapper.text()).toContain('Alpha')
expect(wrapper.get('img').attributes('src')).toContain('/current/logo?tenant=1')
listeners['nova-tenancy:changed']({ current: { key: 2, title: 'Beta' } })
await wrapper.vm.$nextTick()
expect(wrapper.text()).toContain('Beta')
expect(wrapper.get('img').attributes('src')).toContain('/current/logo?tenant=2')
})
it('uses Nova SPA navigation when the brand is clicked', async () => {
const wrapper = mount(TenantAppLogo)
await wrapper.get('.nova-tenancy-brand').trigger('click')
expect(Nova.visit).toHaveBeenCalledWith('/nova-tenancy')
})
})
+25
View File
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import {
currentLogoUrl,
sameTenant,
tenantInitial,
tenantStyle,
} from '../resources/js/tenantState'
describe('tenant state helpers', () => {
it('compares numeric and string tenant keys consistently', () => {
expect(sameTenant(12, '12')).toBe(true)
expect(sameTenant(null, null)).toBe(false)
})
it('builds safe presentation fallbacks', () => {
expect(tenantInitial(' alpha')).toBe('A')
expect(tenantStyle({ accent: null })).toEqual({ '--tenant-accent': '#7c3aed' })
})
it('creates a cache-busted fixed logo endpoint', () => {
expect(currentLogoUrl('/nova-vendor/nova-tenancy', 'a/b', 42)).toBe(
'/nova-vendor/nova-tenancy/current/logo?tenant=a%2Fb&v=42'
)
})
})