#49 feat: gráficos de provenance (proveedores-organizaciones y territorios) en el resumen público
This commit is contained in:
72
tests/unit/components/provenance/ProvenanceSection.spec.js
Normal file
72
tests/unit/components/provenance/ProvenanceSection.spec.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import ProductSupplierOrganizationChart from '@/components/provenance/ProductSupplierOrganizationChart.vue'
|
||||
import ProductTerritoryChart from '@/components/provenance/ProductTerritoryChart.vue'
|
||||
import ProvenanceSection from '@/components/provenance/ProvenanceSection.vue'
|
||||
import vuetify from '@/plugins/vuetify'
|
||||
|
||||
const cy = {
|
||||
on: vi.fn(),
|
||||
elements: vi.fn(() => ({ remove: vi.fn() })),
|
||||
add: vi.fn(),
|
||||
layout: vi.fn(() => ({ run: vi.fn() })),
|
||||
destroy: vi.fn(),
|
||||
}
|
||||
|
||||
vi.mock('cytoscape', () => ({
|
||||
default: vi.fn(() => cy),
|
||||
}))
|
||||
|
||||
const provenance = [
|
||||
{
|
||||
product: { id: 1, name: 'Panela regional por Kg' },
|
||||
suppliers: [
|
||||
{
|
||||
supplier: { id: 5, name: 'Asociación La Mesa' },
|
||||
organization: { id: 3, name: 'Red de Economía Solidaria' },
|
||||
municipality: { id: 7, name: 'La Mesa' },
|
||||
department: { id: 2, name: 'Cundinamarca' },
|
||||
country: { id: 1, name: 'Colombia', code: 'CO' },
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
function mountSection (props = {}) {
|
||||
return mount(ProvenanceSection, {
|
||||
props: { provenance, ...props },
|
||||
global: { plugins: [vuetify] },
|
||||
})
|
||||
}
|
||||
|
||||
describe('ProvenanceSection', () => {
|
||||
it('no renderiza nada cuando no hay provenance', () => {
|
||||
const wrapper = mountSection({ provenance: null })
|
||||
|
||||
expect(wrapper.findComponent(ProductSupplierOrganizationChart).exists()).toBe(false)
|
||||
expect(wrapper.findComponent(ProductTerritoryChart).exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('no renderiza nada cuando provenance es una lista vacía', () => {
|
||||
const wrapper = mountSection({ provenance: [] })
|
||||
|
||||
expect(wrapper.findComponent(ProductSupplierOrganizationChart).exists()).toBe(false)
|
||||
expect(wrapper.findComponent(ProductTerritoryChart).exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('muestra los dos gráficos con sus títulos cuando hay provenance', () => {
|
||||
const wrapper = mountSection()
|
||||
|
||||
expect(wrapper.findComponent(ProductSupplierOrganizationChart).exists()).toBe(true)
|
||||
expect(wrapper.findComponent(ProductTerritoryChart).exists()).toBe(true)
|
||||
expect(wrapper.text()).toContain('Proveedores y organizaciones')
|
||||
expect(wrapper.text()).toContain('Departamento y municipio')
|
||||
})
|
||||
|
||||
it('pasa el provenance a ambos gráficos', () => {
|
||||
const wrapper = mountSection()
|
||||
|
||||
expect(wrapper.findComponent(ProductSupplierOrganizationChart).props('provenance')).toStrictEqual(provenance)
|
||||
expect(wrapper.findComponent(ProductTerritoryChart).props('provenance')).toStrictEqual(provenance)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user