Skip to content

Commit

Permalink
test: remove card-body/card-header test and adjust selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Oct 2, 2024
1 parent dc8a2cd commit 183352f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 38 deletions.
11 changes: 8 additions & 3 deletions src/components/Widget/WidgetDocumentsByCreationDateByPath.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,21 @@ export default {
projects() {
return castArray(this.project)
},
pathTreeValue() {
return trimEnd(this.pathTreeValues[0], this.pathSeparator)
pathTreeValue: {
get () {
return trimEnd(this.pathTreeValues[0], this.pathSeparator)
},
set(value) {
this.pathTreeValues = [value]
}
},
pathSeparator() {
return this.$config.get('pathSeparator', '/')
}
},
watch: {
project() {
this.selectedPaths = [this.dataDir]
this.pathTreeValue = this.dataDir
}
},
methods: {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/specs/components/Widget/WidgetDiskUsage.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { shallowMount } from '@vue/test-utils'
import { mount } from '@vue/test-utils'

import { flushPromises } from '~tests/unit/tests_utils'
import { IndexedDocument, letData } from '~tests/unit/es_utils'
Expand All @@ -18,7 +18,7 @@ describe('WidgetDiskUsage.vue', () => {
config.merge({ dataDir: 'dataDir' })
store.commit('insights/reset')
store.commit('insights/project', project)
wrapper = shallowMount(WidgetDiskUsage, { global: { plugins, renderStubDefaultSlot: true }, props })
wrapper = mount(WidgetDiskUsage, { global: { plugins, renderStubDefaultSlot: true }, props })
})

it('should be a Vue instance', () => {
Expand All @@ -29,7 +29,7 @@ describe('WidgetDiskUsage.vue', () => {
await letData(es).have(new IndexedDocument('document', project).withContentLength(10)).commit()
await wrapper.vm.loadData()

expect(wrapper.find('.widget__main-figure').text()).toBe('10.00 B')
expect(wrapper.find('.widget-barometer__value').text()).toBe('10.00 B')
})

it('should reset path on project change', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { shallowMount } from '@vue/test-utils'
import { mount } from '@vue/test-utils'

import { IndexedDocuments, letData } from '~tests/unit/es_utils'
import esConnectionHelper from '~tests/unit/specs/utils/esConnectionHelper'
import CoreSetup from '~tests/unit/CoreSetup'
import WidgetFileBarometer from '@/components/Widget/WidgetFileBarometer'
import WidgetDocuments from '@/components/Widget/WidgetDocuments'

describe('WidgetFileBarometer.vue', () => {
describe('WidgetDocuments.vue', () => {
const { index: project, es } = esConnectionHelper.build()
const api = { elasticsearch: es }
const props = { widget: { title: 'Hello world' } }
Expand All @@ -15,7 +15,7 @@ describe('WidgetFileBarometer.vue', () => {
const { store, plugins } = CoreSetup.init(api).useAll()
store.commit('insights/reset')
store.commit('insights/project', project)
wrapper = shallowMount(WidgetFileBarometer, { global: { plugins, renderStubDefaultSlot: true }, props })
wrapper = mount(WidgetDocuments, { global: { plugins }, props })
})

it('should be a Vue instance', () => {
Expand All @@ -26,6 +26,6 @@ describe('WidgetFileBarometer.vue', () => {
await letData(es).have(new IndexedDocuments().withIndex(project).count(10)).commit()
await wrapper.vm.loadData()

expect(wrapper.find('.widget__main-figure').text()).toBe('10 documents')
expect(wrapper.find('.widget-barometer__value').text()).toBe('10 documents')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe('WidgetDocumentsByCreationDateByPath.vue', () => {
expect(wrapper).toBeTruthy()
})

it('should reset selectedPath on project change', async () => {
await wrapper.setData({ selectedPath: 'path_01' })
expect(wrapper.vm.selectedPath).toBe('path_01')
it('should reset pathTreeValue on project change', async () => {
await wrapper.setData({ pathTreeValue: 'path_01' })
expect(wrapper.vm.pathTreeValue).toBe('path_01')
wrapper.vm.$store.commit('insights/project', anotherProject)
await flushPromises()
expect(wrapper.vm.selectedPath).toBe('dataDir')
expect(wrapper.vm.pathTreeValue).toBe('dataDir')
})
})
23 changes: 0 additions & 23 deletions tests/unit/specs/components/Widget/WidgetFieldFacets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,6 @@ describe('WidgetFieldFacets.vue', () => {
expect(wrapper.classes()).toContain('widget--field-facets')
})

it('renders the title with card-header class when card is true', () => {
const titleElement = wrapper.find('.widget__header')
expect(titleElement.exists()).toBeTruthy()
expect(titleElement.classes()).toContain('card-body')
expect(titleElement.text()).toBe('Test Widget')
})

it('renders the title without card-header class when card is false', async () => {
await wrapper.setProps({
widget: new widgets.WidgetFieldFacets({
title: 'Test Widget',
card: false,
field: 'testField',
routeQueryField: 'contentType'
})
})

const titleElement = wrapper.find('.widget__header')
expect(titleElement.exists()).toBeTruthy()
expect(titleElement.classes()).not.toContain('card-header')
expect(titleElement.text()).toBe('Test Widget')
})

it('loads a page of data', () => {
expect(wrapper.vm.total).toBe(30)
expect(wrapper.vm.items[0]).toEqual({ label: 'foo', count: 10, href: expect.stringContaining('contentType=foo') })
Expand Down

0 comments on commit 183352f

Please sign in to comment.