Skip to content

Commit

Permalink
Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
VampireAotD committed Dec 18, 2023
1 parent 841889a commit 63b3d16
Show file tree
Hide file tree
Showing 30 changed files with 214 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/resources/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createInertiaApp } from '@inertiajs/vue3';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
// @ts-expect-error Declaration of ZiggyVue
import { ZiggyVue } from 'ziggy-js/dist/vue.m';
import { HasRolePlugin } from '@/plugins/user/authorize';
import { HasRolePlugin } from '@/shared/plugins/user/authorize';
import PrimeVue from 'primevue/config';
import Tailwind from 'primevue/passthrough/tailwind';
import ToastService from 'primevue/toastservice';
Expand Down
6 changes: 5 additions & 1 deletion src/resources/js/entities/anime/model/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { type AnimePagination, type AnimePerDomain } from './types';
export {
type AnimePagination,
type AddedAnimePerDomain,
type AddedAnimePerMonth,
} from './types';
6 changes: 4 additions & 2 deletions src/resources/js/entities/anime/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Laravel, Models } from '@/types';

type AnimePagination = Laravel.Pagination<Models.Anime>;

type AnimePerDomain = Record<string, number>;
type AddedAnimePerDomain = Record<string, number>;

export { type AnimePagination, type AnimePerDomain };
type AddedAnimePerMonth = number[];

export { type AnimePagination, type AddedAnimePerDomain, type AddedAnimePerMonth };
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<script setup lang="ts">
import { Chart } from '@/shared/ui/chart';
import { computed, inject } from 'vue';
import { type AnimePerDomain } from '@/entities/anime';
import { computed } from 'vue';
import { type AddedAnimePerDomain } from '@/entities/anime';
const animePerDomain = inject<AnimePerDomain>('animePerDomain') as object;
type Props = {
domainStatistic: AddedAnimePerDomain;
};
const { domainStatistic } = defineProps<Props>();
const data = computed(() => ({
labels: Object.keys(animePerDomain),
labels: Object.keys(domainStatistic),
datasets: [
{
label: 'Anime per domain',
data: Object.values(animePerDomain),
data: Object.values(domainStatistic),
backgroundColor: [
'rgba(255, 159, 64, 0.2)',
'rgba(75, 192, 192, 0.2)',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<script setup lang="ts">
import { Chart } from '@/shared/ui/chart';
import { inject } from 'vue';
import { type AddedAnimePerMonth } from '@/entities/anime';
const animePerMonth = inject('animePerMonth');
type Props = {
monthlyStatistic: AddedAnimePerMonth;
};
const { monthlyStatistic } = defineProps<Props>();
const months: string[] = [
'January',
Expand All @@ -26,7 +30,7 @@ const data = {
datasets: [
{
label: 'Parsed anime per month',
data: animePerMonth,
data: monthlyStatistic,
fill: false,
borderColor: documentStyle.getPropertyValue('--red-500'),
tension: 0.4,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script setup lang="ts">
import { Button } from '@/shared/ui/button';
</script>

<template>
<Button
variant="secondary"
class="outline-none border-none bg-transparent focus:outline-none focus:ring-0 focus:border-none"
>
<i class="pi pi-search text-zinc-600 dark:text-white" />
</Button>
</template>

<style scoped></style>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as SearchButton } from './SearchButton.vue';
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, it } from 'vitest';
import { mount } from '@vue/test-utils';
import { Modal } from '@/shared/ui/modal';
import { TextInput } from '@/shared/ui/input/text';
import SearchModal from './SearchModal.vue';

describe('SearchModal test (SearchModal.vue)', () => {
it('Shows modal when visible is true', () => {
const wrapper = mount(SearchModal, {
props: { visible: true },
});

expect(wrapper.findComponent(Modal).props('visible')).toBeTruthy();
});

it('Modal emits closed event when it is closed', async () => {
const wrapper = mount(SearchModal, {
props: { visible: true },
});

await wrapper.findComponent(Modal).vm.$emit('close');
expect(wrapper.emitted()).toHaveProperty('closed');
});

it('Modal binds input value to ref', async () => {
const wrapper = mount(SearchModal, {
props: { visible: true },
});

const input = wrapper.findComponent(TextInput);
await input.setValue('test query');
expect(wrapper.vm.query).toBe('test query');
});
});
37 changes: 37 additions & 0 deletions src/resources/js/features/navigation/search-modal/SearchModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script setup lang="ts">
import { Modal } from '@/shared/ui/modal';
import { TextInput } from '@/shared/ui/input/text';
import { ref } from 'vue';
type Props = {
visible: boolean;
};
defineProps<Props>();
defineEmits<{ closed: [] }>();
const query = ref<string>('');
</script>

<template>
<Modal
:visible="visible"
:close-button="false"
close-on-escape
close-on-outside-click
@close="$emit('closed')"
>
<template #header>
<TextInput
ref="searchInput"
v-model="query"
name="search"
autofocus
class="w-full text-xs ring-1 bg-transparent ring-gray-200 dark:ring-zinc-600 focus:ring-red-300 px-5 text-gray-600 dark:text-white py-3 rounded-full w-full outline-none focus:ring-1"
placeholder="Search"
/>
</template>
</Modal>
</template>

<style scoped></style>
1 change: 1 addition & 0 deletions src/resources/js/features/navigation/search-modal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as SearchModal } from './SearchModal.vue';
33 changes: 0 additions & 33 deletions src/resources/js/features/navigation/search/SearchInput.test.ts

This file was deleted.

36 changes: 0 additions & 36 deletions src/resources/js/features/navigation/search/SearchInput.vue

This file was deleted.

1 change: 0 additions & 1 deletion src/resources/js/features/navigation/search/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mount } from '@vue/test-utils';
import { describe, expect, it, vitest } from 'vitest';
import TelegramLoginWidget from './TelegramLoginWidget.vue';
import { RequestAccess, WidgetSize } from './types';
import { RequestAccess, WidgetSize } from './model/types';

describe('TelegramLoginWidget test (TelegramLoginWidget.vue)', () => {
it('Renders correctly', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue';
import { RequestAccess, WidgetSize } from '@/features/telegram/login-widget/types';
import { TelegramUser } from '@/entities/telegram-user';
import { RequestAccess, WidgetSize } from '@/features/telegram/login-widget/model/types';
import { type TelegramUser } from '@/entities/telegram-user';
type Props = {
bot: string;
Expand Down
12 changes: 4 additions & 8 deletions src/resources/js/pages/Dashboard/Index.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
<script setup lang="ts">
import { AuthenticatedLayout } from '@/widgets/layouts';
import { Head } from '@inertiajs/vue3';
import { AnimePerDomain } from '@/entities/anime';
import { type AddedAnimePerDomain, type AddedAnimePerMonth } from '@/entities/anime';
import { Charts, StatisticCards } from '@/widgets/dashboard';
import { AnimeCarousel } from '@/features/dashboard/anime-carousel';
import { provide } from 'vue';
import { Models } from '@/types';
type Props = {
animeCount: number;
usersCount: number;
animePerMonth: number[];
animePerDomain: AnimePerDomain;
animePerMonth: AddedAnimePerMonth;
animePerDomain: AddedAnimePerDomain;
latestAnime: Models.Anime[];
};
const props = defineProps<Props>();
provide('animePerMonth', props.animePerMonth);
provide('animePerDomain', props.animePerDomain);
defineProps<Props>();
</script>

<template>
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion src/resources/js/shared/ui/input/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/resources/js/shared/ui/input/ui/index.ts

This file was deleted.

30 changes: 29 additions & 1 deletion src/resources/js/shared/ui/modal/Modal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ describe('BaseModal test (Modal.vue)', () => {
props: { visible: true, closeOnEscape: true },
});

await wrapper.find('.modal-wrapper').trigger('keyup.esc');
const modal = wrapper.find('.modal-wrapper');
expect(modal.isVisible()).toBeTruthy();

const escapeEvent = new KeyboardEvent('keydown', { key: 'Escape' });
window.dispatchEvent(escapeEvent);

expect(wrapper.emitted()).toHaveProperty('close');
});

Expand All @@ -48,4 +53,27 @@ describe('BaseModal test (Modal.vue)', () => {
expect(wrapper.emitted()).toHaveProperty('click:outside');
expect(wrapper.emitted()).toHaveProperty('close');
});

it('Modal will render content in slots', async () => {
const wrapper = mount(BaseModal, {
props: { visible: true },
slots: {
header: '<div>Test Header</div>',
body: '<div>Test Body</div>',
footer: '<div>Test Footer</div>',
},
});

expect(wrapper.find('header').html()).toContain('<div>Test Header</div>');
expect(wrapper.find('main').html()).toContain('<div>Test Body</div>');
expect(wrapper.find('footer').html()).toContain('<div>Test Footer</div>');
});

it('Modal will not render close closeButton prop is false', () => {
const wrapper = mount(BaseModal, {
props: { visible: true, closeButton: false },
});

expect(wrapper.find('button[aria-label="close"]').exists()).toBeFalsy();
});
});
Loading

0 comments on commit 63b3d16

Please sign in to comment.