Skip to content

Commit

Permalink
fix(#9): FE - Adding unit test for metamine visualization components …
Browse files Browse the repository at this point in the history
…and pages
  • Loading branch information
tholulomo committed Oct 14, 2023
1 parent 98474de commit 735dfcc
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 0 deletions.
50 changes: 50 additions & 0 deletions app/tests/unit/components/metamineNU/paramSelector.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import createWrapper from '../../../jest/script/wrapper'
import { enableAutoDestroy } from '@vue/test-utils'
import ParamSelector from '@/components/metamine/visualizationNU/ParamSelector.vue'

const elementMock = { addEventListener: jest.fn() }
jest.spyOn(document, 'getElementById').mockImplementation(() => elementMock)
describe('ParamSelector.vue', () => {
let wrapper
beforeEach(async () => {
wrapper = await createWrapper(ParamSelector, { }, false)
})

enableAutoDestroy(afterEach)
afterEach(async () => {
wrapper.destroy()
})

it('renders layout properly ', () => {
expect(wrapper.find('div > div.md-title.article_metadata_strong.section_footer.utility-transparentbg').exists()).toBe(true)
expect(wrapper.find('div > div.article_metadata_strong').exists()).toBe(true)
expect(wrapper.findAll('div > div.article_metadata_strong').length).toBe(2)
expect(wrapper.find('div > div.u_display-flex.md-layout.u--layout-flex-justify-sb.tool_page').exists()).toBe(true)
})

it('renders flex layout properly ', () => {
const container = wrapper.find('div.u_display-flex.md-layout.u--layout-flex-justify-sb')
expect(container.find('div.md-layout-item.md-size-80').exists()).toBe(true)
expect(container.find('div.utility-roverflow.md-layout-item.md-size-20').exists()).toBe(true)
})

it('renders slider input properly ', async () => {
const dispatch = jest.spyOn(wrapper.vm.$store, 'dispatch')
const slider = wrapper.find('input.nuplot-range-slider.u--margin-centered.u_centralize_text.viz-u-postion__abs.utility-transparentbg')
slider.element.value = '25'
await slider.trigger('change')

expect(wrapper.vm.knnUmap).toBe('25')
expect(dispatch).toHaveBeenCalledWith('metamineNU/setKnnUmap', '25')
})

it('renders text input properly ', async () => {
const dispatch = jest.spyOn(wrapper.vm.$store, 'dispatch')
const input = wrapper.findComponent('md-input-stub')
input.element.value = '10'
await input.trigger('change')

expect(wrapper.vm.knnUmap).toBe('25')
expect(dispatch).toHaveBeenCalledWith('metamineNU/setKnnUmap', '25')
})
})
109 changes: 109 additions & 0 deletions app/tests/unit/components/metamineNU/umap.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions app/tests/unit/modules/metamine/organizeByName.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { organizeByName } from '../../../../src/modules/metamine/utils/organizeByName'

const datasetSample = [
{
name: 'test',
color: 'red',
C11: parseFloat('12'),
C12: parseFloat('10.33')
},
{
name: 'sample',
color: 'yellow',
C11: parseFloat('12'),
C12: parseFloat('10.33')
},
{
name: 'test',
color: 'orange',
C11: parseFloat('12'),
C12: parseFloat('10.33')
},
{
name: 'sample',
color: 'green',
C11: parseFloat('12'),
C12: parseFloat('10.33')
},
{
name: 'test',
color: 'blue',
C11: parseFloat('12'),
C12: parseFloat('10.33')
}
]
const organizedDataset = [
{
name: 'test',
color: 'red',
data: [datasetSample[0], datasetSample[2], datasetSample[4]]
},
{
name: 'sample',
color: 'yellow',
data: [datasetSample[1], datasetSample[3]]
}
]

describe('articleMetadata.js', () => {
it('organizeByName organizes data by name and returns an array of object ', () => {
const result = organizeByName(datasetSample)
expect(result).toEqual(organizedDataset)
})
})
59 changes: 59 additions & 0 deletions app/tests/unit/modules/metamine/processData.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { processData } from '../../../../src/modules/metamine/utils/processData'

const index = 0
const dataset = {
youngs: '2e10,0.55,13',
poisson: '-2e10,0.55,13',
dataset_name: process.env?.MM_USER ?? 'Frontend',
dataset_color: 'Blue',
C11: '10.33',
C12: '10.33',
C22: '10.33',
C16: '10.33',
C26: '10.33',
C66: '10.33',
condition: 'stable',
symmetry: 'curve',
CM0: 'random strings',
CM1: 'random strings',
CM0_E: 'random strings',
CM0_nu: 'random strings',
CM1_E: 'random strings',
CM1_nu: 'random strings',
geometry_full: 'random strings'
}
const youngs = [20000000000, 0.55, 13]
const poisson = [-20000000000, 0.55, 13]

const result = {
index: index,
name: dataset.dataset_name,
color: dataset.dataset_color,
C11: parseFloat(dataset.C11),
C12: parseFloat(dataset.C12),
C22: parseFloat(dataset.C22),
C16: parseFloat(dataset.C16),
C26: parseFloat(dataset.C26),
C66: parseFloat(dataset.C66),
condition: dataset.condition,
symmetry: dataset.symmetry,
CM0: dataset.CM0,
CM1: dataset.CM1,
CM0_E: dataset.CM0_E,
CM0_nu: dataset.CM0_nu,
CM1_E: dataset.CM1_E,
CM1_nu: dataset.CM1_nu,
geometry: dataset.geometry_full,
youngs: youngs,
poisson: poisson,
"Minimal directional Young's modulus [N/m]": Math.min(...(youngs || [])),
"Maximal directional Young's modulus [N/m]": Math.max(...(youngs || [])),
"Minimal Poisson's ratio [-]": Math.min(...(poisson || [])),
"Maximal Poisson's ratio [-]": Math.max(...(poisson || []))
}

describe('processData function', () => {
it('returns a processed dataset', () => {
expect(processData(dataset, index)).toEqual(result)
})
})
Loading

0 comments on commit 735dfcc

Please sign in to comment.