Skip to content

Commit

Permalink
adjust report viewer unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Nov 8, 2024
1 parent 549c6e4 commit ab24786
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { flushPromises, mount } from '@vue/test-utils'
import { describe, it, vi, expect } from 'vitest'
import { createTestingPinia } from '@pinia/testing'
import { store } from '@/stores/store'
import { MetricType } from '@/model/MetricType.ts'
import { MetricJsonIdentifier } from '@/model/MetricType.ts'
import { router } from '@/router'
import OptionsSelector from '@/components/optionsSelectors/OptionsSelectorComponent.vue'
import OptionComponent from '@/components/optionsSelectors/OptionComponent.vue'
Expand All @@ -19,8 +19,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'A',
secondSubmissionId: 'B',
similarities: {
[MetricType.AVERAGE]: 1,
[MetricType.MAXIMUM]: 0.5
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 1,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 0.5
},
clusterIndex: -1
},
Expand All @@ -30,8 +30,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'C',
secondSubmissionId: 'D',
similarities: {
[MetricType.AVERAGE]: 0.5,
[MetricType.MAXIMUM]: 1
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.5,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 1
},
clusterIndex: -1
}
Expand Down Expand Up @@ -68,8 +68,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'A',
secondSubmissionId: 'B',
similarities: {
[MetricType.AVERAGE]: 0.3,
[MetricType.MAXIMUM]: 0.5
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.3,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 0.5
},
clusterIndex: -1
},
Expand All @@ -79,8 +79,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'C',
secondSubmissionId: 'D',
similarities: {
[MetricType.AVERAGE]: 0.5,
[MetricType.MAXIMUM]: 1
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.5,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 1
},
clusterIndex: -1
},
Expand All @@ -90,8 +90,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'E',
secondSubmissionId: 'F',
similarities: {
[MetricType.AVERAGE]: 0.3,
[MetricType.MAXIMUM]: 0.1
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.3,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 0.1
},
clusterIndex: -1
},
Expand All @@ -101,8 +101,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'H',
secondSubmissionId: 'G',
similarities: {
[MetricType.AVERAGE]: 0.9,
[MetricType.MAXIMUM]: 0.2
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.9,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 0.2
},
clusterIndex: -1
}
Expand Down Expand Up @@ -152,8 +152,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'A',
secondSubmissionId: 'B',
similarities: {
[MetricType.AVERAGE]: 0.3,
[MetricType.MAXIMUM]: 0.5
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.3,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 0.5
},
clusterIndex: -1
},
Expand All @@ -163,8 +163,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'C',
secondSubmissionId: 'D',
similarities: {
[MetricType.AVERAGE]: 0.4,
[MetricType.MAXIMUM]: 1
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.4,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 1
},
clusterIndex: -1
},
Expand All @@ -174,8 +174,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'E',
secondSubmissionId: 'F',
similarities: {
[MetricType.AVERAGE]: 0.3,
[MetricType.MAXIMUM]: 0.1
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.3,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 0.1
},
clusterIndex: -1
},
Expand All @@ -185,8 +185,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'H',
secondSubmissionId: 'G',
similarities: {
[MetricType.AVERAGE]: 0.9,
[MetricType.MAXIMUM]: 0.2
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.9,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 0.2
},
clusterIndex: -1
}
Expand Down Expand Up @@ -249,8 +249,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'A',
secondSubmissionId: 'B',
similarities: {
[MetricType.AVERAGE]: 0.3,
[MetricType.MAXIMUM]: 0.5
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.3,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 0.5
},
clusterIndex: 0
},
Expand All @@ -260,8 +260,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'C',
secondSubmissionId: 'D',
similarities: {
[MetricType.AVERAGE]: 0.5,
[MetricType.MAXIMUM]: 1
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.5,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 1
},
clusterIndex: 1
},
Expand All @@ -271,8 +271,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'E',
secondSubmissionId: 'F',
similarities: {
[MetricType.AVERAGE]: 0.3,
[MetricType.MAXIMUM]: 0.1
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.3,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 0.1
},
clusterIndex: 2
},
Expand All @@ -282,8 +282,8 @@ describe('ComparisonTable', async () => {
firstSubmissionId: 'H',
secondSubmissionId: 'G',
similarities: {
[MetricType.AVERAGE]: 0.9,
[MetricType.MAXIMUM]: 0.2
[MetricJsonIdentifier.AVERAGE_SIMILARITY]: 0.9,
[MetricJsonIdentifier.MAXIMUM_SIMILARITY]: 0.2
},
clusterIndex: -1
}
Expand Down Expand Up @@ -329,7 +329,7 @@ describe('ComparisonTable', async () => {
expect(displayedComparisonsMaxSorted[2].firstSubmissionId).toBe('H')
expect(displayedComparisonsMaxSorted[3].firstSubmissionId).toBe('E')

await metricOptions[2].trigger('click')
await metricOptions[7].trigger('click')
await flushPromises()

// Test sorting by cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { flushPromises, mount } from '@vue/test-utils'
import { describe, it, vi, expect } from 'vitest'
import { createTestingPinia } from '@pinia/testing'
import { store } from '@/stores/store'
import { MetricType } from '@/model/MetricType.ts'
import { MetricJsonIdentifier } from '@/model/MetricType.ts'
import ButtonComponent from '@/components/ButtonComponent.vue'
import OptionsSelector from '@/components/optionsSelectors/OptionsSelectorComponent.vue'
import OptionComponent from '@/components/optionsSelectors/OptionComponent.vue'
Expand Down Expand Up @@ -41,21 +41,31 @@ describe('ComparisonTableFilter', async () => {
expect(wrapper.text()).toContain('Cluster')

const options = wrapper.getComponent(OptionsSelector).findAllComponents(OptionComponent)

expectHighlighting(0)

await options[1].trigger('click')
expect(store().uiState.comparisonTableSortingMetric).toBe(MetricType.MAXIMUM)
expect(store().uiState.comparisonTableSortingMetric).toBe(
MetricJsonIdentifier.MAXIMUM_SIMILARITY
)
expect(store().uiState.comparisonTableClusterSorting).toBeFalsy()
expectHighlighting(1)

await options[2].trigger('click')
expect(store().uiState.comparisonTableSortingMetric).toBe(MetricType.AVERAGE)
await options[4].trigger('click')
expect(store().uiState.comparisonTableSortingMetric).toBe(MetricJsonIdentifier.SYMMETRIC)
expect(store().uiState.comparisonTableClusterSorting).toBeFalsy()
expectHighlighting(4)

await options[7].trigger('click')
expect(store().uiState.comparisonTableSortingMetric).toBe(
MetricJsonIdentifier.AVERAGE_SIMILARITY
)
expect(store().uiState.comparisonTableClusterSorting).toBeTruthy()
expectHighlighting(2)
expectHighlighting(7)

await options[0].trigger('click')
expect(store().uiState.comparisonTableSortingMetric).toBe(MetricType.AVERAGE)
expect(store().uiState.comparisonTableSortingMetric).toBe(
MetricJsonIdentifier.AVERAGE_SIMILARITY
)
expect(store().uiState.comparisonTableClusterSorting).toBeFalsy()
expectHighlighting(0)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'
import MetricSelector from '@/components/optionsSelectors/MetricSelector.vue'
import { MetricType } from '@/model/MetricType'
import { MetricJsonIdentifier, MetricTypes } from '@/model/MetricType'

describe('OptionSelectorComponent', () => {
it('renders all options', async () => {
Expand All @@ -12,20 +12,22 @@ describe('OptionSelectorComponent', () => {
})

expect(wrapper.text()).toContain('Test:')
expect(wrapper.text()).toContain('Average Similarity')
expect(wrapper.text()).toContain('Maximum Similarity')
for (const metric of MetricTypes.METRIC_LIST) {
expect(wrapper.text()).toContain(metric.longName)
}
})

it('renders given metrics only', async () => {
const wrapper = mount(MetricSelector, {
props: {
title: 'Test:',
metrics: [MetricType.AVERAGE]
metrics: [MetricJsonIdentifier.AVERAGE_SIMILARITY, MetricJsonIdentifier.MINIMUM_SIMILARITY]
}
})

expect(wrapper.text()).toContain('Test:')
expect(wrapper.text()).toContain('Average Similarity')
expect(wrapper.text()).toContain('Minimum Similarity')
expect(wrapper.text()).not.toContain('Maximum Similarity')
})

Expand All @@ -40,6 +42,8 @@ describe('OptionSelectorComponent', () => {

expect(wrapper.emitted('selectionChanged')).toBeTruthy()
expect(wrapper.emitted('selectionChanged')?.length).toBe(1)
expect(wrapper.emitted('selectionChanged')?.[0]).toEqual([MetricType.MAXIMUM])
expect(wrapper.emitted('selectionChanged')?.[0]).toEqual([
MetricJsonIdentifier.MAXIMUM_SIMILARITY
])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { it, beforeEach, describe, expect } from 'vitest'
import validNew from './ValidComparison.json'
import { ComparisonFactory } from '@/model/factories/ComparisonFactory'
import { store } from '@/stores/store'
import { MetricType } from '@/model/MetricType'
import { MetricJsonIdentifier } from '@/model/MetricType'
import { setActivePinia, createPinia } from 'pinia'

describe('Test JSON to Comparison', () => {
Expand Down Expand Up @@ -59,8 +59,14 @@ describe('Test JSON to Comparison', () => {
expect(result).toBeDefined()
expect(result.firstSubmissionId).toBe('root1')
expect(result.secondSubmissionId).toBe('root2')
expect(result.similarities[MetricType.AVERAGE]).toBe(0.45)
expect(result.similarities[MetricType.MAXIMUM]).toBe(0.5)
expect(result.similarities[MetricJsonIdentifier.AVERAGE_SIMILARITY]).toBe(0.45)
expect(result.similarities[MetricJsonIdentifier.MAXIMUM_SIMILARITY]).toBe(0.5)
expect(result.similarities[MetricJsonIdentifier.MINIMUM_SIMILARITY]).toBe(0.4)
expect(result.similarities[MetricJsonIdentifier.INTERSECTION]).toBe(229)
expect(result.similarities[MetricJsonIdentifier.SYMMETRIC]).toBe(0.5)
expect(result.similarities[MetricJsonIdentifier.LONGEST_MATCH]).toBe(139)
expect(result.similarities[MetricJsonIdentifier.OVERALL]).toBe(916)

expect(result.filesOfFirstSubmission).toBeDefined()
expect(result.filesOfSecondSubmission).toBeDefined()
expect(result.allMatches.length).toBe(4)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeEach, describe, it, expect } from 'vitest'
import { OptionsFactory } from '@/model/factories/OptionsFactory'
import { ParserLanguage } from '@/model/Language'
import { MetricType } from '@/model/MetricType'
import { MetricTypes } from '@/model/MetricType'
import validOptions from './ValidOptions.json'
import { setActivePinia, createPinia } from 'pinia'
import { store } from '@/stores/store'
Expand All @@ -25,12 +25,12 @@ describe('Test JSON to Options', async () => {
subDirectoryName: 'src/',
fileSuffixes: ['.java', '.JAVA'],
exclusionFileName: 'ex.txt',
similarityMetric: MetricType.AVERAGE,
similarityMetric: MetricTypes.AVERAGE_SIMILARITY,
similarityThreshold: 0.0,
maxNumberComparisons: 500,
clusterOptions: {
enabled: true,
similarityMetric: MetricType.AVERAGE,
similarityMetric: MetricTypes.AVERAGE_SIMILARITY,
spectralBandwidth: 20.0,
spectralGaussianProcessVariance: 0.0025000000000000005,
spectralMinRuns: 5,
Expand Down
Loading

0 comments on commit ab24786

Please sign in to comment.