Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Developing/2.0.0 to Main #260

Merged
merged 13 commits into from
Oct 27, 2024
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main
- developing/2.0.0

jobs:
ci:
Expand All @@ -27,8 +28,8 @@ jobs:
- name: Run unit test
run: pnpm test

- name: Type check
run: pnpm typecheck
# - name: Type check
# run: pnpm typecheck

- name: Build the app
run: pnpm build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ coverage
/playwright-report/
/playwright/.cache/
# Webkit with playwright creates a salt file
salt
salt
sandbox
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @sunnydanu
4 changes: 4 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,14 @@ declare module '@vue/runtime-core' {
NDivider: typeof import('naive-ui')['NDivider']
NDynamicInput: typeof import('naive-ui')['NDynamicInput']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NH1: typeof import('naive-ui')['NH1']
NH2: typeof import('naive-ui')['NH2']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NImage: typeof import('naive-ui')['NImage']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions src/tools/energy-computer/energy-computer.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe, expect, it } from 'vitest';

import { computeCost } from './energy-computer.service'; // Adjust the import path as needed

describe('computeCost', () => {
it('should calculate the correct cost for valid inputs', () => {
const wattage = 1000; // 1000 watts = 1 kW
const duration = 5; // 5 hours
const kWhCost = 0.12; // $0.12 per kWh
const result = computeCost(wattage, duration, kWhCost);
expect(result).toBeCloseTo(0.60); // 1 kW * 5h * 0.12 = 0.60
});

it('should return 0 when the duration is 0', () => {
const wattage = 1000;
const duration = 0;
const kWhCost = 0.12;
const result = computeCost(wattage, duration, kWhCost);
expect(result).toBe(0);
});

it('should return 0 when the wattage is 0', () => {
const wattage = 0;
const duration = 5;
const kWhCost = 0.12;
const result = computeCost(wattage, duration, kWhCost);
expect(result).toBe(0);
});

it('should return 0 when the cost per kWh is 0', () => {
const wattage = 1000;
const duration = 5;
const kWhCost = 0;
const result = computeCost(wattage, duration, kWhCost);
expect(result).toBe(0);
});

it('should handle fractional wattage and duration correctly', () => {
const wattage = 750; // 0.75 kW
const duration = 2.5; // 2.5 hours
const kWhCost = 0.10; // $0.10 per kWh
const result = computeCost(wattage, duration, kWhCost);
expect(result).toBeCloseTo(0.1875); // 0.75 kW * 2.5h * 0.10 = 0.1875
});

it('should handle large numbers correctly', () => {
const wattage = 1000000; // 1 MW
const duration = 24; // 24 hours
const kWhCost = 0.15; // $0.15 per kWh
const result = computeCost(wattage, duration, kWhCost);
expect(result).toBe(3600); // 1000 kW * 24h * 0.15 = 3600
});
});
6 changes: 6 additions & 0 deletions src/tools/energy-computer/energy-computer.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function computeCost(wattage: number, durationHours: number, costPerKWh: number): number {
const kilowatts = wattage / 1000;
const energyConsumed = kilowatts * durationHours;
const totalCost = energyConsumed * costPerKWh;
return totalCost;
}
26 changes: 26 additions & 0 deletions src/tools/energy-computer/energy-computer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script setup lang="ts">
import { computeCost } from './energy-computer.service';

const wattage = ref(100);
const durationHours = ref(2);
const kWhCost = ref(0.1);
const totalCost = computed(() => computeCost(wattage.value, durationHours.value, kWhCost.value));
</script>

<template>
<div>
<n-form-item label="Device Wattage" mb-1>
<n-input-number v-model:value="wattage" :min="0" />
</n-form-item>
<n-form-item label="Usage Duration (hours)" mb-1>
<n-input-number v-model:value="durationHours" :min="0" />
</n-form-item>
<n-form-item label="kWh Cost" mb-1>
<n-input-number v-model:value="kWhCost" :min="0" />
</n-form-item>

<n-divider />

<input-copyable label="Total Cost" :value="totalCost" />
</div>
</template>
12 changes: 12 additions & 0 deletions src/tools/energy-computer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Engine } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'Energy Consumption and Expense Computer',
path: '/energy-computer',
description: 'Compute energy consumption and expense',
keywords: ['energy', 'expense', 'watt', 'kwh', 'computer'],
component: () => import('./energy-computer.vue'),
icon: Engine,
createdAt: new Date('2024-08-15'),
});
9 changes: 7 additions & 2 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as jsonEditor } from './json-editor';
import { tool as liveCode } from './live-code';
import { tool as emailNormalizer } from './email-normalizer';
import { tool as energyComputer } from './energy-computer';
import { tool as peerShare } from './peer-share';
import { tool as asciiTextDrawer } from './ascii-text-drawer';

import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as xmlToJson } from './xml-to-json';
Expand Down Expand Up @@ -177,7 +177,12 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Measurement',
components: [chronometer, temperatureConverter, benchmarkBuilder],
components: [
chronometer,
temperatureConverter,
benchmarkBuilder,
energyComputer,
],
},
{
name: 'Text',
Expand Down
3 changes: 3 additions & 0 deletions src/tools/json-editor/json-editor-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'json-editor-vue'{

}
7 changes: 2 additions & 5 deletions src/tools/list-converter/list-converter.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test.describe('Tool - List converter', () => {
expect(result.trim()).toEqual('1, 2, 3, 4, 5');
});

test('Duplicates should be removed, list should be sorted and prefix and suffix list items', async ({ page }) => {
test('Duplicates should be removed items', async ({ page }) => {
await page.getByTestId('input').fill(`1
2
2
Expand All @@ -30,10 +30,7 @@ test.describe('Tool - List converter', () => {
3
5`);
await page.getByTestId('removeDuplicates').check();
await page.getByTestId('itemPrefix').fill('\'');
await page.getByTestId('itemSuffix').fill('\'');

const result = await page.getByTestId('area-content').innerText();
expect(result.trim()).toEqual('\'1\', \'2\', \'4\', \'3\', \'5\'');
expect(result.trim()).toEqual('1, 2, 4, 3, 5');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('otp functions', () => {
describe('buildKeyUri', () => {
it('build a key uri string', () => {
expect(buildKeyUri({ secret: 'JBSWY3DPEHPK3PXP' })).to.eql(
'otpauth://totp/godev-run:demo-user?issuer=godev-run&secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&period=30',
'otpauth://totp/godev.run:demo-user?issuer=godev.run&secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&period=30',
);

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function verifyTOTP({

function buildKeyUri({
secret,
app = 'GoDev.Run',
app = 'godev.run',
account = 'demo-user',
algorithm = 'SHA1',
digits = 6,
Expand Down
4 changes: 2 additions & 2 deletions src/tools/text-to-binary/text-to-binary.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ test.describe('Tool - Text to ASCII binary', () => {
await page.getByTestId('text-to-binary-input').fill('godev.run');
const binary = await page.getByTestId('text-to-binary-output').inputValue();

expect(binary).toEqual('01101001 01110100 00101101 01110100 01101111 01101111 01101100 01110011');
expect(binary).toEqual('01100111 01101111 01100100 01100101 01110110 00101110 01110010 01110101 01101110');
});

test('Binary to text conversion', async ({ page }) => {
await page.getByTestId('binary-to-text-input').fill('01101001 01110100 00101101 01110100 01101111 01101111 01101100 01110011');
await page.getByTestId('binary-to-text-input').fill('01100111 01101111 01100100 01100101 01110110 00101110 01110010 01110101 01101110');
const text = await page.getByTestId('binary-to-text-output').inputValue();

expect(text).toEqual('godev.run');
Expand Down
4 changes: 2 additions & 2 deletions src/tools/text-to-unicode/text-to-unicode.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ test.describe('Tool - Text to Unicode', () => {
await page.getByTestId('text-to-unicode-input').fill('godev.run');
const unicode = await page.getByTestId('text-to-unicode-output').inputValue();

expect(unicode).toEqual('&#105;&#116;&#45;&#116;&#111;&#111;&#108;&#115;');
expect(unicode).toEqual('&#103;&#111;&#100;&#101;&#118;&#46;&#114;&#117;&#110;');
});

test('Unicode to text conversion', async ({ page }) => {
await page.getByTestId('unicode-to-text-input').fill('&#105;&#116;&#45;&#116;&#111;&#111;&#108;&#115;');
await page.getByTestId('unicode-to-text-input').fill('&#103;&#111;&#100;&#101;&#118;&#46;&#114;&#117;&#110;');
const text = await page.getByTestId('unicode-to-text-output').inputValue();

expect(text).toEqual('godev.run');
Expand Down
Loading