Sort index views by id

This commit is contained in:
josedario87
2025-06-10 00:21:39 -06:00
parent 21274ba1e0
commit 939922cae4
8 changed files with 36 additions and 17 deletions

View File

@@ -86,7 +86,10 @@ const errorMessage = ref('');
// Initialize currentView from the store's default setting for asistencias
const currentView = ref(ui.defaultViewAsistencias);
const asistenciasList = computed(() => asistenciasStore.asistencias);
// Show asistencias ordered by id descending
const asistenciasList = computed(() =>
[...(asistenciasStore.asistencias || [])].sort((a, b) => b.id - a.id)
);
onMounted(async () => {
try {

View File

@@ -85,7 +85,8 @@ describe('AsistenciasIndex.vue', () => {
expect(wrapper.findComponent({ name: 'TablaAsistencias' }).exists()).toBe(true)
expect(wrapper.findComponent({ name: 'TablaAsistencias' }).props('asistencias')).toEqual(asistenciasStoreMock.asistencias)
const expected = [...asistenciasStoreMock.asistencias].sort((a, b) => b.id - a.id)
expect(wrapper.findComponent({ name: 'TablaAsistencias' }).props('asistencias')).toEqual(expected)
expect(wrapper.findComponent({ name: 'CardAsistencia' }).exists()).toBe(false)
})
@@ -99,8 +100,9 @@ describe('AsistenciasIndex.vue', () => {
await wrapper.vm.$nextTick()
const cardWrappers = wrapper.findAllComponents({ name: 'CardAsistencia' })
expect(cardWrappers.length).toBe(asistenciasStoreMock.asistencias.length)
expect(cardWrappers[0].props('asistencia')).toEqual(asistenciasStoreMock.asistencias[0])
const expected = [...asistenciasStoreMock.asistencias].sort((a, b) => b.id - a.id)
expect(cardWrappers.length).toBe(expected.length)
expect(cardWrappers[0].props('asistencia')).toEqual(expected[0])
expect(wrapper.findComponent({ name: 'TablaAsistencias' }).exists()).toBe(false)
})