Skip to content

Commit

Permalink
refactor: update test types
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Dec 7, 2023
1 parent 2aadcaf commit cea6731
Show file tree
Hide file tree
Showing 40 changed files with 102 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {expect, it} from 'vitest';
import {mount} from '@vue/test-utils';
import {type PartialComponentTest} from '../types';

export const runCommonComponentTests: PartialComponentTest = (component, options): void => {
export const runCommonComponentTests = ((component, options = undefined): void => {
it('can be rendered', () => {
expect(() => mount(component as any, options as any)).not.toThrow();
});
Expand All @@ -12,4 +12,4 @@ export const runCommonComponentTests: PartialComponentTest = (component, options
const wrapper = mount(component as any, options as any);
expect(wrapper.isVisible()).toBeTruthy();
});
};
}) satisfies PartialComponentTest;
4 changes: 2 additions & 2 deletions apps/admin-component-tests/src/common/runCommonInputTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {type PartialComponentTest} from '../types';
import {runHasPropTest} from './runHasPropTest';

// eslint-disable-next-line max-lines-per-function
export const runCommonInputTests: PartialComponentTest = (component, options) => {
export const runCommonInputTests = ((component, options = undefined) => {
runHasPropTest(component, {}, 'element', options?.props?.element);

it('can be disabled', () => {
Expand Down Expand Up @@ -55,4 +55,4 @@ export const runCommonInputTests: PartialComponentTest = (component, options) =>

expect(Object.keys(wrapper.emitted())).toContain(['update:modelValue']);
});
};
}) satisfies PartialComponentTest;
25 changes: 11 additions & 14 deletions apps/admin-component-tests/src/common/runHasPropTest.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import {expect, it} from 'vitest';
import {type ComponentMountingOptions, mount} from '@vue/test-utils';
import {mount} from '@vue/test-utils';
import {type PartialComponentTest} from '../types';

export const runHasPropTest: PartialComponentTest = (component, options, prop, value = 'value') => {
export const runHasPropTest = ((component, options, prop, value = 'value') => {
it(`has prop ${prop}`, () => {
const wrapper = mount(
component as any,
{
...options,
props: {
...options?.props,
[prop as string]: value,
},
} as ComponentMountingOptions<any>,
);
const wrapper = mount(component, {
...options,
props: {
...(options?.props as any),
[prop]: value,
},
});

expect(wrapper.props(prop as string)).toBe('value');
expect(wrapper.props(prop as any)).toBe('value');
});
};
}) satisfies PartialComponentTest<[string] | [string, unknown]>;
7 changes: 3 additions & 4 deletions apps/admin-component-tests/src/common/runHasSlotTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import {type PartialComponentTest} from '../types';
/**
* Checks if the html content passed to the slot exists anywhere in the component.
*/
export const runHasSlotTest: PartialComponentTest = (component, options, slot = 'default') => {
export const runHasSlotTest = ((component, options = undefined, slot = 'default') => {
it(`has slot #${slot}`, () => {
const content = `SLOT CONTENT ${Math.ceil(Math.random() * 100)}`;

const wrapper = mount(component as any, {
...options,
slots: {
...options?.slots,
// @ts-expect-error slots are not typed
...(options?.slots as any),
[slot]: () => content,
},
});

expect(wrapper.element.innerHTML).toContain(content);
});
};
}) satisfies PartialComponentTest<[] | [string]>;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {type ComponentMountingOptions} from '@vue/test-utils';
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests, runHasPropTest, runHasSlotTest} from '../common';

export const runActionContainerTest: AdminComponentTest = (component) => {
const options: ComponentMountingOptions<any> = {};
export const runActionContainerTest = ((component) => {
const options = {} satisfies ComponentMountingOptions<any>;

runCommonComponentTests(component, options);

runHasSlotTest(component, options, 'default');
Expand All @@ -23,4 +24,4 @@ export const runActionContainerTest: AdminComponentTest = (component) => {
// .actionEndpointMap((wrapper) => wrapper.element.value),
// ).toEqual(['1', '2']);
// });
};
}) satisfies AdminComponentTest;
4 changes: 2 additions & 2 deletions apps/admin-component-tests/src/components/runBadgeTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests} from '../common';

export const runBadgeTest: AdminComponentTest = (component) => {
export const runBadgeTest = ((component) => {
runCommonComponentTests(component);
};
}) satisfies AdminComponentTest;
4 changes: 2 additions & 2 deletions apps/admin-component-tests/src/components/runButtonTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {mount} from '@vue/test-utils';
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests} from '../common';

export const runButtonTest: AdminComponentTest = (component) => {
export const runButtonTest = ((component) => {
runCommonComponentTests(component);

it('handles click event', async () => {
Expand Down Expand Up @@ -31,4 +31,4 @@ export const runButtonTest: AdminComponentTest = (component) => {
const wrapper = mount(component, {slots: {default: 'Test'}});
expect(wrapper.findAll('*').map((wrapper) => wrapper.text())).toContain('Test');
});
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {type AdminComponentTest} from '../tests';
import {createInputOptions} from '../helpers';
import {runCommonComponentTests} from '../common';

export const runCheckboxGroupTest: AdminComponentTest = (component) => {
export const runCheckboxGroupTest = ((component) => {
const options = createInputOptions(['appel', 'boom']);

runCommonComponentTests(component, options);
// TODO: write more tests
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {type AdminComponentTest} from '../tests';
import {createInputOptions} from '../helpers';
import {runCommonComponentTests, runCommonInputTests} from '../common';

export const runCheckboxInputTest: AdminComponentTest = (component) => {
export const runCheckboxInputTest = ((component) => {
const options = createInputOptions(true);

runCommonComponentTests(component, options);
runCommonInputTests(component);
// TODO write more tests
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests} from '../common';

export const runCodeEditorTest: AdminComponentTest = (component) => {
export const runCodeEditorTest = ((component) => {
runCommonComponentTests(component);
};
}) satisfies AdminComponentTest;
4 changes: 2 additions & 2 deletions apps/admin-component-tests/src/components/runColTest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests, runHasPropTest, runHasSlotTest} from '../common';

export const runColTest: AdminComponentTest = (component) => {
export const runColTest = ((component) => {
runCommonComponentTests(component);

runHasSlotTest(component, {});
runHasPropTest(component, {}, 'span', 3);
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {type AdminComponentTest} from '../tests';
import {createInputOptions} from '../helpers';
import {runCommonComponentTests, runCommonInputTests} from '../common';

export const runCurrencyInputTest: AdminComponentTest = (component) => {
export const runCurrencyInputTest = ((component) => {
const options = createInputOptions(1.42);

runCommonComponentTests(component, options);
runCommonInputTests(component, options);
// TODO write more tests
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const DEFAULT_OPTIONS = {
},
};

export const runDropDownButtonTest: AdminComponentTest = (component) => {
export const runDropDownButtonTest = ((component) => {
const options: ComponentMountingOptions<any> = {};

runCommonComponentTests(component, options);
Expand Down Expand Up @@ -69,4 +69,4 @@ export const runDropDownButtonTest: AdminComponentTest = (component) => {
});

// TODO write more tests
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {type AdminComponentTest} from '../tests';
import {createInputOptions} from '../helpers';
import {runCommonComponentTests, runCommonInputTests} from '../common';

export const runDropOffInputTest: AdminComponentTest = (component) => {
export const runDropOffInputTest = ((component) => {
const options = createInputOptions(true);

runCommonComponentTests(component, options);
runCommonInputTests(component, options);
// TODO write more tests
};
}) satisfies AdminComponentTest;
4 changes: 2 additions & 2 deletions apps/admin-component-tests/src/components/runFormGroupTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {createFormElement, type ElementInstance} from '@myparcel-pdk/admin';
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests, runHasSlotTest} from '../common';

export const runFormGroupTest: AdminComponentTest = (component) => {
export const runFormGroupTest = ((component) => {
const options: ComponentMountingOptions<{element: ElementInstance}> = {
props: {
element: createFormElement({}),
Expand All @@ -13,4 +13,4 @@ export const runFormGroupTest: AdminComponentTest = (component) => {
runCommonComponentTests(component, options);
runHasSlotTest(component, options);
// TODO write more tests
};
}) satisfies AdminComponentTest;
6 changes: 3 additions & 3 deletions apps/admin-component-tests/src/components/runHeadingTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import {type ComponentMountingOptions} from '@vue/test-utils';
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests, runHasPropTest, runHasSlotTest} from '../common';

export const runHeadingTest: AdminComponentTest = (component) => {
const options: ComponentMountingOptions<any> = {};
export const runHeadingTest = ((component) => {
const options = {} satisfies ComponentMountingOptions<any>;

runCommonComponentTests(component, options);

runHasSlotTest(component);

runHasPropTest(component, options, 'level', 1);
};
}) satisfies AdminComponentTest;
10 changes: 5 additions & 5 deletions apps/admin-component-tests/src/components/runIconTest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {expect, it} from 'vitest';
import {type ComponentMountingOptions, mount} from '@vue/test-utils';
import {type AdminComponentTest} from '../tests';
import {type PartialComponentTest} from '../types';
import {runCommonComponentTests, runHasPropTest} from '../common';

export const runIconTest: AdminComponentTest = (component) => {
const options: ComponentMountingOptions<any> = {
export const runIconTest = ((component) => {
const options = {
props: {
icon: 'truck',
},
};
} satisfies ComponentMountingOptions<any>;

runCommonComponentTests(component, options);

Expand All @@ -19,4 +19,4 @@ export const runIconTest: AdminComponentTest = (component) => {

expect(wrapper.props().icon).toBe('truck');
});
};
}) satisfies PartialComponentTest;
4 changes: 2 additions & 2 deletions apps/admin-component-tests/src/components/runImageTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {type ComponentMountingOptions} from '@vue/test-utils';
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests, runHasPropTest} from '../common';

export const runImageTest: AdminComponentTest = (component) => {
export const runImageTest = ((component) => {
const options: ComponentMountingOptions<any> = {
props: {
src: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
Expand All @@ -17,4 +17,4 @@ export const runImageTest: AdminComponentTest = (component) => {
runHasPropTest(component, options, 'height');

// TODO write more tests
};
}) satisfies AdminComponentTest;
4 changes: 2 additions & 2 deletions apps/admin-component-tests/src/components/runLinkTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {type ComponentMountingOptions} from '@vue/test-utils';
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests, runHasSlotTest} from '../common';

export const runLinkTest: AdminComponentTest = (component) => {
export const runLinkTest = ((component) => {
const options: ComponentMountingOptions<any> = {};

runCommonComponentTests(component, options);
runHasSlotTest(component, options);

// TODO write more tests
};
}) satisfies AdminComponentTest;
4 changes: 2 additions & 2 deletions apps/admin-component-tests/src/components/runLoaderTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests} from '../common';

export const runLoaderTest: AdminComponentTest = (component) => {
export const runLoaderTest = ((component) => {
runCommonComponentTests(component);
};
}) satisfies AdminComponentTest;
4 changes: 2 additions & 2 deletions apps/admin-component-tests/src/components/runModalTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {type ComponentMountingOptions} from '@vue/test-utils';
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests, runHasPropTest, runHasSlotTest} from '../common';

export const runModalTest: AdminComponentTest = (component) => {
export const runModalTest = ((component) => {
const options: ComponentMountingOptions<any> = {
props: {
// todo
Expand All @@ -18,4 +18,4 @@ export const runModalTest: AdminComponentTest = (component) => {
runHasPropTest(component, options, 'modalKey');
runHasPropTest(component, options, 'title');
runHasPropTest(component, options, 'actions');
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests} from '../common';

export const runMultiSelectInputTest: AdminComponentTest = (component) => {
export const runMultiSelectInputTest = ((component) => {
runCommonComponentTests(component);
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {type ComponentMountingOptions, mount} from '@vue/test-utils';
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests} from '../common';

export const runNotificationTest: AdminComponentTest = (component) => {
export const runNotificationTest = ((component) => {
const options: ComponentMountingOptions<any> = {
props: {
notification: {
Expand Down Expand Up @@ -34,4 +34,4 @@ export const runNotificationTest: AdminComponentTest = (component) => {
expect(wrapper.findAll('*').map((wrapper) => wrapper.text())).toContain('This is a notification');
expect(wrapper.findAll('*').map((wrapper) => wrapper.text())).toContain('With multiple strings');
});
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {type AdminComponentTest} from '../tests';
import {createInputOptions} from '../helpers';
import {runCommonComponentTests, runCommonInputTests} from '../common';

export const runNumberInputTest: AdminComponentTest = (component) => {
export const runNumberInputTest = ((component) => {
const options = createInputOptions(24);

runCommonComponentTests(component, options);
runCommonInputTests(component, options);
// TODO write more tests
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests, runHasSlotTest} from '../common';

export const runPlainWrapperTest: AdminComponentTest = (component) => {
export const runPlainWrapperTest = ((component) => {
runCommonComponentTests(component);

runHasSlotTest(component);

// TODO write more tests
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {type ComponentMountingOptions} from '@vue/test-utils';
import {type AdminComponentTest} from '../tests';
import {runCommonComponentTests} from '../common';

export const runRadioGroupTest: AdminComponentTest = (component) => {
export const runRadioGroupTest = ((component) => {
const options: ComponentMountingOptions<any> = {};
runCommonComponentTests(component, options);
// TODO write more tests
};
}) satisfies AdminComponentTest;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {type AdminComponentTest} from '../tests';
import {createInputOptions} from '../helpers';
import {runCommonComponentTests, runCommonInputTests} from '../common';

export const runRadioInputTest: AdminComponentTest = (component) => {
export const runRadioInputTest = ((component) => {
const options = createInputOptions(true);

runCommonComponentTests(component, options);
runCommonInputTests(component, options);
// TODO write more tests
};
}) satisfies AdminComponentTest;
Loading

0 comments on commit cea6731

Please sign in to comment.