63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { mount } from '@vue/test-utils'
|
|
import ProvenanceGraph from '@/components/provenance/ProvenanceGraph.vue'
|
|
import ProvenanceSection from '@/components/provenance/ProvenanceSection.vue'
|
|
import vuetify from '@/plugins/vuetify'
|
|
|
|
vi.mock('@/components/graph/VisChart.vue', () => ({
|
|
default: {
|
|
name: 'VisChart',
|
|
template: '<div class="vis-chart-stub" />',
|
|
props: ['nodes', 'edges', 'height', 'options'],
|
|
},
|
|
}))
|
|
|
|
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(ProvenanceGraph).exists()).toBe(false)
|
|
})
|
|
|
|
it('no renderiza nada cuando provenance es una lista vacía', () => {
|
|
const wrapper = mountSection({ provenance: [] })
|
|
|
|
expect(wrapper.findComponent(ProvenanceGraph).exists()).toBe(false)
|
|
})
|
|
|
|
it('muestra el gráfico unificado con su título cuando hay provenance', () => {
|
|
const wrapper = mountSection()
|
|
|
|
expect(wrapper.findComponent(ProvenanceGraph).exists()).toBe(true)
|
|
expect(wrapper.text()).toContain('Origen e historia de los productos')
|
|
})
|
|
|
|
it('pasa el provenance al gráfico', () => {
|
|
const wrapper = mountSection()
|
|
|
|
expect(wrapper.findComponent(ProvenanceGraph).props('provenance')).toStrictEqual(provenance)
|
|
})
|
|
})
|