Skip to content

Commit

Permalink
feat: add vitest-utils, resolves: #27
Browse files Browse the repository at this point in the history
  • Loading branch information
mnenie committed Aug 25, 2024
1 parent ab6f6a4 commit 045e697
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 115 deletions.
13 changes: 1 addition & 12 deletions src/entities/board/ui/__tests__/BoardPreviewCard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import { describe, it, expect, vi } from 'vitest';
import { mount } from '@vue/test-utils';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import i18n from '@/shared/lib/i18n';
import BoardPreviewCard from '../BoardPreviewCard.vue';

// TODO: think about putting this mock in /shared/vitest-utils maybe
// so, the problem - is often used in many tests
vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get: (key: string) => {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});

const mockRouter = {
push: vi.fn(),
beforeEach: vi.fn()
Expand Down
15 changes: 3 additions & 12 deletions src/entities/board/ui/__tests__/ColumnItem.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { describe, expect, it, vi } from 'vitest';
import { describe, expect, it } from 'vitest';
import { mount } from '@vue/test-utils';
import ColumnItem from '../ColumnItem.vue';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import i18n from '@/shared/lib/i18n';

vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get(key: string) {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});
import ColumnItem from '../ColumnItem.vue';

describe('tests for ColumnItem.vue', () => {
const wrapper = mount(ColumnItem, {
Expand Down
15 changes: 3 additions & 12 deletions src/entities/chart/ui/__tests__/ChartItem.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect } from 'vitest';
import { shallowMount } from '@vue/test-utils';
import ChartItem from '../ChartItem.vue';
import { defineComponent, h } from 'vue';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import i18n from '@/shared/lib/i18n';

vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get(key: string) {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});
import ChartItem from '../ChartItem.vue';

const TestChartComponent = defineComponent({
render() {
Expand Down
13 changes: 2 additions & 11 deletions src/entities/template/ui/__tests__/TemplateItem.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect } from 'vitest';
import { shallowMount } from '@vue/test-utils';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import i18n from '@/shared/lib/i18n';
import TemplateItem from '../TemplateItem.vue';
import { _templates } from '../../config';

vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get(key: string) {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});

describe('tests for TemplateItem.vue ', () => {
const wrapper = shallowMount(TemplateItem, {
global: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { mount } from '@vue/test-utils';
import { describe, it, expect, vi } from 'vitest';
import LanguageSwitcher from '../LanguageSwitcher.vue';
import i18n from '@/shared/lib/i18n';
import { nextTick, ref, shallowReactive } from 'vue';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import i18n from '@/shared/lib/i18n';
import LanguageSwitcher from '../LanguageSwitcher.vue';
import { useLanguage } from '@/shared/lib/composables';
import { useI18n } from 'vue-i18n';

vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get(key: string) {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});

vi.mock('vue-i18n', async (importOriginal) => {
const actual = await importOriginal();
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect, vi } from 'vitest';
import { mount } from '@vue/test-utils';
import { ref, shallowRef } from 'vue';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import useTheme from '../../lib/composables/useTheme';
import ThemeSwitcher from '../ThemeSwitcher.vue';
import i18n from '@/shared/lib/i18n';
Expand All @@ -11,16 +12,6 @@ vi.mock('@vueuse/core', () => ({
}))
}));

vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get(key: string) {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});

describe('tests for ThemeSwitcher.vue', () => {
const wrapper = mount(ThemeSwitcher, {
global: {
Expand Down
11 changes: 11 additions & 0 deletions src/shared/lib/vitest-utils/cookiesI18n-mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { vi } from 'vitest';

vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get(key: string) {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});
15 changes: 3 additions & 12 deletions src/widgets/layout/ui/footer/__tests__/FooterWelcome.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect } from 'vitest';
import { shallowMount } from '@vue/test-utils';
import FooterWelcome from '../AppFooter.vue';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import i18n from '@/shared/lib/i18n';

vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get: (key: string) => {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});
import FooterWelcome from '../AppFooter.vue';

describe('tests for FooterWelcome.vue', () => {
const wrapper = shallowMount(FooterWelcome, {
Expand Down
13 changes: 2 additions & 11 deletions src/widgets/layout/ui/header/__tests__/HeaderWelcome.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { mount } from '@vue/test-utils';
import { describe, it, expect, vi } from 'vitest';
import { nextTick } from 'vue';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import HeaderWelcome from '../HeaderWelcome.vue';
import i18n from '@/shared/lib/i18n';
import { UiButton, UiSelect } from '@/shared/ui';
import { Moon, Sun } from 'lucide-vue-next';
import { nextTick } from 'vue';

vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get: (key: string) => {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});

const mockRouter = {
push: vi.fn(),
Expand Down
13 changes: 2 additions & 11 deletions src/widgets/layout/ui/header/__tests__/UserMenu.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { describe, it, expect, vi } from 'vitest';
import { mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import UserMenu from '../UserMenu.vue';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import i18n from '@/shared/lib/i18n';
import UserMenu from '../UserMenu.vue';
import { UiDropdownItem } from '@/shared/ui';

vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get: (key: string) => {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});

const mockRouter = {
push: vi.fn(),
beforeEach: vi.fn()
Expand Down
15 changes: 3 additions & 12 deletions src/widgets/layout/ui/sidebar/__tests__/WorkSpace.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import { describe, it, expect, vi } from 'vitest';
import { mount, RouterLinkStub } from '@vue/test-utils';
import { h } from 'vue';
import { useRoute } from 'vue-router';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import WorkSpace from '../WorkSpace.vue';
import i18n from '@/shared/lib/i18n';
import { RouteNames } from '@/shared/config/consts';
import { h } from 'vue';
import { SquareDashedKanban } from 'lucide-vue-next';
import { useRoute } from 'vue-router';

vi.mock('vue-router');

vi.mock('@vueuse/integrations/useCookies', () => {
return {
useCookies: () => ({
get(key: string) {
return key === 'i18n' ? 'en-US' : undefined;
}
})
};
});

describe('tests for WorkSpace.vue', () => {
//@ts-expect-error mock types
useRoute.mockReturnValue({
Expand Down

0 comments on commit 045e697

Please sign in to comment.