Skip to content

Commit

Permalink
update tests due to primevue migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Logende committed Feb 6, 2025
1 parent 2de1388 commit cdeae55
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 44 deletions.
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 {afterEach, beforeEach, describe, expect, it, test, vi} from 'vitest';
import BooleanProperty from '../BooleanProperty.vue';
import SelectButton from 'primevue/selectbutton';
Expand All @@ -21,10 +21,10 @@ describe('BooleanProperty', () => {
let wrapper: any;
let selectButton: any;

function shallowMountBeforeEach(props: any) {
function mountBeforeEach(props: any) {
beforeEach(() => {
// @ts-ignore
wrapper = shallowMount(BooleanProperty, {
wrapper = mount(BooleanProperty, {
props: props,
});
selectButton = wrapper.findComponent(SelectButton);
Expand All @@ -39,7 +39,7 @@ describe('BooleanProperty', () => {
['false', false],
['undefined', undefined],
])(`with value %s`, (type, data) => {
shallowMountBeforeEach({
mountBeforeEach({
propertyName: 'foo',
propertyData: data,
validationResults: new ValidationResult([]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import {shallowMount} from '@vue/test-utils';
import {mount} from '@vue/test-utils';
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import EnumProperty from '@/components/panels/gui-editor/properties/EnumProperty.vue';
import Select from 'primevue/select';
import {ValidationResult} from '@/schema/validationService';
import {JsonSchemaWrapper} from '@/schema/jsonSchemaWrapper';
import {SessionMode} from '@/store/sessionMode';
import { config } from '@vue/test-utils';
import { defaultOptions } from 'primevue/config';


config.global.mocks['$primevue'] = {
config: defaultOptions
};

// avoid constructing useDataLink store through imports, it is not required for this component
vi.mock('@/data/useDataLink', () => ({
Expand All @@ -25,10 +32,10 @@ describe('EnumProperty', () => {
let wrapper: any;
let dropdown: any;

function shallowMountBeforeEach(props: any) {
function mountBeforeEach(props: any) {
beforeEach(() => {
// @ts-ignore
wrapper = shallowMount(EnumProperty, {
wrapper = mount(EnumProperty, {
props: props,
});
dropdown = wrapper.findComponent(Select);
Expand All @@ -52,7 +59,7 @@ describe('EnumProperty', () => {
false
),
};
shallowMountBeforeEach(stringValuesProps);
mountBeforeEach(stringValuesProps);

it('should have the correct props', () => {
expect(wrapper.props()).toEqual(stringValuesProps);
Expand Down Expand Up @@ -128,7 +135,7 @@ describe('EnumProperty', () => {
false
),
};
shallowMountBeforeEach(numberValuesProps);
mountBeforeEach(numberValuesProps);

it('should have the correct props', () => {
expect(wrapper.props()).toEqual(numberValuesProps);
Expand Down Expand Up @@ -183,7 +190,7 @@ describe('EnumProperty', () => {
false
),
};
shallowMountBeforeEach(booleanValuesProps);
mountBeforeEach(booleanValuesProps);

it('should have the correct props', () => {
expect(wrapper.props()).toEqual(booleanValuesProps);
Expand Down Expand Up @@ -238,7 +245,7 @@ describe('EnumProperty', () => {
false
),
};
shallowMountBeforeEach(objectValuesProps);
mountBeforeEach(objectValuesProps);

it('should have the correct props', () => {
expect(wrapper.props()).toEqual(objectValuesProps);
Expand Down Expand Up @@ -296,7 +303,7 @@ describe('EnumProperty', () => {
false
),
};
shallowMountBeforeEach(arrayValuesProps);
mountBeforeEach(arrayValuesProps);

it('should have the correct props', () => {
expect(wrapper.props()).toEqual(arrayValuesProps);
Expand Down Expand Up @@ -353,7 +360,7 @@ describe('EnumProperty', () => {

beforeEach(() => {
// @ts-ignore
wrapper = shallowMount(EnumProperty, {
wrapper = mount(EnumProperty, {
props: nullValuesProps,
});
dropdown = wrapper.findComponent(Select);
Expand Down Expand Up @@ -403,7 +410,7 @@ describe('EnumProperty', () => {
false
),
};
shallowMountBeforeEach(testProps);
mountBeforeEach(testProps);

it('should have the correct props', () => {
expect(wrapper.props()).toEqual(testProps);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import {shallowMount} from '@vue/test-utils';
import {mount} from '@vue/test-utils';
import {afterEach, beforeEach, describe, expect, it, test, vi} from 'vitest';
import NumberProperty from '../NumberProperty.vue';
import InputNumber from 'primevue/inputnumber';
import {JsonSchemaWrapper} from '@/schema/jsonSchemaWrapper';
import {GuiConstants} from '@/constants';
import {SessionMode} from '@/store/sessionMode';
import {ValidationResult} from '@/schema/validationService';
import { config } from '@vue/test-utils';
import { defaultOptions } from 'primevue/config';


config.global.mocks['$primevue'] = {
config: defaultOptions
};

// avoid constructing useDataLink store through imports, it is not required for this component
vi.mock('@/data/useDataLink', () => ({
Expand All @@ -22,10 +29,10 @@ describe('NumberProperty', () => {
let wrapper: any;
let inputNumber: any;

function shallowMountBeforeEach(props: any) {
function mountBeforeEach(props: any) {
beforeEach(() => {
// @ts-ignore
wrapper = shallowMount(NumberProperty, {
wrapper = mount(NumberProperty, {
props: props,
});
inputNumber = wrapper.findComponent(InputNumber);
Expand All @@ -49,10 +56,10 @@ describe('NumberProperty', () => {
false
),
};
shallowMountBeforeEach(props);
mountBeforeEach(props);

it('should correctly setup the input number', () => {
expect(inputNumber.props().modelValue).toBe(data ?? null); // primeVue converts undefined to null
expect(inputNumber.props().modelValue).toBe(data);
expect(inputNumber.props().minFractionDigits).toBe(0);
expect(inputNumber.props().maxFractionDigits).toBe(0);
expect(inputNumber.props().step).toBe(1);
Expand All @@ -79,10 +86,10 @@ describe('NumberProperty', () => {
false
),
};
shallowMountBeforeEach(props);
mountBeforeEach(props);

it('should correctly setup the input number', () => {
expect(inputNumber.props().modelValue).toBe(data ?? null); // primeVue converts undefined to null
expect(inputNumber.props().modelValue).toBe(data);
expect(inputNumber.props().minFractionDigits).toBe(0);
expect(inputNumber.props().maxFractionDigits).toBe(GuiConstants.NUMBER_MAX_DECIMAL_PLACES);
expect(inputNumber.props().step).toBe(0.5);
Expand All @@ -95,7 +102,7 @@ describe('NumberProperty', () => {
});

describe('emits the correct event', () => {
shallowMountBeforeEach({
mountBeforeEach({
propertyName: 'foo',
propertyData: 1,
validationResults: new ValidationResult([]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import {shallowMount} from '@vue/test-utils';
import {mount} from '@vue/test-utils';
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import StringProperty from '../StringProperty.vue';
import InputText from 'primevue/inputtext';
import {ValidationResult} from '@/schema/validationService';
import {JsonSchemaWrapper} from '@/schema/jsonSchemaWrapper';
import {SessionMode} from '@/store/sessionMode';
import { config } from '@vue/test-utils';
import { defaultOptions } from 'primevue/config';


config.global.mocks['$primevue'] = {
config: defaultOptions
};

// avoid constructing useDataLink store through imports, it is not required for this component
vi.mock('@/data/useDataLink', () => ({
Expand All @@ -21,10 +28,10 @@ describe('StringProperty', () => {
let wrapper: any;
let inputField: any;

function shallowMountBeforeEach(props: any) {
function mountBeforeEach(props: any) {
beforeEach(() => {
// @ts-ignore
wrapper = shallowMount(StringProperty, {
wrapper = mount(StringProperty, {
props: props,
});
inputField = wrapper.findComponent(InputText);
Expand All @@ -35,7 +42,7 @@ describe('StringProperty', () => {
}

describe('with string data', () => {
shallowMountBeforeEach({
mountBeforeEach({
propertyName: 'foo',
propertyData: 'bar',
validationResults: new ValidationResult([]),
Expand Down Expand Up @@ -93,7 +100,7 @@ describe('StringProperty', () => {
});

describe('with number data', () => {
shallowMountBeforeEach({
mountBeforeEach({
propertyName: 'foo',
propertyData: 1,
validationResults: new ValidationResult([]),
Expand All @@ -112,7 +119,7 @@ describe('StringProperty', () => {
});

describe('with object data', () => {
shallowMountBeforeEach({
mountBeforeEach({
propertyName: 'foo',
propertyData: {},
validationResults: new ValidationResult([]),
Expand All @@ -131,7 +138,7 @@ describe('StringProperty', () => {
});

describe('with array data', () => {
shallowMountBeforeEach({
mountBeforeEach({
propertyName: 'foo',
propertyData: [],
validationResults: new ValidationResult([]),
Expand All @@ -150,7 +157,7 @@ describe('StringProperty', () => {
});

describe('with null data', () => {
shallowMountBeforeEach({
mountBeforeEach({
propertyName: 'foo',
propertyData: null,
validationResults: new ValidationResult([]),
Expand All @@ -169,7 +176,7 @@ describe('StringProperty', () => {
});

describe('with undefined data', () => {
shallowMountBeforeEach({
mountBeforeEach({
propertyName: 'foo',
propertyData: undefined,
validationResults: new ValidationResult([]),
Expand Down
34 changes: 21 additions & 13 deletions meta_configurator/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@ import {fileURLToPath, URL} from 'node:url';
import {mergeConfig} from 'vite';
import {configDefaults, defineConfig} from 'vitest/config';
import viteConfig from './vite.config';
import {config} from '@vue/test-utils';
import PrimeVue from 'primevue/config';
import {UserConfig} from "vitest";




const userConfig: UserConfig = defineConfig({
test: {
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/*'],
root: fileURLToPath(new URL('./', import.meta.url)),
transformMode: {
web: [/\.[jt]sx$/],
},
coverage: {
provider: 'c8',
},
},
});

export default mergeConfig(
viteConfig,
defineConfig({
test: {
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/*'],
root: fileURLToPath(new URL('./', import.meta.url)),
transformMode: {
web: [/\.[jt]sx$/],
},
coverage: {
provider: 'c8',
},
},
})
userConfig,
);

0 comments on commit cdeae55

Please sign in to comment.