#58 feat: mostrar categorías creadas y actualizadas al sincronizar productos
This commit is contained in:
1105
package-lock.json
generated
1105
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -116,6 +116,39 @@
|
||||
</v-card>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" md="6">
|
||||
<v-card elevation="2">
|
||||
<v-card-title class="bg-indigo text-white">🏷️ Categorías creadas ({{ result.created_categories?.length || 0 }})</v-card-title>
|
||||
<v-card-text>
|
||||
<v-data-table
|
||||
:items="formatResults(result.created_categories)"
|
||||
density="compact"
|
||||
:headers="[
|
||||
{ title: 'ID', key: 'id' },
|
||||
{ title: 'Nombre', key: 'name' }
|
||||
]"
|
||||
></v-data-table>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" md="6">
|
||||
<v-card elevation="2">
|
||||
<v-card-title class="bg-deep-purple text-white">♻️ Categorías actualizadas ({{ result.updated_categories?.length || 0 }})</v-card-title>
|
||||
<v-card-text>
|
||||
<v-data-table
|
||||
:items="formatResults(result.updated_categories)"
|
||||
density="compact"
|
||||
:headers="[
|
||||
{ title: 'ID', key: 'id' },
|
||||
{ title: 'Nombre', key: 'name' },
|
||||
{ title: 'Detalle', key: 'detail' }
|
||||
]"
|
||||
></v-data-table>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" class="text-center mt-4">
|
||||
<v-btn color="primary" @click="$router.push('/')">
|
||||
Volver al inicio
|
||||
|
||||
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