From 84c169df1e5bfd43302981b068bb863e923bbef1 Mon Sep 17 00:00:00 2001 From: Blaine Jester Date: Thu, 9 Nov 2023 09:19:24 -0800 Subject: [PATCH] Fix bug that set unavailable instances to available --- .../__test__/SelectDeviceForm.spec.js | 4 ++++ .../views/sync/SelectDeviceModalGroup/useDevices.js | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/__test__/SelectDeviceForm.spec.js b/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/__test__/SelectDeviceForm.spec.js index 92d6525b92d..59e74b4cd83 100644 --- a/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/__test__/SelectDeviceForm.spec.js +++ b/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/__test__/SelectDeviceForm.spec.js @@ -61,6 +61,7 @@ describe('SelectDeviceForm', () => { const { els, wrapper } = makeWrapper(); await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick(); + await wrapper.vm.$nextTick(); expect(wrapper.vm.hasFetched).toBe(true); expect(els.radioButtons()).toHaveLength(6); const server1 = els.radioButtons().at(0); @@ -74,6 +75,7 @@ describe('SelectDeviceForm', () => { const { els, wrapper } = makeWrapper(); await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick(); + await wrapper.vm.$nextTick(); expect(els.radioButtons()).toHaveLength(0); expect(wrapper.text()).toContain('There are no devices yet'); expect(els.KModal().props().submitDisabled).toEqual(true); @@ -89,6 +91,7 @@ describe('SelectDeviceForm', () => { } await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick(); + await wrapper.vm.$nextTick(); expect(radioButtonNIsDisabled(0)).toEqual(false); expect(radioButtonNIsDisabled(1)).toEqual(true); expect(radioButtonNIsDisabled(2)).toEqual(false); @@ -108,6 +111,7 @@ describe('SelectDeviceForm', () => { els.KModal().vm.$emit('submit'); await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick(); + await wrapper.vm.$nextTick(); expect(wrapper.emitted().submit[0][0].id).toEqual('1'); }); diff --git a/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/useDevices.js b/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/useDevices.js index 1ded5d33a98..98ae988fb16 100644 --- a/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/useDevices.js +++ b/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/useDevices.js @@ -88,7 +88,7 @@ export function useDevicesWithFilter(apiParams, filterFunctionOrFunctions) { // result is memoized once successful let isAvailable = true; for (const filterFunction of filterFunctions) { - if (!(await filterFunction(device))) { + if (filterFunction && !(await filterFunction(device))) { isAvailable = false; break; } @@ -96,11 +96,11 @@ export function useDevicesWithFilter(apiParams, filterFunctionOrFunctions) { // Put into refs to trigger reactive behavior in computed devices if (isAvailable) { - if (get(availableIds).indexOf(device.id) < 0) { + if (!get(availableIds).includes(device.id)) { get(availableIds).push(device.id); } } else { - if (get(unavailableIds).indexOf(device.id) < 0) { + if (!get(unavailableIds).includes(device.id)) { get(unavailableIds).push(device.id); } } @@ -119,10 +119,12 @@ export function useDevicesWithFilter(apiParams, filterFunctionOrFunctions) { // use computed array that depends on availableIds/unavailableIds devices: computed(() => { return get(devices) - .filter(d => get(unavailableIds).indexOf(d.id) < 0) + .filter(d => !get(unavailableIds).includes(d.id)) .map(d => { // set unavailable if we haven't determined if it should be filtered out yet - d.available = get(availableIds).indexOf(d.id) >= 0; + if (!get(availableIds).includes(d.id)) { + d.available = false; + } return d; }); }),