#58 feat: mostrar categorías creadas y actualizadas al sincronizar productos
This commit is contained in:
82
tests/unit/pages/sincronizar_productos_tryton.spec.js
Normal file
82
tests/unit/pages/sincronizar_productos_tryton.spec.js
Normal file
@@ -0,0 +1,82 @@
|
||||
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 ProductsFromTrytonPage from '@/pages/sincronizar_productos_tryton.vue'
|
||||
import vuetify from '@/plugins/vuetify'
|
||||
|
||||
const syncResult = {
|
||||
checked_tryton_products: [{ id: 190, name: 'Producto 1' }],
|
||||
created_products: [{ id: 3, name: 'Producto 1' }],
|
||||
updated_products: [],
|
||||
failed_products: [],
|
||||
untouched_products: [],
|
||||
created_categories: [
|
||||
{ id: 9, name: 'Abarrotes', external_id: '5' },
|
||||
],
|
||||
updated_categories: [
|
||||
{
|
||||
id: 7,
|
||||
name: 'Cereales',
|
||||
external_id: '7',
|
||||
detail: 'Nombre: Granos → Cereales',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
function mockApi () {
|
||||
return {
|
||||
getProductsFromTryton: vi.fn().mockResolvedValue(syncResult),
|
||||
}
|
||||
}
|
||||
|
||||
async function mountPageAsAdmin (api) {
|
||||
const pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
const authStore = useAuthStore()
|
||||
authStore.setUser({ role: 'administrator', username: 'admin' })
|
||||
const wrapper = mount(ProductsFromTrytonPage, {
|
||||
global: { plugins: [pinia, vuetify], provide: { api } },
|
||||
})
|
||||
await flushPromises()
|
||||
await wrapper.vm.$nextTick()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
async function startSync (wrapper) {
|
||||
const button = wrapper
|
||||
.findAll('button')
|
||||
.find(b => b.text().includes('Iniciar Sincronización'))
|
||||
await button.trigger('click')
|
||||
await flushPromises()
|
||||
await wrapper.vm.$nextTick()
|
||||
}
|
||||
|
||||
describe('página sincronizar_productos_tryton', () => {
|
||||
it('muestra las categorías creadas al sincronizar productos', async () => {
|
||||
const wrapper = await mountPageAsAdmin(mockApi())
|
||||
await startSync(wrapper)
|
||||
|
||||
expect(wrapper.text()).toContain('Categorías creadas (1)')
|
||||
expect(wrapper.text()).toContain('Abarrotes')
|
||||
})
|
||||
|
||||
it('muestra las categorías actualizadas con su detalle', async () => {
|
||||
const wrapper = await mountPageAsAdmin(mockApi())
|
||||
await startSync(wrapper)
|
||||
|
||||
expect(wrapper.text()).toContain('Categorías actualizadas (1)')
|
||||
expect(wrapper.text()).toContain('Cereales')
|
||||
expect(wrapper.text()).toContain('Nombre: Granos → Cereales')
|
||||
})
|
||||
|
||||
it('mantiene el resumen de productos al sincronizar', async () => {
|
||||
const api = mockApi()
|
||||
const wrapper = await mountPageAsAdmin(api)
|
||||
await startSync(wrapper)
|
||||
|
||||
expect(api.getProductsFromTryton).toHaveBeenCalled()
|
||||
expect(wrapper.text()).toContain('✅ Creados (1)')
|
||||
expect(wrapper.text()).toContain('Producto 1')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user