create project
This commit is contained in:
commit
1390855517
13
.eslintignore
Normal file
13
.eslintignore
Normal file
@ -0,0 +1,13 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Ignore files for PNPM, NPM and YARN
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
30
.eslintrc.cjs
Normal file
30
.eslintrc.cjs
Normal file
@ -0,0 +1,30 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:svelte/recommended',
|
||||
'prettier'
|
||||
],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 2020,
|
||||
extraFileExtensions: ['.svelte']
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
es2017: true,
|
||||
node: true
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.svelte'],
|
||||
parser: 'svelte-eslint-parser',
|
||||
parserOptions: {
|
||||
parser: '@typescript-eslint/parser'
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
||||
5
.idea/.gitignore
generated
vendored
Normal file
5
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
58
.idea/codeStyles/Project.xml
generated
Normal file
58
.idea/codeStyles/Project.xml
generated
Normal file
@ -0,0 +1,58 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<HTMLCodeStyleSettings>
|
||||
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
||||
<option name="HTML_ENFORCE_QUOTES" value="true" />
|
||||
</HTMLCodeStyleSettings>
|
||||
<JSCodeStyleSettings version="0">
|
||||
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
||||
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
||||
<option name="FORCE_QUOTE_STYlE" value="true" />
|
||||
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
||||
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
||||
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
||||
</JSCodeStyleSettings>
|
||||
<TypeScriptCodeStyleSettings version="0">
|
||||
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
||||
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
||||
<option name="FORCE_QUOTE_STYlE" value="true" />
|
||||
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
||||
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
||||
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
||||
</TypeScriptCodeStyleSettings>
|
||||
<VueCodeStyleSettings>
|
||||
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
||||
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
||||
</VueCodeStyleSettings>
|
||||
<codeStyleSettings language="HTML">
|
||||
<option name="SOFT_MARGINS" value="80" />
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||
<option name="TAB_SIZE" value="2" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JavaScript">
|
||||
<option name="SOFT_MARGINS" value="80" />
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||
<option name="TAB_SIZE" value="2" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="TypeScript">
|
||||
<option name="SOFT_MARGINS" value="80" />
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||
<option name="TAB_SIZE" value="2" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Vue">
|
||||
<option name="SOFT_MARGINS" value="80" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
||||
12
.idea/dphcko-frontend.iml
generated
Normal file
12
.idea/dphcko-frontend.iml
generated
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/dphcko-frontend.iml" filepath="$PROJECT_DIR$/.idea/dphcko-frontend.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/prettier.xml
generated
Normal file
6
.idea/prettier.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PrettierConfiguration">
|
||||
<option name="myConfigurationMode" value="AUTOMATIC" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
13
.prettierignore
Normal file
13
.prettierignore
Normal file
@ -0,0 +1,13 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Ignore files for PNPM, NPM and YARN
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
9
.prettierrc
Normal file
9
.prettierrc
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 100,
|
||||
"plugins": ["prettier-plugin-svelte"],
|
||||
"pluginSearchDirs": ["."],
|
||||
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
|
||||
}
|
||||
38
README.md
Normal file
38
README.md
Normal file
@ -0,0 +1,38 @@
|
||||
# create-svelte
|
||||
|
||||
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
|
||||
|
||||
## Creating a project
|
||||
|
||||
If you're seeing this, you've probably already done this step. Congrats!
|
||||
|
||||
```bash
|
||||
# create a new project in the current directory
|
||||
npm create svelte@latest
|
||||
|
||||
# create a new project in my-app
|
||||
npm create svelte@latest my-app
|
||||
```
|
||||
|
||||
## Developing
|
||||
|
||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
|
||||
# or start the server and open the app in a new browser tab
|
||||
npm run dev -- --open
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
To create a production version of your app:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
You can preview the production build with `npm run preview`.
|
||||
|
||||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
||||
5388
package-lock.json
generated
Normal file
5388
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
40
package.json
Normal file
40
package.json
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "dphcko-frontend",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"test": "npm run test:integration && npm run test:unit",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"lint": "prettier --plugin-search-dir . --check . && eslint .",
|
||||
"format": "prettier --plugin-search-dir . --write .",
|
||||
"test:integration": "playwright test",
|
||||
"test:unit": "vitest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.28.1",
|
||||
"@sveltejs/adapter-auto": "^2.0.0",
|
||||
"@sveltejs/kit": "^1.20.4",
|
||||
"@testing-library/jest-dom": "^5.17.0",
|
||||
"@testing-library/svelte": "^4.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
||||
"@typescript-eslint/parser": "^5.45.0",
|
||||
"eslint": "^8.28.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-svelte": "^2.30.0",
|
||||
"jsdom": "^22.1.0",
|
||||
"prettier": "^2.8.0",
|
||||
"prettier-plugin-svelte": "^2.10.1",
|
||||
"ress": "^5.0.2",
|
||||
"svelte": "^4.0.5",
|
||||
"svelte-check": "^3.4.3",
|
||||
"tslib": "^2.4.1",
|
||||
"typescript": "^5.0.0",
|
||||
"vite": "^4.4.2",
|
||||
"vitest": "^0.32.4"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
12
playwright.config.ts
Normal file
12
playwright.config.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import type { PlaywrightTestConfig } from '@playwright/test';
|
||||
|
||||
const config: PlaywrightTestConfig = {
|
||||
webServer: {
|
||||
command: 'npm run build && npm run preview',
|
||||
port: 4173
|
||||
},
|
||||
testDir: 'tests',
|
||||
testMatch: /(.+\.)?(test|spec)\.[jt]s/
|
||||
};
|
||||
|
||||
export default config;
|
||||
12
src/app.d.ts
vendored
Normal file
12
src/app.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
// See https://kit.svelte.dev/docs/types#app
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
12
src/app.html
Normal file
12
src/app.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<main>%sveltekit.body%</main>
|
||||
</body>
|
||||
</html>
|
||||
7
src/index.test.ts
Normal file
7
src/index.test.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
describe('sum test', () => {
|
||||
it('adds 1 + 2 to equal 3', () => {
|
||||
expect(1 + 2).toBe(3);
|
||||
});
|
||||
});
|
||||
110
src/lib/calculator/Calculator.svelte
Normal file
110
src/lib/calculator/Calculator.svelte
Normal file
@ -0,0 +1,110 @@
|
||||
<script lang="ts">
|
||||
import type CalculatorValues from '$lib/calculator/type/CalculatorValues';
|
||||
import {
|
||||
refreshBasePrice,
|
||||
refreshFinalPrice,
|
||||
refreshVatAmount
|
||||
} from '$lib/calculator/functions/RefreshFunctions';
|
||||
|
||||
let calcValues: CalculatorValues = {
|
||||
basePrice: 0.0,
|
||||
vatRate: 0.0,
|
||||
vatAmount: 0.0,
|
||||
finalPrice: 0.0
|
||||
};
|
||||
|
||||
let calcValuesCache: CalculatorValues = {
|
||||
...calcValues
|
||||
};
|
||||
|
||||
function refreshCache(calcValues: CalculatorValues) {
|
||||
calcValuesCache = {
|
||||
...calcValues
|
||||
};
|
||||
}
|
||||
|
||||
function refreshPrices(calcValues: CalculatorValues) {
|
||||
console.log(calcValues);
|
||||
if (
|
||||
calcValues.basePrice !== calcValuesCache.basePrice ||
|
||||
calcValues.vatRate !== calcValuesCache.vatRate
|
||||
) {
|
||||
refreshFinalPrice(calcValues);
|
||||
} else if (calcValues.finalPrice !== calcValuesCache.finalPrice) {
|
||||
refreshBasePrice(calcValues);
|
||||
}
|
||||
|
||||
refreshVatAmount(calcValues);
|
||||
refreshCache(calcValues);
|
||||
}
|
||||
|
||||
$: refreshPrices(calcValues);
|
||||
|
||||
const invalidNumberErrorText = 'Zadejte platné číslo.';
|
||||
</script>
|
||||
|
||||
<form>
|
||||
<label for="vatRate">Sazba DPH (%)</label>
|
||||
<input
|
||||
id="vatRate"
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
bind:value={calcValues.vatRate}
|
||||
class:invalid={calcValues.vatRate === null}
|
||||
/>
|
||||
{#if calcValues.vatRate === null}
|
||||
<p class="invalid">{invalidNumberErrorText}</p>
|
||||
{/if}
|
||||
<label for="basePrice">Cena bez DPH (Kč)</label>
|
||||
<input
|
||||
id="basePrice"
|
||||
type="number"
|
||||
min="0"
|
||||
bind:value={calcValues.basePrice}
|
||||
class:invalid={calcValues.basePrice === null}
|
||||
/>
|
||||
{#if calcValues.basePrice === null}
|
||||
<p class="invalid">{invalidNumberErrorText}</p>
|
||||
{/if}
|
||||
<label for="finalPrice">Cena s DPH (Kč)</label>
|
||||
<input
|
||||
id="finalPrice"
|
||||
type="number"
|
||||
min="0 "
|
||||
bind:value={calcValues.finalPrice}
|
||||
class:invalid={calcValues.finalPrice === null}
|
||||
/>
|
||||
{#if calcValues.finalPrice === null}
|
||||
<p class="invalid">{invalidNumberErrorText}</p>
|
||||
{/if}
|
||||
</form>
|
||||
|
||||
<div class="vatAmount">
|
||||
Výše DPH: {calcValues.vatAmount} Kč
|
||||
</div>
|
||||
|
||||
<style>
|
||||
p.invalid {
|
||||
color: var(--invalid-color);
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
border: 2px solid gray;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
input.invalid {
|
||||
border: 4px solid var(--invalid-color);
|
||||
}
|
||||
|
||||
input[type='number'] {
|
||||
-moz-appearance: textfield;
|
||||
appearance: textfield;
|
||||
}
|
||||
|
||||
input[type='number']::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
</style>
|
||||
80
src/lib/calculator/Calculator.test.ts
Normal file
80
src/lib/calculator/Calculator.test.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import Calculator from '$lib/calculator/Calculator.svelte';
|
||||
import { describe, it } from 'vitest';
|
||||
import '@testing-library/jest-dom';
|
||||
import { fireEvent, render, screen } from '@testing-library/svelte';
|
||||
|
||||
function initFields() {
|
||||
render(Calculator);
|
||||
|
||||
return {
|
||||
vatRate: screen.getByLabelText('Sazba DPH (%)', { selector: 'input' }),
|
||||
basePrice: screen.getByLabelText('Cena bez DPH', { selector: 'input' }),
|
||||
finalPrice: screen.getByLabelText('Cena s DPH', { selector: 'input' })
|
||||
};
|
||||
}
|
||||
|
||||
describe('Test Calculator.svelte', async () => {
|
||||
it('Initial prices should be zero', async () => {
|
||||
const { vatRate, basePrice, finalPrice } = initFields();
|
||||
|
||||
expect(vatRate).toHaveValue(0);
|
||||
expect(basePrice).toHaveValue(0);
|
||||
expect(finalPrice).toHaveValue(0);
|
||||
});
|
||||
|
||||
it('Calculation #1 should be correct (225*1.21=272.25)', async () => {
|
||||
const { vatRate, basePrice, finalPrice } = initFields();
|
||||
|
||||
expect(vatRate).toHaveValue(0);
|
||||
expect(basePrice).toHaveValue(0);
|
||||
expect(finalPrice).toHaveValue(0);
|
||||
|
||||
await fireEvent.input(vatRate, {
|
||||
target: {
|
||||
value: 21
|
||||
}
|
||||
});
|
||||
|
||||
expect(vatRate).toHaveValue(21);
|
||||
expect(basePrice).toHaveValue(0);
|
||||
expect(finalPrice).toHaveValue(0);
|
||||
|
||||
await fireEvent.input(basePrice, {
|
||||
target: {
|
||||
value: 225
|
||||
}
|
||||
});
|
||||
|
||||
expect(vatRate).toHaveValue(21);
|
||||
expect(basePrice).toHaveValue(225);
|
||||
expect(finalPrice).toHaveValue(272.25);
|
||||
});
|
||||
|
||||
it('Calculation #2 should be correct (272.25/1.21=225)', async () => {
|
||||
const { vatRate, basePrice, finalPrice } = initFields();
|
||||
|
||||
expect(vatRate).toHaveValue(0);
|
||||
expect(basePrice).toHaveValue(0);
|
||||
expect(finalPrice).toHaveValue(0);
|
||||
|
||||
await fireEvent.input(vatRate, {
|
||||
target: {
|
||||
value: 21
|
||||
}
|
||||
});
|
||||
|
||||
expect(vatRate).toHaveValue(21);
|
||||
expect(basePrice).toHaveValue(0);
|
||||
expect(finalPrice).toHaveValue(0);
|
||||
|
||||
await fireEvent.input(finalPrice, {
|
||||
target: {
|
||||
value: 272.25
|
||||
}
|
||||
});
|
||||
|
||||
expect(vatRate).toHaveValue(21);
|
||||
expect(basePrice).toHaveValue(225);
|
||||
expect(finalPrice).toHaveValue(272.25);
|
||||
});
|
||||
});
|
||||
7
src/lib/calculator/functions/CentsConvertFunctions.ts
Normal file
7
src/lib/calculator/functions/CentsConvertFunctions.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export function toCents(price: number): number {
|
||||
return Math.round(price * 100);
|
||||
}
|
||||
|
||||
export function fromCents(priceCents: number): number {
|
||||
return priceCents / 100;
|
||||
}
|
||||
18
src/lib/calculator/functions/RefreshFunctions.ts
Normal file
18
src/lib/calculator/functions/RefreshFunctions.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import type CalculatorValues from '$lib/calculator/type/CalculatorValues';
|
||||
import { getVatAmount, getVatCoefficient } from '$lib/calculator/functions/VatFunctions';
|
||||
import { fromCents, toCents } from '$lib/calculator/functions/CentsConvertFunctions';
|
||||
|
||||
export function refreshFinalPrice(calcValues: CalculatorValues) {
|
||||
const finalPriceCents = toCents(calcValues.basePrice * getVatCoefficient(calcValues.vatRate));
|
||||
calcValues.finalPrice = fromCents(finalPriceCents);
|
||||
}
|
||||
|
||||
export function refreshBasePrice(calcValues: CalculatorValues) {
|
||||
const basePriceCents = toCents(calcValues.finalPrice / getVatCoefficient(calcValues.vatRate));
|
||||
calcValues.basePrice = fromCents(basePriceCents);
|
||||
}
|
||||
|
||||
export function refreshVatAmount(calcValues: CalculatorValues) {
|
||||
const vatAmountCents = toCents(getVatAmount(calcValues.basePrice, calcValues.finalPrice));
|
||||
calcValues.vatAmount = fromCents(vatAmountCents);
|
||||
}
|
||||
7
src/lib/calculator/functions/VatFunctions.ts
Normal file
7
src/lib/calculator/functions/VatFunctions.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export function getVatCoefficient(vatRate: number): number {
|
||||
return 1 + vatRate / 100;
|
||||
}
|
||||
|
||||
export function getVatAmount(basePrice: number, finalPrice: number): number {
|
||||
return finalPrice - basePrice;
|
||||
}
|
||||
1
src/lib/calculator/rates/VatRates.ts
Normal file
1
src/lib/calculator/rates/VatRates.ts
Normal file
@ -0,0 +1 @@
|
||||
export const vatRates = [];
|
||||
6
src/lib/calculator/type/CalculatorValues.ts
Normal file
6
src/lib/calculator/type/CalculatorValues.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export default interface CalculatorValues {
|
||||
basePrice: number;
|
||||
vatRate: number;
|
||||
vatAmount: number;
|
||||
finalPrice: number;
|
||||
}
|
||||
4
src/lib/calculator/type/VatRate.ts
Normal file
4
src/lib/calculator/type/VatRate.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export default interface VatRate {
|
||||
title: string;
|
||||
rate: number;
|
||||
}
|
||||
1
src/lib/index.ts
Normal file
1
src/lib/index.ts
Normal file
@ -0,0 +1 @@
|
||||
// place files you want to import through the `$lib` alias in this folder.
|
||||
11
src/routes/+layout.svelte
Normal file
11
src/routes/+layout.svelte
Normal file
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
import 'ress/dist/ress.min.css';
|
||||
</script>
|
||||
|
||||
<slot />
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--invalid-color: red;
|
||||
}
|
||||
</style>
|
||||
9
src/routes/+page.svelte
Normal file
9
src/routes/+page.svelte
Normal file
@ -0,0 +1,9 @@
|
||||
<script lang="ts">
|
||||
import Calculator from '$lib/calculator/Calculator.svelte';
|
||||
</script>
|
||||
|
||||
<h1>DPHčko.cz</h1>
|
||||
|
||||
<p>Kalkulačka DPH – spočítejte si daň z přidané hodnoty</p>
|
||||
|
||||
<Calculator />
|
||||
10
static/data/vat_rates.json
Normal file
10
static/data/vat_rates.json
Normal file
@ -0,0 +1,10 @@
|
||||
[
|
||||
{
|
||||
"name": "Základní sazba",
|
||||
"rate": 21
|
||||
},
|
||||
{
|
||||
"name": "Snížená sazba",
|
||||
"rate": 15
|
||||
}
|
||||
]
|
||||
BIN
static/favicon.png
Normal file
BIN
static/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
18
svelte.config.js
Normal file
18
svelte.config.js
Normal file
@ -0,0 +1,18 @@
|
||||
import adapter from '@sveltejs/adapter-auto';
|
||||
import { vitePreprocess } from '@sveltejs/kit/vite';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
||||
// for more information about preprocessors
|
||||
preprocess: vitePreprocess(),
|
||||
|
||||
kit: {
|
||||
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
|
||||
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
|
||||
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
|
||||
adapter: adapter()
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
6
tests/test.ts
Normal file
6
tests/test.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test('index page has expected h1', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await expect(page.getByRole('heading', { name: 'Welcome to SvelteKit' })).toBeVisible();
|
||||
});
|
||||
17
tsconfig.json
Normal file
17
tsconfig.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true
|
||||
}
|
||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
||||
//
|
||||
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
||||
// from the referenced tsconfig.json - TypeScript does not merge them in
|
||||
}
|
||||
11
vite.config.ts
Normal file
11
vite.config.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [sveltekit()],
|
||||
test: {
|
||||
environment: 'jsdom',
|
||||
globals: true,
|
||||
include: ['src/**/*.{test,spec}.{js,ts}']
|
||||
}
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user