#49 test: cubrir páginas admin de provenance y NavBar
This commit is contained in:
83
tests/unit/pages/admin/admin-pages.spec.js
Normal file
83
tests/unit/pages/admin/admin-pages.spec.js
Normal file
@@ -0,0 +1,83 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import OrganizationsManagement from '@/components/provenance/admin/OrganizationsManagement.vue'
|
||||
import SuppliersManagement from '@/components/provenance/admin/SuppliersManagement.vue'
|
||||
import GeographyManagement from '@/components/provenance/admin/GeographyManagement.vue'
|
||||
import OrganizationsPage from '@/pages/admin/organizations.vue'
|
||||
import SuppliersPage from '@/pages/admin/suppliers.vue'
|
||||
import GeographyPage from '@/pages/admin/geography.vue'
|
||||
import vuetify from '@/plugins/vuetify'
|
||||
|
||||
function mockApi () {
|
||||
return {
|
||||
getOrganizations: vi.fn().mockResolvedValue([]),
|
||||
getSuppliers: vi.fn().mockResolvedValue([]),
|
||||
getMunicipalities: vi.fn().mockResolvedValue([]),
|
||||
getCountries: vi.fn().mockResolvedValue([]),
|
||||
getDepartments: vi.fn().mockResolvedValue([]),
|
||||
}
|
||||
}
|
||||
|
||||
function mountAdmin (page, api, role) {
|
||||
const pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
const authStore = useAuthStore()
|
||||
authStore.setUser({ role, username: 'admin' })
|
||||
const wrapper = mount(page, {
|
||||
global: { plugins: [pinia, vuetify], provide: { api } },
|
||||
})
|
||||
return { wrapper }
|
||||
}
|
||||
|
||||
async function flushAll (wrapper) {
|
||||
await flushPromises()
|
||||
await wrapper.vm.$nextTick()
|
||||
}
|
||||
|
||||
describe('página admin/organizations', () => {
|
||||
it('renderiza OrganizationsManagement cuando el usuario es administrador', async () => {
|
||||
const { wrapper } = mountAdmin(OrganizationsPage, mockApi(), 'administrator')
|
||||
await flushAll(wrapper)
|
||||
|
||||
expect(wrapper.findComponent(OrganizationsManagement).exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('no renderiza el componente cuando el usuario no es administrador', async () => {
|
||||
const { wrapper } = mountAdmin(OrganizationsPage, mockApi(), 'publico')
|
||||
|
||||
expect(wrapper.findComponent(OrganizationsManagement).exists()).toBe(false)
|
||||
expect(wrapper.text()).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('página admin/suppliers', () => {
|
||||
it('renderiza SuppliersManagement cuando el usuario es administrador', async () => {
|
||||
const { wrapper } = mountAdmin(SuppliersPage, mockApi(), 'administrator')
|
||||
await flushAll(wrapper)
|
||||
|
||||
expect(wrapper.findComponent(SuppliersManagement).exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('no renderiza el componente cuando el usuario no es administrador', async () => {
|
||||
const { wrapper } = mountAdmin(SuppliersPage, mockApi(), 'publico')
|
||||
|
||||
expect(wrapper.findComponent(SuppliersManagement).exists()).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('página admin/geography', () => {
|
||||
it('renderiza GeographyManagement cuando el usuario es administrador', async () => {
|
||||
const { wrapper } = mountAdmin(GeographyPage, mockApi(), 'administrator')
|
||||
await flushAll(wrapper)
|
||||
|
||||
expect(wrapper.findComponent(GeographyManagement).exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('no renderiza el componente cuando el usuario no es administrador', async () => {
|
||||
const { wrapper } = mountAdmin(GeographyPage, mockApi(), 'publico')
|
||||
|
||||
expect(wrapper.findComponent(GeographyManagement).exists()).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user