Skip to content

Commit

Permalink
Fix bug that set unavailable instances to available
Browse files Browse the repository at this point in the history
  • Loading branch information
bjester committed Nov 17, 2023
1 parent 43ff9a9 commit 84c169d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ 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;
}
}

// 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);
}
}
Expand All @@ -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;
});
}),
Expand Down

0 comments on commit 84c169d

Please sign in to comment.