Skip to content

Commit

Permalink
fix: hide output message while fetching annotation search results (#2519
Browse files Browse the repository at this point in the history
)

* Visually hide output message while fetching

* Add and fix unit tests
  • Loading branch information
LeoniePeters authored Dec 16, 2024
1 parent 18371ba commit 0a7ec56
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<output
form="media-annotation-search-form"
class="px-3"
:class="{ 'visually-hidden': !noResults }"
:class="{ 'visually-hidden': !noResults || !annotationsFetched }"
>
{{ noResults ? $t('noResults') : $t('searchHasLoaded', [$n(annotationsCount)]) }}
</output>
Expand Down Expand Up @@ -77,6 +77,7 @@
data() {
return {
annotationsCount: null,
annotationsFetched: false,
annoQuery: this.$route.query.fulltext || null,
query: this.$route.query.fulltext || null
};
Expand All @@ -96,6 +97,7 @@
methods: {
handleSubmitForm() {
this.annotationsFetched = false;
this.$router.push({ ...this.$route, query: { ...this.$route.query, fulltext: this.query } });
},
Expand All @@ -110,6 +112,7 @@
handleAnnotationsFetched(annotationsLength) {
this.annotationsCount = annotationsLength;
this.annotationsFetched = true;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createLocalVue, shallowMount } from '@vue/test-utils';
import BootstrapVue from 'bootstrap-vue';
import sinon from 'sinon';

import MediaAnnotationSearch from '@/components/media/MediaAnnotationSearch.vue';

const localVue = createLocalVue();
localVue.use(BootstrapVue);
const routerPushSpy = sinon.spy();
const fulltext = 'something';

Expand All @@ -25,7 +27,7 @@ const factory = ({ data, propsData, mocks } = {}) => shallowMount(MediaAnnotatio
...mocks
},
localVue,
stubs: ['b-button', 'b-form', 'b-form-group', 'b-form-input', 'MediaAnnotationList']
stubs: ['MediaAnnotationList']
});

describe('components/media/MediaAnnotationSearch', () => {
Expand Down Expand Up @@ -68,15 +70,29 @@ describe('components/media/MediaAnnotationSearch', () => {

expect(text).toBe('noResults');
});
});

describe('on form submit', () => {
it('updates the route and resets the fetch state', async() => {
const query = 'euro';
const wrapper = factory({ data: { query } });

wrapper.find('#media-annotation-search-form').trigger('submit.prevent');
await wrapper.vm.$nextTick();

expect(routerPushSpy.calledWith({ query: { fulltext: 'euro' } })).toBe(true);
expect(wrapper.vm.annotationsFetched).toEqual(false);
});

it('hides the no results message while fetching new results', async() => {
const wrapper = factory({ data: { annoQuery: 'euro' } });
wrapper.vm.annotationsFetched = true;

// FIXME: submit.prevent trigger isn't working here (but does when rendered)
// it('updates the route when the form is submitted', async() => {
// const wrapper = factory({ data: { query } });
//
// wrapper.find('#media-annotation-search-form').trigger('submit.prevent');
// await wrapper.vm.$nextTick();
//
// expect(routerPushSpy.calledWith({ query: { query } })).toBe(true);
// });
wrapper.find('#media-annotation-search-form').trigger('submit.prevent');
await wrapper.vm.$nextTick();

expect(wrapper.vm.annotationsFetched).toEqual(false);
expect(wrapper.find('output.visually-hidden').exists()).toBe(true);
});
});
});

0 comments on commit 0a7ec56

Please sign in to comment.