From 8a2d926801fdb731f5fbd1109bb9e8522ba719a4 Mon Sep 17 00:00:00 2001 From: rishu ray Date: Fri, 17 Apr 2026 12:21:26 +0530 Subject: [PATCH 1/5] feat: add Tip Calculator and Bill Splitter tool --- locales/en.yml | 4 + src/tools/index.ts | 3 +- src/tools/tip-calculator/index.ts | 13 +++ src/tools/tip-calculator/tip-calculator.vue | 93 +++++++++++++++++++++ 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/tools/tip-calculator/index.ts create mode 100644 src/tools/tip-calculator/tip-calculator.vue diff --git a/locales/en.yml b/locales/en.yml index d03d80d3f6..221c854716 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -97,6 +97,10 @@ tools: title: Percentage calculator description: Easily calculate percentages from a value to another value, or from a percentage to a value. + tip-calculator: + title: Tip calculator + description: Calculate the tip for a bill and split it among multiple people. + svg-placeholder-generator: title: SVG placeholder generator description: Generate svg images to use as a placeholder in your applications. diff --git a/src/tools/index.ts b/src/tools/index.ts index 388cfaf494..4143e205e8 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -58,6 +58,7 @@ import { tool as dateTimeConverter } from './date-time-converter'; import { tool as deviceInformation } from './device-information'; import { tool as cypher } from './encryption'; import { tool as etaCalculator } from './eta-calculator'; +import { tool as tipCalculator } from './tip-calculator'; import { tool as percentageCalculator } from './percentage-calculator'; import { tool as gitMemo } from './git-memo'; import { tool as hashText } from './hash-text'; @@ -168,7 +169,7 @@ export const toolsByCategory: ToolCategory[] = [ }, { name: 'Math', - components: [mathEvaluator, etaCalculator, percentageCalculator], + components: [mathEvaluator, etaCalculator, percentageCalculator, tipCalculator], }, { name: 'Measurement', diff --git a/src/tools/tip-calculator/index.ts b/src/tools/tip-calculator/index.ts new file mode 100644 index 0000000000..d1e528fae5 --- /dev/null +++ b/src/tools/tip-calculator/index.ts @@ -0,0 +1,13 @@ +import { Calculator } from '@vicons/tabler'; +import { defineTool } from '../tool'; +import { translate } from '@/plugins/i18n.plugin'; + +export const tool = defineTool({ + name: translate('tools.tip-calculator.title'), + path: '/tip-calculator', + description: translate('tools.tip-calculator.description'), + keywords: ['tip', 'calculator', 'bill', 'split', 'restaurant', 'money', 'payment'], + component: () => import('./tip-calculator.vue'), + icon: Calculator, + createdAt: new Date('2024-04-17'), +}); diff --git a/src/tools/tip-calculator/tip-calculator.vue b/src/tools/tip-calculator/tip-calculator.vue new file mode 100644 index 0000000000..576a5cf761 --- /dev/null +++ b/src/tools/tip-calculator/tip-calculator.vue @@ -0,0 +1,93 @@ + + + From a48ca886c29a1690004a8bbb83ec087434b4a529 Mon Sep 17 00:00:00 2001 From: rishu ray Date: Sun, 19 Apr 2026 20:49:17 +0530 Subject: [PATCH 2/5] fix: add E2E tests, data-test-id and remove currency symbols --- .../tip-calculator/tip-calculator.e2e.spec.ts | 49 ++++++++++++++++ src/tools/tip-calculator/tip-calculator.vue | 58 ++++++++++++++----- 2 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 src/tools/tip-calculator/tip-calculator.e2e.spec.ts diff --git a/src/tools/tip-calculator/tip-calculator.e2e.spec.ts b/src/tools/tip-calculator/tip-calculator.e2e.spec.ts new file mode 100644 index 0000000000..f122afefab --- /dev/null +++ b/src/tools/tip-calculator/tip-calculator.e2e.spec.ts @@ -0,0 +1,49 @@ +import { expect, test } from '@playwright/test'; + +test.describe('Tool - Tip calculator', () => { + test.beforeEach(async ({ page }) => { + await page.goto('/tip-calculator'); + }); + + test('Has correct title', async ({ page }) => { + await expect(page).toHaveTitle('Tip calculator - IT Tools'); + }); + + test('Correctly calculates tip and split', async ({ page }) => { + // Fill bill amount + await page.getByTestId('billAmount').locator('input').fill('100'); + + // Fill tip percentage + await page.getByTestId('tipPercentage').locator('input').fill('15'); + + // Fill number of people + await page.getByTestId('numberOfPeople').locator('input').fill('2'); + + // Check results + // 100 * 0.15 = 15.00 + await expect(page.getByTestId('tipAmountResult').locator('input')).toHaveValue('15.00'); + + // 100 + 15 = 115.00 + await expect(page.getByTestId('totalBillResult').locator('input')).toHaveValue('115.00'); + + // 115 / 2 = 57.50 + await expect(page.getByTestId('amountPerPersonResult').locator('input')).toHaveValue('57.50'); + }); + + test('Quick tip buttons work', async ({ page }) => { + await page.getByTestId('billAmount').locator('input').fill('100'); + + // Click 20% button + await page.getByRole('button', { name: '20%' }).click(); + + await expect(page.getByTestId('tipPercentage').locator('input')).toHaveValue('20'); + await expect(page.getByTestId('tipAmountResult').locator('input')).toHaveValue('20.00'); + }); + + test('Displays initial/empty results correctly', async ({ page }) => { + // Initial state with empty bill + await expect(page.getByTestId('tipAmountResult').locator('input')).toHaveValue('0.00'); + await expect(page.getByTestId('totalBillResult').locator('input')).toHaveValue('0.00'); + await expect(page.getByTestId('amountPerPersonResult').locator('input')).toHaveValue('0.00'); + }); +}); diff --git a/src/tools/tip-calculator/tip-calculator.vue b/src/tools/tip-calculator/tip-calculator.vue index 576a5cf761..3838724c21 100644 --- a/src/tools/tip-calculator/tip-calculator.vue +++ b/src/tools/tip-calculator/tip-calculator.vue @@ -24,13 +24,13 @@ const amountPerPerson = computed(() => { return totalAmount.value / numberOfPeople.value; }); -const formatCurrency = (value: number) => { - return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(value); +const formatNumber = (value: number) => { + return new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value); }; -const tipAmountFormatted = computed(() => formatCurrency(tipAmount.value)); -const totalAmountFormatted = computed(() => formatCurrency(totalAmount.value)); -const amountPerPersonFormatted = computed(() => formatCurrency(amountPerPerson.value)); +const tipAmountFormatted = computed(() => formatNumber(tipAmount.value)); +const totalAmountFormatted = computed(() => formatNumber(totalAmount.value)); +const amountPerPersonFormatted = computed(() => formatNumber(amountPerPerson.value)); + From 6419e7836d024cfaf620e848112aba421f10ab2e Mon Sep 17 00:00:00 2001 From: rishu ray Date: Mon, 20 Apr 2026 04:02:07 +0530 Subject: [PATCH 3/5] fix(tip-calculator): resolve SonarCloud duplication and stabilize E2E locators --- src/tools/tip-calculator/tip-calculator.vue | 110 +++++--------------- 1 file changed, 27 insertions(+), 83 deletions(-) diff --git a/src/tools/tip-calculator/tip-calculator.vue b/src/tools/tip-calculator/tip-calculator.vue index 3838724c21..55f5b28637 100644 --- a/src/tools/tip-calculator/tip-calculator.vue +++ b/src/tools/tip-calculator/tip-calculator.vue @@ -3,77 +3,44 @@ const billAmount = ref(); const tipPercentage = ref(15); const numberOfPeople = ref(1); -const tipAmount = computed(() => { - if (billAmount.value === undefined || tipPercentage.value === undefined) { - return 0; - } - return (billAmount.value * tipPercentage.value) / 100; -}); +const tipAmount = computed(() => (billAmount.value && tipPercentage.value) ? (billAmount.value * tipPercentage.value) / 100 : 0); +const totalAmount = computed(() => billAmount.value ? billAmount.value + tipAmount.value : 0); +const amountPerPerson = computed(() => (totalAmount.value && numberOfPeople.value && numberOfPeople.value > 0) ? totalAmount.value / numberOfPeople.value : 0); -const totalAmount = computed(() => { - if (billAmount.value === undefined) { - return 0; - } - return billAmount.value + tipAmount.value; -}); +const formatNum = (v: number) => new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(v); -const amountPerPerson = computed(() => { - if (totalAmount.value === 0 || numberOfPeople.value === undefined || numberOfPeople.value <= 0) { - return 0; - } - return totalAmount.value / numberOfPeople.value; -}); - -const formatNumber = (value: number) => { - return new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value); -}; - -const tipAmountFormatted = computed(() => formatNumber(tipAmount.value)); -const totalAmountFormatted = computed(() => formatNumber(totalAmount.value)); -const amountPerPersonFormatted = computed(() => formatNumber(amountPerPerson.value)); +const results = computed(() => [ + { label: 'Tip Amount', val: formatNum(tipAmount.value), id: 'tipAmountResult' }, + { label: 'Total Bill', val: formatNum(totalAmount.value), id: 'totalBillResult' }, + { label: 'Amount Per Person', val: formatNum(amountPerPerson.value), id: 'amountPerPersonResult', isBold: true } +]); - diff --git a/src/ui/c-select/c-select.vue b/src/ui/c-select/c-select.vue index 7b3607c93e..38e2eb8fef 100644 --- a/src/ui/c-select/c-select.vue +++ b/src/ui/c-select/c-select.vue @@ -151,7 +151,7 @@ function onSearchInput() { >
- + {{ selectedOption.label }} diff --git a/src/ui/c-table/c-table.vue b/src/ui/c-table/c-table.vue index ef569890e0..43293ab3c9 100644 --- a/src/ui/c-table/c-table.vue +++ b/src/ui/c-table/c-table.vue @@ -39,7 +39,7 @@ const headers = computed(() => {