Skip to content

Commit

Permalink
[refactor] clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Mar 5, 2020
1 parent f91f760 commit 6b1fcf4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/api/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export function datasharePlugin (Client, config, components) {
default_field: fields.length ? undefined : '*'
})
.orQuery('has_parent', 'parent_type', 'Document', {
'inner_hits': {
'size': 30
inner_hits: {
size: 30
}
}, sub => sub.query('match', 'content', query))
)
Expand Down Expand Up @@ -164,7 +164,7 @@ export function datasharePlugin (Client, config, components) {

const elasticsearch = new es.Client({
host: process.env.VUE_APP_ES_HOST || window.location.hostname + ':' + window.location.port + '/api/index/search',
plugins: [ datasharePlugin ]
plugins: [datasharePlugin]
})

export default elasticsearch
8 changes: 4 additions & 4 deletions src/components/FilterBoilerplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ import throttle from 'lodash/throttle'
import toLower from 'lodash/toLower'
import filters from '@/mixins/filters'
import Hook from './Hook'
import Hook from '@/components/Hook'
export default {
name: 'FilterBoilerplate',
Expand All @@ -107,11 +107,11 @@ export default {
},
data () {
return {
filterQuery: '',
collapseItems: !this.asyncItems,
filterQuery: '',
isInitialized: !!this.asyncItems,
results: [],
moreToDisplay: false
moreToDisplay: false,
results: []
}
},
watch: {
Expand Down
6 changes: 3 additions & 3 deletions src/components/FilterSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export default {
}
},
components: {
FilterText,
FilterYesNo,
FilterDate,
FilterDateRange,
FilterPath,
FilterNamedEntity,
FilterPath,
FilterText,
FilterYesNo,
InfiniteLoading
},
data () {
Expand Down
1 change: 0 additions & 1 deletion src/components/Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,4 @@ export default {
}
}
}
</style>
2 changes: 1 addition & 1 deletion src/components/SearchResultsHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
</template>

<script>
import { mapState } from 'vuex'
import cloneDeep from 'lodash/cloneDeep'
import min from 'lodash/min'
import { mapState } from 'vuex'
import Pagination from '@/components/Pagination'
import SearchResultsAppliedFilters from '@/components/SearchResultsAppliedFilters'
Expand Down
28 changes: 14 additions & 14 deletions tests/unit/specs/components/FilterText.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import FilterText from '@/components/FilterText'
import { IndexedDocument, letData } from 'tests/unit/es_utils'
import messagesFr from '@/lang/fr'

const { localVue, router, store, wait } = Core.init(createLocalVue()).useAll()
const { i18n, localVue, router, store, wait } = Core.init(createLocalVue()).useAll()

describe('FilterText.vue', () => {
const index = toLower('FilterText')
Expand All @@ -23,12 +23,12 @@ describe('FilterText.vue', () => {

beforeEach(() => {
wrapper = mount(FilterText, {
i18n,
localVue,
router,
store,
wait,
propsData: { filter: find(store.getters['search/instantiatedFilters'], { name: 'contentType' }) },
mocks: { $t: msg => msg, $te: msg => msg, $n: msg => msg }
propsData: { filter: find(store.getters['search/instantiatedFilters'], { name: 'contentType' }) }
})
store.commit('search/setGlobalSearch', true)
store.commit('search/index', index)
Expand Down Expand Up @@ -319,14 +319,14 @@ describe('FilterText.vue', () => {

it('should display an "All" item on top of others items, and this item should be active by default', async () => {
await letData(es).have(new IndexedDocument('document_01', index)
.withContentType('text/javascript')).commit()
.withContentType('type_01')).commit()
await letData(es).have(new IndexedDocument('document_02', index)
.withContentType('text/html')).commit()
.withContentType('type_02')).commit()

await wrapper.vm.root.aggregate()

expect(wrapper.findAll('.filter__items__all')).toHaveLength(1)
expect(wrapper.find('.filter__items__all .filter__items__item__label').text()).toBe('all')
expect(wrapper.find('.filter__items__all .filter__items__item__label').text()).toBe('All')
expect(wrapper.findAll('.filter__items__all .filter__items__item__count').at(0).text()).toBe('2')
expect(wrapper.find('.filter__items__all .custom-control-input').element.checked).toBeTruthy()
expect(wrapper.vm.root.total).toBe(2)
Expand All @@ -337,17 +337,17 @@ describe('FilterText.vue', () => {
const spyRefreshRoute = jest.spyOn(wrapper.vm.root, 'refreshRoute')

await letData(es).have(new IndexedDocument('document_01', index)
.withContentType('text/type_01')).commit()
.withContentType('type_01')).commit()
await letData(es).have(new IndexedDocument('document_02', index)
.withContentType('text/type_02')).commit()
.withContentType('type_02')).commit()
await letData(es).have(new IndexedDocument('document_03', index)
.withContentType('text/type_02')).commit()
.withContentType('type_02')).commit()
await letData(es).have(new IndexedDocument('document_04', index)
.withContentType('text/type_03')).commit()
.withContentType('type_03')).commit()
await letData(es).have(new IndexedDocument('document_05', index)
.withContentType('text/type_03')).commit()
.withContentType('type_03')).commit()
await letData(es).have(new IndexedDocument('document_06', index)
.withContentType('text/type_03')).commit()
.withContentType('type_03')).commit()

await wrapper.vm.root.aggregate()
wrapper.find('.filter__items__item:nth-child(2) input').trigger('click')
Expand Down Expand Up @@ -405,14 +405,14 @@ describe('FilterText.vue', () => {
await wrapper.vm.root.aggregate()

expect(wrapper.findAll('.filter__items__item')).toHaveLength(2)
expect(wrapper.findAll('.filter__items__item .filter__items__item__label').at(0).text()).toBe('filter.level.level00')
expect(wrapper.findAll('.filter__items__item .filter__items__item__label').at(0).text()).toBe('File on disk')
})

it('should display the extraction level filter with correct labels in French', async () => {
const i18n = new VueI18n({ locale: 'fr', messages: { fr: messagesFr } })
wrapper = mount(FilterText, {
localVue,
i18n,
localVue,
router,
store,
wait,
Expand Down

0 comments on commit 6b1fcf4

Please sign in to comment.