Skip to content

Commit 53829c2

Browse files
committed
remove before enter fetch to before mount
1 parent 4479860 commit 53829c2

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

src/components/chart.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
defineProps<{
33
recordValues: Record<string | number, number>
44
}>()
5-
const getBarHeight = (value: number) => `${value * 10}px`
5+
const getBarHeight = (value: number) => `${value * 20}px`
66
</script>
77

88
<template>
@@ -14,6 +14,7 @@ const getBarHeight = (value: number) => `${value * 10}px`
1414
:style="{ height: `${getBarHeight(occurrences)}` }"
1515
data-testid="chart-bar"
1616
>
17+
<span class="occurrence-label" data-testid="chart-bar-occurrence-amount">{{ occurrences }}</span>
1718
<span class="label" data-testid="chart-bar-label">{{ label }}</span>
1819
</div>
1920
</div>
@@ -43,4 +44,8 @@ const getBarHeight = (value: number) => `${value * 10}px`
4344
left: 50%;
4445
transform: translateX(-50%);
4546
}
47+
48+
.occurrence-label {
49+
color: whitesmoke;
50+
}
4651
</style>

src/pages/home-page.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import Chart from '@/components/chart.vue'
44
import PageLayout from '@/layouts/page-layout.vue'
55
import { useRandomIntegersStore } from '@/stores/useRandomIntegers.store.ts'
66
import { storeToRefs } from 'pinia'
7-
7+
import { onBeforeMount } from 'vue'
88
const { integersArray } = storeToRefs(useRandomIntegersStore())
99
const { searchIntegers } = useRandomIntegersStore()
1010
11+
const params = { num: 100, min: 0, max: 10, col: 1, base: 10, format: 'plain' }
1112
const handleSearchButtonClick = () => {
12-
searchIntegers({ num: 20, min: 1, max: 10, col: 1, base: 2, format: 'plain' })
13+
searchIntegers(params)
1314
}
15+
16+
onBeforeMount(() => searchIntegers(params))
1417
</script>
1518

1619
<template>

src/router/index.ts

-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useRandomIntegersStore } from '@/stores/useRandomIntegers.store.ts'
21
import { createRouter, createWebHistory } from 'vue-router'
32
import HomePage from '@/pages/home-page.vue'
43

@@ -9,15 +8,6 @@ const router = createRouter({
98
path: '/',
109
name: 'home',
1110
component: HomePage,
12-
beforeEnter: () =>
13-
useRandomIntegersStore().searchIntegers({
14-
num: 20,
15-
min: 1,
16-
max: 10,
17-
col: 1,
18-
base: 10,
19-
format: 'plain'
20-
})
2111
}
2212
]
2313
})

tests/components/chart.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,11 @@ describe('Chart', () => {
4949
expect(first.text()).toBe('15')
5050
expect(second.text()).toBe('20')
5151
})
52+
53+
it('should render the amount of occurrences', async () => {
54+
await wrapper.setProps({ recordValues: { '15': '1' } })
55+
const occurrenceLabel = wrapper.find('[data-testid="chart-bar-occurrence-amount"]')
56+
57+
expect(occurrenceLabel.text()).toBe('1')
58+
})
5259
})

tests/test.spec.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)