Skip to content

Commit

Permalink
Various small codebase clean-ups (directus#20977)
Browse files Browse the repository at this point in the history
  • Loading branch information
paescuj authored Jan 5, 2024
1 parent 8a314a8 commit c9292fd
Show file tree
Hide file tree
Showing 34 changed files with 76 additions and 284 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dist/
/packages/extensions-sdk/templates/
/api/extensions/
!/app/.storybook/
!/docs/.vitepress/
!/docs/.typedocs/
/docs/.vitepress/cache/
Expand Down
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,12 @@ module.exports = {
...vueRules,
},
},
// Test files
{
files: ['*.test.ts'],
rules: {
'vue/one-component-per-file': 'off',
},
},
],
};
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ node_modules/

# Builds / Caches
dist/
storybook-static/
coverage/
.histoire/
*.tsbuildinfo
**/.vitepress/cache/
**/.vitepress/.temp/
.thumbsmith/
.eslintcache

# Dotenv configs
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
dist/
coverage/
pnpm-lock.yaml
.histoire/
**/.vitepress/cache/
/.changeset/pre.json
/.changeset/*.md
/app/src/lang/translations/*.yaml
!/app/src/lang/translations/en-US.yaml
/docs/packages/
storybook-static/
/api/uploads/
/api/extensions/
File renamed without changes.
2 changes: 1 addition & 1 deletion api/tsconfig.prod.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["**/*.test.ts"]
"exclude": ["**/*.test.ts", "src/__utils__", "src/__setup__"]
}
2 changes: 1 addition & 1 deletion api/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globalSetup: ['./globalSetup.js'],
globalSetup: ['./src/__setup__/global.js'],
},
});
2 changes: 1 addition & 1 deletion app/histoire.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from 'histoire';

export default defineConfig({
plugins: [HstVue()],
setupFile: './src/histoire/setup.ts',
setupFile: './src/__histoire__/setup.ts',
theme: {
title: 'Directus Components',
favicon: './public/favicon.ico',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 0 additions & 21 deletions app/src/__setup__/mock-globals.ts

This file was deleted.

10 changes: 8 additions & 2 deletions app/src/__utils__/router.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { h } from 'vue';
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';

export function generateRouter(routes: RouteRecordRaw[]) {
export function generateRouter(routes?: RouteRecordRaw[]) {
const router = createRouter({
history: createWebHistory(),
routes,
routes: routes ?? [
{
path: '/',
component: h('div'),
},
],
});

return router;
Expand Down
39 changes: 8 additions & 31 deletions app/src/components/v-button.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import { test, expect, beforeEach } from 'vitest';
import { mount } from '@vue/test-utils';

import VButton from './v-button.vue';
import { h } from 'vue';
import { generateRouter } from '@/__utils__/router';
import { beforeEach, expect, test } from 'vitest';
import { Router } from 'vue-router';
import { GlobalMountOptions } from '@vue/test-utils/dist/types';

import { Focus } from '@/__utils__/focus';
import { generateRouter } from '@/__utils__/router';
import { Tooltip } from '@/__utils__/tooltip';
import { GlobalMountOptions } from '@/__utils__/types';
import VButton from './v-button.vue';

let router: Router;

let global: GlobalMountOptions;

beforeEach(async () => {
router = generateRouter([
{
path: '/',
component: h('div', VButton),
},
{
path: '/test',
component: h('div', 'empty'),
},
]);
router = generateRouter();

router.push('/');
await router.isReady();
Expand All @@ -31,6 +21,7 @@ beforeEach(async () => {
stubs: ['v-progress-circular'],
directives: {
focus: Focus,
tooltip: Tooltip,
},
plugins: [router],
};
Expand All @@ -45,17 +36,3 @@ test('Mount component', () => {

expect(wrapper.html()).toMatchSnapshot();
});

// test('Click on link', async () => {
// const wrapper = mount(VButton, {
// props: {
// to: '/test'
// },
// global
// });

// await wrapper.get('a').trigger('click')

// expect(router.currentRoute.value.path).toBe('/test')

// });
66 changes: 10 additions & 56 deletions app/src/components/v-checkbox-tree/v-checkbox-tree.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
import { test, expect, beforeEach } from 'vitest';
import { mount } from '@vue/test-utils';
import { beforeEach, expect, test } from 'vitest';
import { Router } from 'vue-router';

import VCheckboxTree from './v-checkbox-tree.vue';
import VCheckboxTreeCheckbox from './v-checkbox-tree-checkbox.vue';
import VListItem from '../v-list-item.vue';
import { generateRouter } from '@/__utils__/router';
import type { GlobalMountOptions } from '@/__utils__/types';
import VCheckbox from '../v-checkbox.vue';
import VListGroup from '../v-list-group.vue';
import VListItemIcon from '../v-list-item-icon.vue';
import VListItem from '../v-list-item.vue';
import VList from '../v-list.vue';
import VListGroup from '../v-list-group.vue';
import VCheckbox from '../v-checkbox.vue';
import { h } from 'vue';
import type { GlobalMountOptions } from '@/__utils__/types';
import { Router } from 'vue-router';
import { generateRouter } from '@/__utils__/router';
import VCheckboxTreeCheckbox from './v-checkbox-tree-checkbox.vue';
import VCheckboxTree from './v-checkbox-tree.vue';

let router: Router;
let global: GlobalMountOptions;

beforeEach(async () => {
router = generateRouter([
{
path: '/',
component: h('div', 'test'),
},
{
path: '/test',
component: h('div', 'empty'),
},
]);
router = generateRouter();

router.push('/');
await router.isReady();
Expand Down Expand Up @@ -54,39 +44,3 @@ test('Mount component', () => {

expect(wrapper.html()).toMatchSnapshot();
});

// test('Choices prop', async () => {
// const wrapper = mount(VCheckboxTree, {
// props: {
// modelValue: ['p1', 'c1'],
// showSelectionOnly: true,
// choices: [
// {
// text: 'Parent 1',
// value: 'p1',
// },
// {
// text: 'Parent 2',
// value: 'p2',
// children: [
// {
// text: 'Child 1',
// value: 'c1',
// },
// ],
// },
// ],
// },
// global,
// });

// expect(wrapper.getComponent('.v-checkbox:nth-child(1)').classes()).toContain('checked');
// expect(wrapper.getComponent('.v-checkbox:nth-child(1)').props().label).toBe('Parent 1');
// expect(wrapper.getComponent('.v-checkbox:nth-child(2)').classes()).not.toContain('checked');

// await wrapper.get('.v-checkbox:nth-child(2)').trigger('click');

// const child1 = wrapper.get('.v-checkbox:nth-child(2)').find('.v-checkbox');
// expect(child1.exists()).toBeTruthy();
// expect(child1.props().label).toBe('Child 1');
// });
2 changes: 0 additions & 2 deletions app/src/components/v-error-boundary.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable vue/one-component-per-file */

import { mount } from '@vue/test-utils';
import { afterAll, beforeAll, expect, test, vi } from 'vitest';
import { defineComponent, h, nextTick } from 'vue';
Expand Down

This file was deleted.

92 changes: 0 additions & 92 deletions app/src/components/v-form/form-field-raw-editor.test.ts

This file was deleted.

Loading

0 comments on commit c9292fd

Please sign in to comment.