diff --git a/src/modules/record/components/StepRecord.vue b/src/modules/record/components/StepRecord.vue
index c5efb70..2832577 100644
--- a/src/modules/record/components/StepRecord.vue
+++ b/src/modules/record/components/StepRecord.vue
@@ -4,6 +4,7 @@ import { formatDiffInMinutes } from '@/shared/format-date'
import { toISODate } from '@/shared/types/date'
import { computed, onUnmounted, ref } from 'vue'
import { useTaskRecordStore } from '../stores/useTaskRecordStore'
+import { is10PercentOffThanEstimation } from '@/modules/record/services/compare-with-estimation'
const props = defineProps<{
taskId: string
@@ -52,12 +53,15 @@ const duration = computed(() => {
)
})
-const isGreaterThanEstimation = computed(() => {
+const isOffEstimation = computed(() => {
if (!step.value || !stepRecord.value || !duration.value) {
return false
}
- return duration.value > step.value.estimation
+ return is10PercentOffThanEstimation({
+ estimation: step.value.estimation,
+ duration: duration.value
+ })
})
@@ -80,9 +84,9 @@ const isGreaterThanEstimation = computed(() => {
- ✅
- ❓
- ⌛
+ ⌛
+ ❓
+ ✅
|
{{ step.title }}
diff --git a/src/modules/record/services/compare-with-estimation.test.ts b/src/modules/record/services/compare-with-estimation.test.ts
new file mode 100644
index 0000000..ce0724b
--- /dev/null
+++ b/src/modules/record/services/compare-with-estimation.test.ts
@@ -0,0 +1,19 @@
+import { is10PercentOffThanEstimation } from '@/modules/record/services/compare-with-estimation'
+import { describe, expect, it } from 'vitest'
+
+describe('compareWithEstimation', () => {
+ it('should tells if the estimation is off by 10% or more', () => {
+ expect(is10PercentOffThanEstimation({ estimation: 10, duration: 9 })).toBe(
+ false
+ )
+ expect(is10PercentOffThanEstimation({ estimation: 5, duration: 4 })).toBe(
+ false
+ )
+ expect(is10PercentOffThanEstimation({ estimation: 10, duration: 5 })).toBe(
+ true
+ )
+ expect(is10PercentOffThanEstimation({ estimation: 10, duration: 8 })).toBe(
+ true
+ )
+ })
+})
diff --git a/src/modules/record/services/compare-with-estimation.ts b/src/modules/record/services/compare-with-estimation.ts
new file mode 100644
index 0000000..8c22e9c
--- /dev/null
+++ b/src/modules/record/services/compare-with-estimation.ts
@@ -0,0 +1,9 @@
+export const is10PercentOffThanEstimation = ({
+ estimation,
+ duration
+}: {
+ estimation: number
+ duration: number
+}) => {
+ return Math.abs(duration - estimation) > Math.max(estimation * 0.1, 1)
+}
|