Skip to content

Commit 54e2c65

Browse files
committed
fix: consider month offset in ending balance
adjust context menu offset for selects closes #118
1 parent 3ff5311 commit 54e2c65

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

src/app/components/base/context-menu/ContextMenu.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ const props = withDefaults(
4848
options?: ContextMenuOption[];
4949
highlight?: ContextMenuOptionId;
5050
testId?: string;
51+
offset?: [number, number];
5152
}>(),
5253
{
53-
position: 'right-end'
54+
position: 'right-end',
55+
offset: () => [10, 10]
5456
}
5557
);
5658
@@ -69,7 +71,7 @@ watch([visible, reference, popper], () => {
6971
instance = createPopper(reference.value, popper.value, {
7072
placement: props.position,
7173
modifiers: [
72-
{ name: 'offset', options: { offset: [10, 10] } },
74+
{ name: 'offset', options: { offset: props.offset } },
7375
{
7476
name: 'positionTracker',
7577
enabled: true,

src/app/components/base/select/Select.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
:testId="testId"
77
tooltipPosition="bottom"
88
:options="options"
9+
:offset="[0, 4]"
910
position="bottom-start"
1011
@select="modelValue = $event.id"
1112
>

src/app/pages/dashboard/overview/widgets/header-panels/SummaryPanels.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
? t('page.dashboard.yearInThePast')
5050
: state.activeYear > time.year.value
5151
? t('page.dashboard.yearInTheFuture')
52-
: time.month.value === 11
52+
: time.month.value === settings.general.monthOffset
5353
? t('page.dashboard.yearEnding')
5454
: undefined
5555
"
@@ -125,15 +125,15 @@ const expensePercentage = computed(() => {
125125
});
126126
127127
const remainingBalance = computed(() => {
128-
const nextMonth = time.year.value === state.activeYear ? time.month.value + 1 : 0;
129-
const netValues = subtract(incomeTotals.value.slice(nextMonth), expensesTotals.value.slice(nextMonth));
130-
return sum(netValues);
131-
});
128+
const monthOffset = time.year.value === state.activeYear ? time.month.value - settings.general.monthOffset + 1 : 0;
129+
const nextMonth = monthOffset % 12;
132130
133-
const remainingBalancePercentage = computed(() => {
134-
const endBalance = expenses.value.at(-1) ?? 0;
135-
return endBalance ? remainingBalance.value / endBalance : 0;
131+
return sum(subtract(incomeTotals.value.slice(nextMonth), expensesTotals.value.slice(nextMonth)));
136132
});
133+
134+
const remainingBalancePercentage = computed(() =>
135+
endingBalanceSum.value ? remainingBalance.value / endingBalanceSum.value : 0
136+
);
137137
</script>
138138

139139
<style lang="scss" module>

test/settings.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ test('Change the starting month and show correct labels', async ({ page }) => {
5454
await expect(page.getByTestId('remaining-balance-title')).toHaveText(`Remaining Balance until ${currentYear + 1}`);
5555
});
5656

57+
test('Show correct ending balance when using a monthly offset', async ({ page }) => {
58+
await page.clock.setFixedTime(new Date('2025-09-26T18:13:50.628Z'));
59+
await page.goto('/#demo');
60+
61+
await expect(page.getByTestId('remaining-balance-value')).toHaveText('€9,253');
62+
await expect(page.getByTestId('remaining-balance-sub')).toHaveText('22%');
63+
64+
await page.getByTestId('settings').click();
65+
await page.getByTestId('change-month-offset').click();
66+
await page.getByTestId('change-month-offset-2').click();
67+
await expect(page.getByTestId('remaining-balance-value')).toHaveText('€17,605');
68+
await expect(page.getByTestId('remaining-balance-sub')).toHaveText('42%');
69+
70+
await page.getByTestId('change-month-offset').click();
71+
await page.getByTestId('change-month-offset-4').click();
72+
await expect(page.getByTestId('remaining-balance-value')).toHaveText('€23,612');
73+
await expect(page.getByTestId('remaining-balance-sub')).toHaveText('56%');
74+
});
75+
5776
test('Carry over net-savings to next year', async ({ page }) => {
5877
const currentYear = new Date().getFullYear();
5978

0 commit comments

Comments
 (0)