Skip to content

Open source personal finance application

chore: reorganise tests

ilkomee254b3a225dd
diff --git a/components/amount/Amount.vue b/components/amount/Amount.vue
index d5e9b0c9..550c7a54 100644
--- a/components/amount/Amount.vue
+++ b/components/amount/Amount.vue
@@ -5,9 +5,9 @@ import { formatAmount, getCurrencySymbol } from '~/components/amount/formatAmoun
const props = withDefaults(defineProps<{
amount: number
currencyCode: string
- colorize: string
- type: number
- align: string
+ colorize?: string
+ type?: number
+ align?: string
isShowBaseRate?: boolean
isShowSign?: boolean
}>(), {
diff --git a/tests/getAmount.test.ts b/components/amount/getAmount.test.ts
similarity index 87%
rename from tests/getAmount.test.ts
rename to components/amount/getAmount.test.ts
index e3cbbc6f..1c8248e1 100644
--- a/tests/getAmount.test.ts
+++ b/components/amount/getAmount.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
-import { getAmountInRate } from '~/components/trns/getTotal'
-import { ratesBasedOnUsd as rates } from '~/tests/rates.mock'
+import { getAmountInRate } from '~/components/amount/getTotal'
+import { ratesBasedOnUsd as rates } from '~/mocks/rates'
describe('Get amount', () => {
it('Get amount in same rate as base rate', () => {
diff --git a/tests/getTotal.test.ts b/components/amount/getTotal.test.ts
similarity index 95%
rename from tests/getTotal.test.ts
rename to components/amount/getTotal.test.ts
index 1af95a4d..4f58a613 100644
--- a/tests/getTotal.test.ts
+++ b/components/amount/getTotal.test.ts
@@ -1,10 +1,10 @@
import { describe, expect, it } from 'vitest'
-import { categoriesItems } from '~/tests/categories.mock'
-import { getTotal } from '~/components/trns/getTotal'
+import { categoriesItems } from '~/mocks/categories'
+import { getTotal } from '~/components/amount/getTotal'
import { getTransferCategoriesIds } from '~/components/categories/getCategories'
-import { trnsItems } from '~/tests/trns.mock'
-import { walletsItems } from '~/tests/wallets.mock'
-import { ratesBasedOnUsd as rates } from '~/tests/rates.mock'
+import { ratesBasedOnUsd as rates } from '~/mocks/rates'
+import { trnsItems } from '~/mocks/trns'
+import { walletsItems } from '~/mocks/wallets'
const transferCategoriesIds = getTransferCategoriesIds(categoriesItems)
diff --git a/components/trns/getTotal.ts b/components/amount/getTotal.ts
similarity index 100%
rename from components/trns/getTotal.ts
rename to components/amount/getTotal.ts
diff --git a/components/amount/useAmount.ts b/components/amount/useAmount.ts
index 4852bb24..a73e325d 100644
--- a/components/amount/useAmount.ts
+++ b/components/amount/useAmount.ts
@@ -1,4 +1,4 @@
-import { getAmountInRate } from '~/components/trns/getTotal'
+import { getAmountInRate } from '~/components/amount/getTotal'
import { formatAmount } from '~/components/amount/formatAmount'
export default function useAmount() {
diff --git a/components/stat/chart/View.vue b/components/stat/chart/View.vue
index 574e5ea8..5f0fef98 100644
--- a/components/stat/chart/View.vue
+++ b/components/stat/chart/View.vue
@@ -4,7 +4,7 @@ import chartOptions from '~/components/stat/chart/chartOptions'
import useChart from '~/components/chart/useChart'
import useFilter from '~/modules/filter/useFilter'
import { getCatsIds, getTransferCategoriesIds } from '~/components/categories/getCategories'
-import { getTotal } from '~/components/trns/getTotal'
+import { getTotal } from '~/components/amount/getTotal'
import { getTrnsIds } from '~/components/trns/getTrns'
export default defineComponent({
diff --git a/components/stat/group/HorizontalItemCat.vue b/components/stat/group/HorizontalItemCat.vue
index 3b7677bb..ad7f5657 100644
--- a/components/stat/group/HorizontalItemCat.vue
+++ b/components/stat/group/HorizontalItemCat.vue
@@ -1,5 +1,5 @@
<script>
-import { getTotal } from '~/components/trns/getTotal'
+import { getTotal } from '~/components/amount/getTotal'
export default {
props: {
diff --git a/components/stat/laptop/LaptopView.vue b/components/stat/laptop/LaptopView.vue
new file mode 100644
index 00000000..2fba3d20
--- /dev/null
+++ b/components/stat/laptop/LaptopView.vue
@@ -0,0 +1,148 @@
+<script setup lang="ts">
+import useStat from '~/modules/stat/useStat'
+import useStatChart from '~/components/stat/useStatChart'
+import useStatPage from '~/components/stat/useStatPage'
+import useUIView from '~/components/layout/useUIView'
+import useWallets from '~/components/wallets/useWallets'
+const { walletsCurrencies } = useWallets()
+
+const { $store } = useNuxtApp()
+const { statPage } = useStatPage()
+const { ui } = useUIView()
+const { moneyTypes, isEmptyStat } = useStat()
+
+const { onWatch } = useStatChart()
+onWatch()
+
+const isShowGroup = (type) => {
+ const p1 = statPage.activeTab === 'details'
+ || statPage.activeTab === 'balance'
+ || (statPage.activeTab === 'income' && type === 'income')
+ || (statPage.activeTab === 'expense' && type === 'expense')
+
+ const p2 = statPage.current[type].total > 0
+ || (statPage.average && statPage.average[type] !== 0)
+ || $store.state.filter.period === 'all'
+
+ return p1 && p2
+}
+
+const isShowTrns = computed(() => {
+ return statPage.activeTab === 'details'
+ && statPage.average?.income !== 0
+ && statPage.average?.expense !== 0
+ && $store.getters['trns/selectedTrnsIdsWithDate'].length > 0
+})
+
+const isShowGroupTrns = computed(() => {
+ const p1 = statPage.activeTab === 'income' || statPage.activeTab === 'expense'
+ const p2 = statPage.average?.sum === 0
+ return (p1 || p2) && statPage.activeTab !== 'history'
+})
+
+const chartKeyDirtyFix = ref('show')
+onActivated(async () => {
+ await nextTick()
+ chartKeyDirtyFix.value = 'hide'
+})
+onDeactivated(async () => {
+ await nextTick()
+ chartKeyDirtyFix.value = 'show'
+})
+</script>
+
+<template lang="pug">
+.overflow-y-auto.h-full.pb-8.js_scroll_page
+ .max-w-4xl.pb-6
+ .px-2.flex.items-center.justify-between.gap-4.sticky.top-0.z-20.backdrop-blur(
+ class="bg-white/70 dark_bg-dark3/70"
+ )
+ StatDate.grow
+ .cursor-pointer.py-2.px-4.text-xs.text-skin-item-base-down.rounded-md.hocus_bg-skin-item-main-hover(
+ v-if="walletsCurrencies.length > 1"
+ @click="$store.commit('currencies/showBaseCurrenciesModal')"
+ )
+ | {{ $store.state.currencies.base }}
+
+ .pb-6.px-3(v-if="walletsCurrencies.length > 1")
+ WalletsCurrenciesChanger
+
+ .mx-2.mb-4.rounded-lg.bg-skin-item-main-bg.border.dark_border-neutral-800
+ LazyStatChartWrap(
+ :key="chartKeyDirtyFix"
+ v-if="ui.showMainChart && statPage.isHasTrns"
+ )
+ .sm_flex.justify-between.px-2.pb-2
+ StatChartPeriods
+ StatChartOptions
+
+ .my-4.mx-2.p-3.rounded-lg.bg-skin-item-main-active(v-if="statPage.filter.isShow")
+ LazyStatFilter(v-if="statPage.filter.isShow")
+
+ .px-2.flex.flex-wrap.items-center.justify-between.gap-x-6
+ StatSumTotal
+ StatViewConfig
+
+ .pb-4.px-2
+ StatLaptopMenu
+
+ template(v-if="statPage.activeTab !== 'trns' && statPage.activeTab !== 'history'")
+ //- Loop throw income / expense
+ .mb-8.md_mb-4.px-2
+ .grid.grid-cols-1.gap-y-5(class="md_grid-cols-2 md_gap-x-20")
+ div(
+ v-for="item in moneyTypes"
+ v-show="isShowGroup(item.id)"
+ :key="item.id"
+ class="max-w-[420px]"
+ )
+ StatSumGroup(
+ :typeText="item.id"
+ )
+
+ template(v-if="statPage.activeTab !== 'balance'")
+ StatGroupEmpty(:typeText="item.id")
+ StatGroupPie(:typeText="item.id")
+ StatGroupVertical(:typeText="item.id")
+ StatGroupRound(:typeText="item.id")
+ StatGroupHorizontal(:typeText="item.id")
+
+ template(v-if="statPage.activeTab === 'balance'")
+ StatGroupBudget(:typeText="item.id")
+
+ LazyStatGroupTrns(
+ v-if="isShowGroupTrns && !isEmptyStat"
+ :isShowExpense="statPage.activeTab === 'expense'"
+ :isShowIncome="statPage.activeTab === 'income'"
+ )
+
+ .px-2
+ StatEmpty
+ .grid.md_grid-cols-2.md_gap-x-20
+ LazyStatTrns(v-if="isShowTrns && !isEmptyStat")
+
+ //- Trns
+ template(v-if="statPage.activeTab === 'trns'")
+ .my-4.px-2
+ .pb-2.text-lg.leading-none.font-nunito.font-semibold.text-skin-item-base
+ | {{ $t('trns.inPeriodTitle') }}
+
+ .grid.md_grid-cols-2.md_gap-x-20
+ TrnsList(
+ :size="50"
+ classNames="md_grid-cols-1"
+ )
+
+ //- History
+ template(v-if="statPage.activeTab === 'history'")
+ .my-4.px-2
+ StatHistory
+</template>
+
+<style lang="stylus">
+.firefoxBackdropFix
+ @supports (not (-webkit-backdrop-filter: none)) and (not (backdrop-filter: none))
+ background theme('colors.dark3') !important
+ /.light &
+ background theme('colors.white') !important
+</style>
diff --git a/components/trnForm/TrnForm.vue b/components/trnForm/TrnForm.vue
index 1c89db91..f2abee35 100644
--- a/components/trnForm/TrnForm.vue
+++ b/components/trnForm/TrnForm.vue
@@ -124,7 +124,7 @@ function onClickWallet(walletId) {
/**
* Prepare values
*/
-function prepeareValues(): any {
+function prepareValues(): any {
let normalizedValues
const id = $store.state.trnForm.values.trnId || generateId(dayjs().valueOf())
@@ -170,7 +170,7 @@ function prepeareValues(): any {
function handleSubmitForm() {
try {
const { validate } = useTrnFormValidate()
- const { id, values } = prepeareValues()
+ const { id, values } = prepareValues()
const validateStatus = validate(values)
@@ -213,8 +213,8 @@ function handleSubmitForm() {
.swiper-slide.getHeight
.scroll.scrollerBlock(:style="{ maxHeight: `${$store.state.ui.height}px` }")
.subTitle.text-center.pt-5.pb-2.text-xs
- temaplte(v-if="$store.state.trnForm.values.trnId") {{ $t('trnForm.titleEditTrn') }}
- temaplte(v-if="!$store.state.trnForm.values.trnId") {{ $t('trnForm.titleCreateTrn') }}
+ template(v-if="$store.state.trnForm.values.trnId") {{ $t('trnForm.titleEditTrn') }}
+ template(v-if="!$store.state.trnForm.values.trnId") {{ $t('trnForm.titleCreateTrn') }}
TrnFormTypes
TrnFormAmount(v-if="!isTransfer || isTransfer && isSameCurrency")
diff --git a/tests/getTrns.test.ts b/components/trns/getTrns.test.ts
similarity index 97%
rename from tests/getTrns.test.ts
rename to components/trns/getTrns.test.ts
index 58385a2e..9b60618b 100644
--- a/tests/getTrns.test.ts
+++ b/components/trns/getTrns.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { getTrnsIds } from '~/components/trns/getTrns'
-import { trnsItems } from '~/tests/trns.mock'
+import { trnsItems } from '~/mocks/trns'
describe('Get Transactions IDs', () => {
it('Get Transactions IDs in Wallet Cash USD', () => {
diff --git a/components/wallets/ItemTotalSum.vue b/components/wallets/ItemTotalSum.vue
index 48b7131e..6919f1e3 100644
--- a/components/wallets/ItemTotalSum.vue
+++ b/components/wallets/ItemTotalSum.vue
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { getTransferCategoriesIds } from '~/components/categories/getCategories'
-import { getTotal } from '~/components/trns/getTotal'
+import { getTotal } from '~/components/amount/getTotal'
import type { WalletID } from '~/components/wallets/types'
import type { TrnID } from '~/components/trns/types'
diff --git a/tests/categories.mock.ts b/mocks/categories.ts
similarity index 100%
rename from tests/categories.mock.ts
rename to mocks/categories.ts
diff --git a/tests/rates.mock.ts b/mocks/rates.ts
similarity index 100%
rename from tests/rates.mock.ts
rename to mocks/rates.ts
diff --git a/tests/trns.mock.ts b/mocks/trns.ts
similarity index 100%
rename from tests/trns.mock.ts
rename to mocks/trns.ts
diff --git a/tests/wallets.mock.ts b/mocks/wallets.ts
similarity index 100%
rename from tests/wallets.mock.ts
rename to mocks/wallets.ts
diff --git a/pages/wallets/total.vue b/pages/wallets/total.vue
index 0f7a0a33..697299b0 100644
--- a/pages/wallets/total.vue
+++ b/pages/wallets/total.vue
@@ -9,7 +9,7 @@ import type { TrnID, TrnItem } from '~/components/trns/types'
import useAmount from '~/components/amount/useAmount'
import { averageLine, baseSeriesItemStyle, options } from '~/components/chart/chartOprions'
import { getTransferCategoriesIds } from '~/components/categories/getCategories'
-import { getTotal } from '~/components/trns/getTotal'
+import { getTotal } from '~/components/amount/getTotal'
import { getTrnsIds } from '~/components/trns/getTrns'
import { formatAmount, getCurrencySymbol } from '~/components/amount/formatAmount'
@@ -29,7 +29,7 @@ function getOldestTrnDate(trnsItems: Record<TrnID, TrnItem>): DateValueOf {
/**
* Get max periods to show
*/
-function getMaxPeriodsToShow({ periodName, fromDate }: { periodName: PeriodsNamesExceptAll; fromDate: DateValueOf }) {
+function getMaxPeriodsToShow(periodName: PeriodsNamesExceptAll, fromDate: DateValueOf): number {
return dayjs().endOf(periodName).diff(fromDate, periodName) + 1
}
@@ -48,7 +48,7 @@ const activePeriod: Ref<PeriodsNamesExceptAll> = ref('month')
* Periods
*/
const periods: PeriodsNamesExceptAll[] = ['day', 'week', 'month', 'year']
-const maxPeriodsNumber = computed(() => getMaxPeriodsToShow({ periodName: activePeriod.value, fromDate: oldestTrnDate }))
+const maxPeriodsNumber = computed(() => getMaxPeriodsToShow(activePeriod.value, oldestTrnDate))
/**
* Get Period date from until
diff --git a/store/stat/getters.ts b/store/stat/getters.ts
index 832bb13e..5b4173bb 100644
--- a/store/stat/getters.ts
+++ b/store/stat/getters.ts
@@ -1,6 +1,6 @@
import dayjs from 'dayjs'
import { getCatsIds, getTransferCategoriesIds } from '~/components/categories/getCategories'
-import { getTotal } from '~/components/trns/getTotal'
+import { getTotal } from '~/components/amount/getTotal'
import { getTrnsIds } from '~/components/trns/getTrns'
export default {
diff --git a/store/wallets/getters.js b/store/wallets/getters.js
index a040bc93..d83a7208 100644
--- a/store/wallets/getters.js
+++ b/store/wallets/getters.js
@@ -1,5 +1,5 @@
import { getTrnsIds } from '~/components/trns/getTrns'
-import { getTotal } from '~/components/trns/getTotal'
+import { getTotal } from '~/components/amount/getTotal'
export default {
hasWallets(state, getters, rootState) {