55 Commits

Author SHA1 Message Date
77e506ea4c Merge pull request 'development' (#48) from development into main
Reviewed-on: #48
2025-12-16 15:24:58 +01:00
810b020d7d Merge pull request 'b999_chrome_file_upload' (#47) from b999_chrome_file_upload into development
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
Reviewed-on: #47
2025-12-16 13:24:37 +01:00
5be89f83fd add .GLD file verification for drag and drop 2025-12-16 13:20:18 +01:00
2a7783004a fix chrome issue: selecting the same file does not work properly 2025-12-16 12:54:28 +01:00
6f9b386c18 Merge pull request 'implement drag and drop feature' (#46) from f120_drag_and_drop into development
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
Reviewed-on: #46
2025-12-16 09:43:49 +01:00
b4d9824942 implement drag and drop feature 2025-12-16 09:23:22 +01:00
776cc7a1f0 Merge pull request 'fix file upload for Chrome' (#45) from b119_model_upload_chrome into development
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
Reviewed-on: #45
2025-12-15 12:19:11 +01:00
eaa75833df fix file upload for Chrome 2025-12-15 12:18:00 +01:00
30d457f562 Merge pull request 'sync dev with main' (#44) from main into development
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
Reviewed-on: #44
2025-12-15 10:43:14 +01:00
titver968
c1dd9092ea config_prod und dev auf s3 minio 2025-12-10 14:37:03 +01:00
79e0b01796 Merge pull request 'development' (#43) from development into main
Reviewed-on: #43
2025-12-10 10:28:32 +01:00
f008cee404 make share-button secondary style for less emphasis
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
2025-12-10 08:36:43 +01:00
bb91162438 copy link into clipboard and open mail client
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
2025-12-09 11:37:47 +01:00
c078266449 change config to new minio setup for prod
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
2025-12-09 10:26:30 +01:00
922b840c9a fix jenkins pipeline: update packages
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
2025-12-09 10:18:30 +01:00
68823d6ced change config to new minio setup
Some checks failed
InnoHub Processor/tatort/pipeline/head There was a failure building this commit
2025-12-09 10:01:56 +01:00
9bb4d23a2d Merge pull request 'main' (#42) from main into development
Some checks failed
InnoHub Processor/tatort/pipeline/head There was a failure building this commit
Reviewed-on: #42
2025-12-09 09:34:26 +01:00
titver968
e2cd6945f5 Dockerfile.prod 2025-12-02 14:44:35 +01:00
titver968
ba21f797de src/lib/config.ts -> config.json 2025-12-02 14:36:02 +01:00
titver968
646ff668f7 Dockerfile.prod und tailwind.config.cjs 2025-12-02 14:23:12 +01:00
8b6d35b66f remove old configs 2025-11-25 11:44:32 +01:00
e0d6e3cc62 Merge branch 'development' 2025-11-25 11:43:18 +01:00
1158c88d43 fix SonarQube issues: mainly unused imports
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
2025-11-24 08:41:46 +01:00
e6add823a5 update packages 2025-11-24 08:36:42 +01:00
b1c246113c Merge pull request 'f112_vorgang_operationen' (#41) from f112_vorgang_operationen into development
Some checks failed
InnoHub Processor/tatort/pipeline/head There was a failure building this commit
Reviewed-on: #41
2025-11-21 13:12:25 +01:00
5c76e77766 add tests for Vorgang operation: change name and pin 2025-11-21 12:00:14 +01:00
3aee87aaed clarify test case description 2025-11-21 09:39:13 +01:00
97aaf2cd12 fix ´onDelete´ function type 2025-11-21 09:33:41 +01:00
9d35079058 change function parameter name to make it more descriptive: newName -> newValue 2025-11-21 09:26:08 +01:00
73cb398aa0 position PIN code on the same line as the label 2025-11-20 13:05:40 +01:00
365fb0f2c7 allow vorgangPIN to be changed on Vorgang page
includes:
- UI and backend logic
- adjustment to `NameItemEditor` to disallow deletion
2025-11-20 12:54:53 +01:00
c81196343f adjust minor test config: global mock of HTML functions and addition of test-id 2025-11-20 09:52:37 +01:00
c7526be3c9 adjust test to work with adjusted NameItemEditor 2025-11-20 09:50:20 +01:00
b6996902cc implement renaming feature for vorgang
UI and backend logic
make ´NameItemEditor´ reusable to be able to use with Vorgang
2025-11-20 09:46:28 +01:00
b3ba6256e0 remove unused import 2025-11-20 09:37:08 +01:00
9d72a99626 Merge pull request 'f113_UI_fixes' (#40) from f113_UI_fixes into development
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
Reviewed-on: #40
2025-11-13 12:51:29 +01:00
320f6d6c8b remove Vorgang label 2025-11-13 12:46:58 +01:00
ac79f10153 adjust ´edit´ and ´delete´ button on Vorgang page with crimesList 2025-11-13 12:45:07 +01:00
dac1c57c98 align Vorgang item on list page and remove ´Vorgang´ description 2025-11-13 12:03:51 +01:00
4582306dc8 Merge pull request 'f111_frontend_ueberarbeitung' (#39) from f111_frontend_ueberarbeitung into development
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
Reviewed-on: #39
2025-11-13 10:11:05 +01:00
64ff7c6e97 add some tests for crimes ´add´-button, further tests to be defined 2025-11-13 09:41:46 +01:00
e1f207f6fe tests for + (plus) button onVorgang list 2025-11-12 08:10:43 +01:00
2e16a0bc03 adjust UI test for removal of ´Hinzufügen´ button 2025-11-11 08:13:14 +01:00
1c4b154e41 add + (plus) button for addition of Vorgaenge and Crimes 2025-11-11 07:57:29 +01:00
b26080f4c1 successful upload modal for crimes 2025-11-10 08:40:52 +01:00
f92bcd5876 successful file upload 2025-11-07 11:17:39 +01:00
939b3174f2 Merge branch 'development' into f111_frontend_ueberarbeitung 2025-11-07 08:24:19 +01:00
44a9669ea4 remove ´Hinzufügen´ button on home view 2025-11-06 12:45:46 +01:00
cc469f67a5 allow for addition of Vorgaenge on Vorgang overview 2025-11-05 12:19:34 +01:00
titver968
2d9acb402d Merge branch 'main' of ssh://gitea.innovation-hub-niedersachsen.de:4422/innohub/tatort 2025-06-25 12:27:00 +02:00
titver968
a71807c63a Dockerfile end config.json for prod and dev 2025-06-25 12:26:18 +02:00
78bf7c7dbc Jenkinsfile gelöscht 2025-06-25 09:29:34 +02:00
aeccb684b4 Jenkinsfile aktualisiert
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
rename file
2025-06-25 09:11:37 +02:00
425b1ee8fa Jenkins hinzugefügt 2025-06-24 17:20:25 +02:00
6b1a49583e Merge pull request 'refactor-login-page' (#7) from refactor-login-page into main
Reviewed-on: #7
2025-06-18 13:10:25 +02:00
24 changed files with 1429 additions and 900 deletions

View File

@@ -1,7 +1,5 @@
# --- Build stage ---
FROM node:22 AS build
ENV NODE_ENV=production
ENV ORIGIN=https://tatort.innovation-hub-niedersachsen.de
WORKDIR /app
COPY package*.json ./
RUN npm ci
@@ -11,7 +9,13 @@ RUN npm run build
# --- Production stage ---
FROM node:22-alpine3.20
COPY --from=build /app .
WORKDIR /app
ENV NODE_ENV=production
ENV ORIGIN=https://tatort.innovation-hub-niedersachsen.de
COPY --from=build /app/build ./build
COPY --from=build /app/package*.json ./
COPY --from=build /app/config.json ./config.json
RUN npm ci --omit=dev
ENV HOST=0.0.0.0
EXPOSE 3000
CMD ["sh", "-c", "ORIGIN=https://tatort.innovation-hub-niedersachsen.de node build/index.js"]
CMD ["node", "build/index.js"]

View File

@@ -1,10 +1,10 @@
{
"minio": {
"endPoint": "sws3.innovation-hub-niedersachsen.de",
"endPoint": "api-s3.innovation-hub-niedersachsen.de",
"port": 443,
"useSSL": true,
"accessKey": "wjpKrmaqXra99rX3D61H",
"secretKey": "fTPi0u0FR6Lv9Y9IKydWv6WM0EA5XrsK008HCt9u"
"accessKey": "AbCdEfGhIjKlMnOpQrSt",
"secretKey": "UvWxYz1234567890AbCdEfGhIjKlMnOpQrStUvWx"
},
"jwt": {
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",

View File

@@ -1,10 +1,10 @@
{
"minio": {
"endPoint": "sws3.innovation-hub-niedersachsen.de",
"endPoint": "api-s3.innovation-hub-niedersachsen.de",
"port": 443,
"useSSL": true,
"accessKey": "wjpKrmaqXra99rX3D61H",
"secretKey": "fTPi0u0FR6Lv9Y9IKydWv6WM0EA5XrsK008HCt9u"
"accessKey": "AbCdEfGhIjKlMnOpQrSt",
"secretKey": "UvWxYz1234567890AbCdEfGhIjKlMnOpQrStUvWx"
},
"jwt": {
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",

View File

@@ -1,10 +1,10 @@
{
"minio": {
"endPoint": "sws3.innovation-hub-niedersachsen.de",
"endPoint": "api-s3.innovation-hub-niedersachsen.de",
"port": 443,
"useSSL": true,
"accessKey": "wjpKrmaqXra99rX3D61H",
"secretKey": "fTPi0u0FR6Lv9Y9IKydWv6WM0EA5XrsK008HCt9u"
"accessKey": "GxKhfnfkNvlDU7qzsz0D",
"secretKey": "cqSM5rIRr4MPtqzu2sNKgmB9k2OghPbyxwAWogeM"
},
"jwt": {
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",

1107
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,54 @@
<script lang="ts">
import { fly, scale, fade } from 'svelte/transition';
import { cubicOut } from 'svelte/easing';
import { tick } from 'svelte';
let expanded = false;
let formContainer: HTMLDivElement;
async function toggle() {
expanded = !expanded;
if (expanded) {
// Wait for DOM to update
await tick();
// Scroll smoothly into view
formContainer?.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
</script>
<div data-testid="expand-container" class="flex flex-col items-center">
<!-- + / × button -->
<button
data-testid="expand-button"
class="flex items-center justify-center w-12 h-12 rounded-full bg-blue-600 text-white text-2xl font-bold hover:bg-blue-700 transition"
on:click={toggle}
aria-expanded={expanded}
aria-label="Add item"
>
{#if expanded}
{:else}
+
{/if}
</button>
<!-- Expandable content below button -->
{#if expanded}
<div
bind:this={formContainer}
class="w-full mt-4 flex justify-center"
transition:fade
>
<div
in:fly={{ y: 10, duration: 200, easing: cubicOut }}
out:scale={{ duration: 150 }}
class="w-full max-w-2xl"
>
<slot />
</div>
</div>
{/if}
</div>

View File

@@ -13,8 +13,9 @@
// props, old syntax
export let list: ListItem[] = [];
export let currentName: string;
export let onSave: (n: string, o: string) => unknown = () => {};
export let onDelete: (n: string) => unknown = () => {};
export let vorgangToken: string | null;
export let onSave: (n: string, o: string, t?: string) => unknown = () => {};
export let onDelete: ((n: string) => unknown) | null = () => {};
let localName = currentName;
let isEditing = false;
@@ -43,7 +44,9 @@
}
function commitEdit() {
if (!error && localName != currentName) onSave(localName, currentName);
if (!error && localName != currentName) onSave(localName, currentName, vorgangToken);
// restore original value
if (error) { localName = currentName }
isEditing = false;
}
@@ -54,30 +57,60 @@
}
function handleDeleteClick() {
onDelete(currentName);
// vorgangToken defined when deleting Vorgang, otherwise Crime
onDelete(vorgangToken || currentName);
}
</script>
<div data-testid="test-nameItemEditor">
{#if isEditing}
<input
data-testid="test-input"
bind:this={inputRef}
bind:value={localName}
onkeydown={handleKeydown}
/>
<div data-testid="test-nameItemEditor" class="flex flex-col gap-1">
{#if isEditing}
<div class="flex items-center gap-1">
<input
data-testid="test-input"
bind:this={inputRef}
bind:value={localName}
onkeydown={handleKeydown}
class="flex-1 border border-gray-300 rounded px-1.5 py-0.5 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
<button
data-testid="commit-button"
disabled={!!error || localName === currentName}
onclick={commitEdit}
class="text-gray-500 hover:text-green-600 transition disabled:opacity-40"
>
<Check class="w-4 h-4" />
</button>
<button
data-testid="cancel-button"
onclick={cancelEdit}
class="text-gray-500 hover:text-red-600 transition"
>
<X class="w-4 h-4" />
</button>
</div>
{:else}
<div class="flex items-center gap-1">
<span class="text-sm font-medium text-gray-900 truncate">{localName}</span>
<button
data-testid="edit-button"
onclick={startEdit}
class="text-gray-500 hover:text-blue-600 transition"
>
<Edit class="w-4 h-4" />
</button>
{#if onDelete}
<button
data-testid="commit-button"
disabled={!!error || localName === currentName}
onclick={commitEdit}><Check /></button
data-testid="delete-button"
onclick={handleDeleteClick}
class="text-gray-500 hover:text-red-600 transition"
>
<button data-testid="cancel-button" onclick={cancelEdit}><X /></button>
{:else}
<span>{localName}</span>
<button data-testid="edit-button" onclick={startEdit}><Edit /></button>
<button data-testid="delete-button" onclick={handleDeleteClick}><Trash /></button>
{/if}
{#if error}
<p class="text-red-500">{error}</p>
{/if}
<Trash class="w-4 h-4" />
</button>
{/if}
</div>
{/if}
{#if error}
<p class="text-xs text-red-500 mt-1">{error}</p>
{/if}
</div>

View File

@@ -1,3 +1,3 @@
import { readFileSync } from 'fs';
export default JSON.parse(readFileSync('./config_prod.json').toString());
export default JSON.parse(readFileSync('./config.json').toString());

View File

@@ -1,6 +1,7 @@
import { fail } from '@sveltejs/kit';
import { BUCKET, client, CONFIGFILENAME, TOKENFILENAME } from '$lib/minio';
import { checkIfExactDirectoryExists, getContentOfTextObject } from './s3ClientService';
import { v4 as uuidv4 } from 'uuid';
import { db } from './dbService';
@@ -45,6 +46,31 @@ export const getVorgangByToken = (
return result;
};
/**
* Create Vorgang, using a vorgangName and vorgangPIN
* @param vorgangName
* @param vorgangPIN
* @returns {string || false} vorgangToken if successful
*/
export const createVorgang = (vorgangName: string, vorgangPIN: string): string | boolean => {
const vorgangExists = vorgangNameExists(vorgangName);
if (vorgangExists) {
return false;
}
const vorgangToken = uuidv4();
const insertSQLStatement = `INSERT INTO cases (token, name, pin) VALUES (?, ?, ?)`;
const statement = db.prepare(insertSQLStatement);
const info = statement.run(vorgangToken, vorgangName, vorgangPIN);
if (info.changes) {
return vorgangToken;
} else {
return false;
}
};
/**
* Get Vorgang
* @param vorgangName
@@ -208,3 +234,27 @@ export const vorgangPINValidation = function (vorgangToken: string, vorgangPIN:
return true;
};
/**
* Change VorgangName or VorgangPIN
* @param vorgangToken
* @param newValue
* @returns {int} number of affected lines
*/
export const updateVorgangAttrByToken = function (vorgangToken: string,
newValue: string,
column: string) {
const renameSQLStmt = `UPDATE cases set ${column} = ? WHERE token = ?`;
const statement = db.prepare(renameSQLStmt);
let info;
try {
info = statement.run(newValue, vorgangToken);
} catch (err) {
console.log(`error: ${err}`)
return 0;
}
return info.changes;
};

View File

@@ -1,8 +1,6 @@
import { type ServerLoadEvent } from '@sveltejs/kit';
import type { PageServerLoad } from '../anmeldung/$types';
import { ROUTE_NAMES } from '..';
export const load: PageServerLoad = (event: ServerLoadEvent) => {
if (event.locals.user) {
return {

View File

@@ -31,18 +31,6 @@
Verschaffe Dir einen Überblick über alle gespeicherten Tatorte.
</p>
</div>
<div class="group relative rounded-lg p-6 text-sm leading-6 hover:bg-gray-50 w-1/4">
<div
class="flex h-11 w-11 items-center justify-center rounded-lg bg-gray-50 group-hover:bg-white"
>
<AddProcess class=" group-hover:text-indigo-600" />
</div>
<a href="{ROUTE_NAMES.UPLOAD}" class="mt-6 block font-semibold text-gray-900">
Hinzufügen
<span class="absolute inset-0"></span>
</a>
<p class="mt-1 text-gray-600">Fügen Sie einem Tatort Bilder hinzu.</p>
</div>
<div class="group relative rounded-lg p-6 text-sm leading-6 hover:bg-gray-50 w-1/4">
<div
class="flex h-11 w-11 items-center justify-center rounded-lg bg-gray-50 group-hover:bg-white"

View File

@@ -1,6 +1,6 @@
import { getVorgaenge } from '$lib/server/vorgangService';
import { createVorgang, getVorgaenge } from '$lib/server/vorgangService';
import type { PageServerLoad } from '../../(token-based)/view/$types';
import { error } from '@sveltejs/kit';
import { error, fail } from '@sveltejs/kit';
export const load: PageServerLoad = async (event) => {
if (!event.locals.user) {
@@ -13,3 +13,23 @@ export const load: PageServerLoad = async (event) => {
vorgangList
};
};
export const actions = {
default: async ({ request }: { request: Request }) => {
const data = await request.formData();
const vorgangName: string | null = data.get('vorgang') as string;
const vorgangPIN: string | null = data.get('pin') as string;
const err = {};
const token = createVorgang(vorgangName, vorgangPIN);
if (!token) {
err.message = "Der Vorgang konnte nicht angelegt werden"
return fail(400, err)
} else {
// success
return { token }
}
}
};

View File

@@ -1,24 +1,94 @@
<script lang="ts">
import ExpandableForm from '$lib/components/ExpandableForm.svelte';
import Trash from '$lib/icons/Trash.svelte';
import Folder from '$lib/icons/Folder.svelte';
import EmptyList from '$lib/components/EmptyList.svelte';
import NameItemEditor from '$lib/components/NameItemEditor.svelte';
import Alert from '$lib/components/Alert.svelte';
import Button from '$lib/components/Button.svelte';
import Modal from '$lib/components/Modal/Modal.svelte';
import ModalTitle from '$lib/components/Modal/ModalTitle.svelte';
import ModalContent from '$lib/components/Modal/ModalContent.svelte';
import ModalFooter from '$lib/components/Modal/ModalFooter.svelte';
import { API_ROUTES, ROUTE_NAMES } from '../../index.js';
import { invalidateAll } from '$app/navigation';
let { data } = $props();
let { data, form } = $props();
let vorgangList = data.vorgangList;
let vorgangList = $state(data.vorgangList);
// same as `vorgangList` but with one different property to be used
// with ´NameItemEditor`
const derivedList = $derived.by(
() => {
return vorgangList.map(
({ vorgangName, ...rest }) => (
{
name: vorgangName,
...rest
}
)
)
}
);
let isEmptyList = vorgangList.length === 0;
async function delete_item(ev: Event) {
let vorgangName = $state('');
let vorgangPIN = $state('');
let errorMsg = $state('');
// reset input fields when submission successful
$effect(() => {
if (form?.token) {
vorgangName = '';
vorgangPIN = '';
errorMsg = '';
}
});
async function submitVorgang(ev: Event) {
const isValid = inputValid(vorgangName, vorgangPIN);
if (!isValid) {
ev.preventDefault();
return;
}
// continue form action on server
}
/**
* Check for required fields
* @param vorgangName
* @param vorgangPIN
* @returns {boolean} Indicates whether input is valid
*/
function inputValid(vorgangName, vorgangPIN) {
if (!(vorgangName || vorgangPIN)) {
errorMsg = 'Bitte beide Felder ausfüllen.';
return false;
} else if (!vorgangName) {
errorMsg = 'Bitte einen Vorgangsnamen vergeben.';
return false;
} else if (!vorgangPIN) {
errorMsg = 'Bitte einen Vorgangs-PIN eingeben.';
return false;
}
const existing = vorgangList.some((vorg) => vorg.vorgangName === vorgangName);
if (existing) {
errorMsg = 'Der Name existiert bereits.';
return false;
}
return true;
}
async function deleteVorgang(vorgangToken: string) {
let delete_item = window.confirm('Bist du sicher?');
if (delete_item) {
const target = ev.currentTarget as HTMLElement | null;
if (!target) return;
let filename = target.id.split('del__')[1];
let url = API_ROUTES.VORGANG(filename);
let url = API_ROUTES.VORGANG(vorgangToken);
try {
const response = await fetch(url, { method: 'DELETE' });
@@ -36,6 +106,46 @@
}
}
}
//Variablen für Modal
let open = $state(false);
let inProgress = $state(false);
let isError = $state(false);
async function handleSave(newName: string, oldName: string, vorgangToken: string) {
open = true;
inProgress = true;
isError = false;
try {
const res = await fetch(API_ROUTES.VORGANG(vorgangToken), {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ vorgangToken, oldName, newName })
});
if (!res.ok) {
throw new Error('Fehler beim Speichern');
}
await invalidateAll();
vorgangList = data.vorgangList;
open = false;
} catch (err) {
console.error('⚠️ Netzwerkfehler beim Speichern', err);
isError = true;
} finally {
inProgress = false;
}
}
async function closeModal() {
open = false;
isError = false;
}
</script>
<div class="-z-10 bg-white">
@@ -49,30 +159,21 @@
{:else}
{#each vorgangList as vorgangItem}
<li data-testid="test-list-item">
<div class="flex items-center justify-center gap-3">
<a
href="{ROUTE_NAMES.VORGANG(vorgangItem.vorgangToken)}"
class="flex justify-between gap-x-6 py-5"
href="{ROUTE_NAMES.VORGANG(vorgangItem.vorgangToken)}"
class="flex flex-col items-center justify-center gap-2 py-4 rounded-lg hover:bg-gray-50 transition text-center"
>
<div class="flex gap-x-4">
<Folder />
<div class="min-w-0 flex-auto">
<span class="text-sm font-semibold leading-6 text-gray-900"
>{vorgangItem.vorgangName}</span
>
<button
style="padding: 2px"
id="del__{vorgangItem.vorgangToken}"
on:click|preventDefault={delete_item}
aria-label="Vorgang {vorgangItem.name} löschen"
>
<Trash />
</button>
</div>
</div>
<div class="hidden sm:flex sm:flex-col sm:items-end">
<p class="text-sm leading-6 text-gray-900">Vorgang</p>
</div>
<Folder class="w-6 h-6 text-gray-600" />
</a>
<NameItemEditor
list={derivedList}
currentName={vorgangItem.vorgangName}
vorgangToken={vorgangItem.vorgangToken}
onSave={handleSave}
onDelete={deleteVorgang}
/>
</div>
</li>
{/each}
{/if}
@@ -80,8 +181,84 @@
</div>
</div>
<ExpandableForm>
<form class="flex flex-col items-center" method="POST">
<div class="flex flex-col sm:flex-row sm:space-x-4 w-full max-w-lg">
<div class="flex-1">
<label for="vorgang" class="block text-sm font-medium leading-6 text-gray-900">
<span class="flex"> Vorgangsname </span>
</label>
<div class="mt-2">
<div
class="flex rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
>
<input
required
bind:value={vorgangName}
type="text"
name="vorgang"
id="vorgang"
class="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
/>
</div>
</div>
</div>
<div class="flex-1 mt-4 sm:mt-0">
<label for="pin" class="block text-sm font-medium leading-6 text-gray-900">
<span class="flex"> PIN </span>
</label>
<div class="mt-2">
<div
class="flex rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
>
<input
required
type="password"
bind:value={vorgangPIN}
name="pin"
id="pin"
class="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
/>
</div>
</div>
</div>
</div>
{#if errorMsg}
<p>{errorMsg}</p>
{/if}
{#if form?.message}
<p>{form.message}</p>
{/if}
<button
type="submit"
on:click={submitVorgang}
class="mt-4 bg-indigo-600 text-white px-6 py-2 rounded hover:bg-indigo-700 transition"
>
Neuen Vorgang hinzufügen
</button>
</form>
</ExpandableForm>
<Modal {open}
><ModalTitle>Umbenennen</ModalTitle><ModalContent>
{#if inProgress}
<p class="py-2 mb-1">Vorgang läuft...</p>
{:else if isError}
<Alert class="w-full" type="error">Fehler beim Umbenennen</Alert>
{:else}
<Alert class="w-full">Umbenennen erfolgreich</Alert>
{/if}
</ModalContent>
<ModalFooter><Button disabled={inProgress} on:click={closeModal}>Ok</Button></ModalFooter>
</Modal>
<style>
ul {
min-width: 24rem;
}
</style>

View File

@@ -1,10 +1,8 @@
import { Readable } from 'stream';
import { BUCKET, client } from '$lib/minio';
import { fail, error } from '@sveltejs/kit';
import { v4 as uuidv4 } from 'uuid';
import { db } from '$lib/server/dbService';
import { getVorgangByName, vorgangNameExists } from '$lib/server/vorgangService';
import { getVorgangByName } from '$lib/server/vorgangService';
const isRequiredFieldValid = (value: unknown) => {
if (value == null) return false;
@@ -20,26 +18,11 @@ export const actions = {
const vorgangName: string | null = data.get('vorgang') as string;
const crimeName: string | null = data.get('name') as string;
const type: string | null = data.get('type') as string;
const vorgangPIN: string | null = data.get('vorgangPIN') as string;
const fileName: string | null = data.get('fileName') as string;
const vorgangExists = vorgangNameExists(vorgangName);
let vorgangToken;
if (!vorgangExists) {
vorgangToken = uuidv4();
const insertSQLStatement = `INSERT INTO cases (token, name, pin) VALUES (?, ?, ?)`;
const statement = db.prepare(insertSQLStatement);
statement.run(vorgangToken, vorgangName, vorgangPIN);
} else {
const vorgang = getVorgangByName(vorgangName);
vorgangToken = vorgang.token;
if (vorgang && vorgang.pin != vorgangPIN) {
const updateSQLStmt = `UPDATE cases SET pin = ? WHERE token = ?`;
const statement = db.prepare(updateSQLStmt);
statement.run(vorgangPIN, vorgangToken);
}
}
const vorgang = getVorgangByName(vorgangName);
vorgangToken = vorgang.token;
let objectName = `${vorgangToken}/${crimeName}`;
switch (type) {
@@ -60,7 +43,6 @@ export const actions = {
const data = Object.fromEntries(requestData);
const vorgang = data.vorgang;
const name = data.name;
const vorgangPIN = data.vorgangPIN;
let success = true;
const err = {};
if (isRequiredFieldValid(vorgang)) {
@@ -77,13 +59,6 @@ export const actions = {
success = false;
}
if (isRequiredFieldValid(vorgangPIN)) {
err.vorgangPIN = null;
} else {
err.vorgangPIN = 'Das Feld Zugangspasswort darf nicht leer bleiben.';
success = false;
}
if (success) return { success };
return fail(400, err);

View File

@@ -1,7 +1,9 @@
<script lang="ts">
import { fade } from 'svelte/transition';
import shortenFileSize from '$lib/helper/shortenFileSize';
import timeElapsed from '$lib/helper/timeElapsed';
import { deserialize } from '$app/forms';
import ExpandableForm from '$lib/components/ExpandableForm.svelte';
import Alert from '$lib/components/Alert.svelte';
import Button from '$lib/components/Button.svelte';
import Modal from '$lib/components/Modal/Modal.svelte';
@@ -12,10 +14,12 @@
import { invalidateAll } from '$app/navigation';
import NameItemEditor from '$lib/components/NameItemEditor.svelte';
import EmptyList from '$lib/components/EmptyList.svelte';
import FileRect from '$lib/icons/File-rect.svelte';
import Exclamation from '$lib/icons/Exclamation.svelte';
import { API_ROUTES, ROUTE_NAMES } from '../../../index.js';
//Seite für die Tatort-Liste
let { data } = $props();
let { data, form } = $props();
interface ListItem {
//sollte Typ Vorgang sein, aber der einfachheit ist es noch ListItem, damit die Komponente NameItemEditor für Vorgang und Tatort eingesetzt werden kann
@@ -33,6 +37,131 @@
let vorgangToken: string = data.vorgang.vorgangToken;
let isEmptyList = $derived(crimesList.length === 0);
// File Upload Variablen
let name = $state('');
let formErrors: Record<string, any> | null = $state(null);
let etag: string | null = $state(null);
let files: FileList | null = $state(null);
let fileInput = $state(null);
// Model Variablen für Upload
let openUL = $state(false);
let inProgressUL = $state(form === null);
// Variablen für Copy-Funktion
let copied = $state(false);
async function buttonClick(event: MouseEvent) {
if (!(await validateForm())) {
event.preventDefault();
return;
}
const url = await getUrl();
openUL = true;
inProgressUL = true;
fetch(url, { method: 'PUT', body: files[0] })
.then((response) => {
inProgressUL = false;
etag = '123';
})
.catch((err) => {
inProgressUL = false;
etag = null;
console.log('ERROR', err);
});
}
async function validateForm() {
let data = new FormData();
data.append('vorgang', vorgangName);
data.append('name', name);
const response = await fetch(ROUTE_NAMES.UPLOAD_VALIDATE, { method: 'POST', body: data });
const result = deserialize(await response.text());
let success = true;
if (result.type === 'success') {
formErrors = null;
} else {
if (result.type === 'failure' && result.data) formErrors = result.data;
success = false;
}
if (!files?.length) {
formErrors = { file: 'Sie haben keine Datei ausgewählt.', ...formErrors };
success = false;
}
if (!(await check_valid_glb_file())) {
formErrors = { file: 'Keine gültige .GLD-Datei', ...formErrors };
success = false;
}
return success;
}
async function uploadSuccessful() {
openUL = false;
name = '';
files = null;
fileInput.value = "";
await invalidateAll();
crimesList = data.crimesList;
}
// `val` is hex string
function swap_endian(val) {
// from https://www.geeksforgeeks.org/bit-manipulation-swap-endianness-of-a-number/
let leftmost_byte = (val & eval(0x000000ff)) >> 0;
let left_middle_byte = (val & eval(0x0000ff00)) >> 8;
let right_middle_byte = (val & eval(0x00ff0000)) >> 16;
let rightmost_byte = (val & eval(0xff000000)) >> 24;
leftmost_byte <<= 24;
left_middle_byte <<= 16;
right_middle_byte <<= 8;
rightmost_byte <<= 0;
let res = leftmost_byte | left_middle_byte | right_middle_byte | rightmost_byte;
return res;
}
async function check_valid_glb_file() {
// GLD Header, magic value 0x46546C67, identifies data as binary glTF, 4 bytes
// little endian!
const GLD_MAGIC = 0x46546c67;
// big endian!
let file = files[0];
const fileHeader = file.slice(0, 4);
const buffer = await fileHeader.arrayBuffer();
console.log(fileHeader);
let headerBytes = new Uint8Array(buffer);
let fileHeaderHex = '0x' + headerBytes.toHex().toString();
if (GLD_MAGIC == swap_endian(fileHeaderHex)) {
return true;
} else {
return false;
}
}
async function getUrl() {
let data = new FormData();
data.append('vorgang', vorgangName);
data.append('name', name);
if (files?.length === 1) {
data.append('type', files[0].type);
data.append('fileName', files[0].name);
}
const response = await fetch(ROUTE_NAMES.UPLOAD_URL, { method: 'POST', body: data });
const result = deserialize(await response.text());
if (result.type === 'success') return result.data?.url;
return null;
}
//Variablen für Modal
let open = $state(false);
let inProgress = $state(false);
@@ -67,6 +196,34 @@
}
}
async function savePIN(newVorgangPIN: string, oldVorgangPIN: string) {
open = true;
inProgress = true;
isError = false;
try {
const res = await fetch(API_ROUTES.VORGANG(vorgangToken), {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ vorgangToken, oldVorgangPIN, newVorgangPIN,
changePIN: true})
});
if (!res.ok) {
throw new Error('Fehler beim Speichern');
}
await invalidateAll();
crimesList = data.crimesList;
open = false;
} catch (err) {
console.error('⚠️ Netzwerkfehler beim Speichern', err);
isError = true;
} finally {
inProgress = false;
}
}
async function handleDelete(tatort: string) {
open = true;
inProgress = true;
@@ -97,9 +254,8 @@
}
}
function constructMailToLink() {
async function copyAndOpenMail() {
const subject = 'Link zum Tatvorgang';
const link = data.url.origin + data.url.pathname;
const body = `Hallo,
@@ -111,27 +267,75 @@ Der Zugangs-PIN wird zur Sicherheit über einen zweiten Kommunikationskanal übe
Mit freundlichen Grüßen,
`;
const mailtoLink = `mailto:?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`;
try {
await navigator.clipboard.writeText(body);
return mailtoLink;
}
copied = true;
// Kurz warten, dann Mail öffnen
setTimeout(() => {
const mailtoLink = `mailto:?subject=${encodeURIComponent(subject)}`;
window.location.href = mailtoLink;
}, 1000);
setTimeout(() => copied = false, 2000);
} catch (err) {
console.error('Clipboard-Fehler:', err);
error = 'Konnte Text nicht kopieren. Bitte manuell markieren und kopieren.';
}
}
function closeModal() {
open = false;
isError = false;
}
// drag and drop functionality
let isDragging = $state(false);
async function handleDrop(event) {
event.preventDefault();
isDragging = false;
if (event.dataTransfer?.files?.length) {
files = event.dataTransfer.files;
}
if (!(await check_valid_glb_file())) {
formErrors = { file: 'Keine gültige .GLD-Datei' }
// reset form fields etc.
files = null;
fileInput.value = '';
} else {
formErrors = { ...formErrors, file: ''}
};
}
</script>
<svelte:window
on:dragover|preventDefault
on:drop|preventDefault
/>
{#if data.vorgang && crimesList}
<div class="-z-10 bg-white">
<div class="flex flex-col items-center justify-center w-full">
<h1 class="text-xl">Vorgang {vorgangName}</h1>
<h1 class="text-xl">{vorgangName}</h1>
{#if admin}
Zugangs-PIN: {vorgangPIN}
<a class="pt-2 pb-6" href={constructMailToLink()}
><Button disabled={isEmptyList}>Share Link</Button></a
>
<div class="flex items-center gap-2">
Zugangs-PIN:
<NameItemEditor
list={[]}
currentName={vorgangPIN}
onSave={savePIN}
onDelete={null}
/>
</div>
<Button variant="secondary" on:click={copyAndOpenMail} disabled={isEmptyList}>Link kopieren und Mail verfassen</Button>
{#if copied}
<p transition:fade>✔ Kopiert! Per Ctrl+V einfügen.</p>
{/if}
{/if}
</div>
<div class="mx-auto flex justify-center max-w-7xl h-full">
@@ -140,56 +344,155 @@ Mit freundlichen Grüßen,
<EmptyList></EmptyList>
{:else}
{#each crimesList as item (item.name)}
<li data-testid="test-list-item">
<div class=" flex gap-x-4">
<a
data-testid="crime-link"
href="{ROUTE_NAMES.CRIME(vorgangToken, item.name, vorgangPIN)}"
class=" flex justify-between gap-x-6 py-5"
aria-label="{ROUTE_NAMES.CRIME(vorgangToken, item.name, vorgangPIN)}"
title={item.name}
>
<Cube />
</a>
<div class="min-w-0 flex-auto">
{#if admin}
<NameItemEditor
list={crimesList}
currentName={item.name}
onSave={handleSave}
onDelete={handleDelete}
></NameItemEditor>
{:else}
<p
data-testid="test-nameItem-p"
class="text-sm font-semibold leading-6 text-gray-900 inline-block min-w-1"
>
{item.name}
</p>
{/if}
{#if item.size}
<p class="mt-1 truncate text-xs leading-5 text-gray-500">
{shortenFileSize(item.size)}
</p>
{/if}
</div>
</div>
<div class="hidden sm:flex sm:flex-col sm:items-end">
<p class="text-sm leading-6 text-gray-900">3D Tatort</p>
{#if item.lastModified}
<p class="mt-1 text-xs leading-5 text-gray-500">
Zuletzt geändert <time datetime="2023-01-23T13:23Z"
>{timeElapsed(new Date(item.lastModified))}</time
>
</p>
{/if}
</div>
</li>
<li
data-testid="test-list-item"
class="flex items-center justify-between gap-6 py-4 px-2 hover:bg-gray-50 rounded-lg transition"
>
<div class="flex items-center gap-4 flex-1">
<a
data-testid="crime-link"
href="{ROUTE_NAMES.CRIME(vorgangToken, item.name, vorgangPIN)}"
class="flex items-center justify-center w-8 h-8 text-gray-600 hover:text-blue-600 transition"
aria-label="{ROUTE_NAMES.CRIME(vorgangToken, item.name, vorgangPIN)}"
title={item.name}
>
<Cube class="w-5 h-5" />
</a>
<div class="flex flex-col flex-1 min-w-0">
{#if admin}
<NameItemEditor
list={crimesList}
currentName={item.name}
onSave={handleSave}
onDelete={handleDelete}
/>
{:else}
<p
data-testid="test-nameItem-p"
class="text-sm font-semibold leading-6 text-gray-900 truncate"
>
{item.name}
</p>
{/if}
<!-- size left, last modified right -->
<div class="flex items-center justify-between mt-1 text-xs leading-5 text-gray-500">
{#if item.size}
<span>{shortenFileSize(item.size)}</span>
{:else}
<span></span>
{/if}
{#if item.lastModified}
<span>
Zuletzt geändert
<time datetime={item.lastModified}>
{timeElapsed(new Date(item.lastModified))}
</time>
</span>
{/if}
</div>
</div>
</div>
</li>
{/each}
{/if}
</ul>
</div>
{#if admin}
<div class="flex justify-center my-4">
<ExpandableForm>
<div class="mx-auto max-w-2xl">
<div class="flex flex-col items-center space-y-6">
<!-- Name Input -->
<div class="w-full max-w-md">
<label for="name" class="block text-sm font-medium leading-6 text-gray-900">
<span class="flex">
{#if formErrors?.name}
<span class="inline-block mr-1"><Exclamation /></span>
{/if} Modellname
</span>
</label>
<div class="mt-2">
<div
class="flex rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
>
<input
bind:value={name}
type="text"
name="name"
id="name"
autocomplete={name}
class="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
/>
</div>
</div>
{#if formErrors?.name}
<p class="block text-sm leading-6 text-red-900 mt-2">{formErrors.name}</p>
{/if}
</div>
<!-- File Upload -->
<div class="w-full max-w-md">
<label for="file" class="block text-sm font-medium leading-6 text-gray-900">
<span class="flex">
{#if formErrors?.file}
<span class="inline-block mr-1"><Exclamation /></span>
{/if} Datei
</span>
</label>
<div
class="mt-2 flex justify-center rounded-lg border border-dashed px-6 py-10
{isDragging
? 'border-blue-500 bg-blue-50'
: 'border-gray-900/25'}"
on:dragover|preventDefault={() => (isDragging = true)}
on:dragleave={() => (isDragging = false)}
on:drop={handleDrop}
>
<div class="text-center">
<FileRect />
<div class="mt-4 flex text-sm leading-6 text-gray-600">
<label
for="file"
class="relative cursor-pointer rounded-md bg-white font-semibold text-indigo-600 focus-within:outline-none focus-within:ring-2 focus-within:ring-indigo-600 focus-within:ring-offset-2 hover:text-indigo-500"
>
<span>Wähle eine Datei aus</span>
<input id="file" bind:this={fileInput} bind:files name="file" type="file" class="sr-only" />
</label>
<p class="pl-1">oder ziehe sie ins Feld</p>
</div>
<p class="text-xs leading-5 text-gray-600">GLB Dateien bis zu 1GB</p>
{#if files?.length}
<div class="flex justify-center text-xs mt-2">
<p class="mx-2">Datei: <span class="font-bold">{files[0].name}</span></p>
<p class="mx-2">
Größe: <span class="font-bold">{shortenFileSize(files[0].size)}</span>
</p>
</div>
{/if}
</div>
</div>
{#if formErrors?.file}
<p class="block text-sm leading-6 text-red-900 mt-2">{formErrors.file}</p>
{/if}
</div>
<div class="mt-6 flex items-center justify-end gap-x-6">
<Button
on:click={buttonClick}
class="rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
>
Hinzufügen
</Button>
</div>
</div>
</div>
</ExpandableForm>
</div>
{/if}
<Modal {open}
><ModalTitle>Umbenennen</ModalTitle><ModalContent>
{#if inProgress}
@@ -202,6 +505,21 @@ Mit freundlichen Grüßen,
</ModalContent>
<ModalFooter><Button disabled={inProgress} on:click={closeModal}>Ok</Button></ModalFooter>
</Modal>
<Modal open={openUL}
><ModalTitle>Upload</ModalTitle><ModalContent>
{#if inProgressUL}
<p class="py-2 mb-1">Upload läuft...</p>
{:else if etag}
<Alert class="w-full">Upload erfolgreich</Alert>
{:else}
<Alert class="w-full" type="error">Fehler beim Upload</Alert>
{/if}
</ModalContent>
<ModalFooter
><Button disabled={inProgressUL} on:click={uploadSuccessful}>Ok</Button></ModalFooter
>
</Modal>
</div>
{/if}

View File

@@ -1,5 +1,4 @@
import { getVorgaenge } from '$lib/server/vorgangService';
import { json } from '@sveltejs/kit';
export async function GET() {
const vorgaenge = getVorgaenge();

View File

@@ -3,7 +3,8 @@ import { json } from '@sveltejs/kit';
import {
deleteVorgangByToken,
getCrimesListByToken,
vorgangNameExists
vorgangNameExists,
updateVorgangAttrByToken
} from '$lib/server/vorgangService';
export async function DELETE({ params }) {
@@ -57,3 +58,31 @@ export async function GET({ params }) {
return new Response(null, { status: 500 });
}
}
// change Vorgang properties
export async function PUT({ request }) {
const data = await request.json();
const vorgangToken = data['vorgangToken'];
const changePIN = data['changePIN'];
let attrChanged;
let newValue;
if (changePIN) {
attrChanged = 'pin';
newValue = data['newVorgangPIN']
} else {
attrChanged = 'name';
newValue = data['newName']
}
const res = updateVorgangAttrByToken(vorgangToken, newValue, attrChanged);
if (!res) {
return json({ msg: 'Fehler beim Umbenennen' }, { status: 400 });
}
return json({ success: 'success' }, { status: 200 });
}

View File

@@ -1,4 +1,3 @@
import { json } from '@sveltejs/kit';
import { deleteUser } from '$lib/server/userService';
export async function DELETE({ params }) {

View File

@@ -87,7 +87,7 @@ describe('NameItemEditor - Funktionalität', () => {
expect(onSave).not.toHaveBeenCalled();
});
it('ruft onSave korrekt auf bei gültigem Namen', async () => {
it('ruft onSave korrekt auf bei gültigem Namen: Tatort/Crime', async () => {
render(NameItemEditor, { props: baseProps });
await fireEvent.click(screen.getByTestId('edit-button'));
@@ -95,7 +95,7 @@ describe('NameItemEditor - Funktionalität', () => {
await fireEvent.input(input, { target: { value: testLocalName } });
await fireEvent.click(screen.getByTestId('commit-button'));
expect(onSave).toHaveBeenCalledWith(testLocalName, testCurrentName);
expect(onSave).toHaveBeenCalledWith(testLocalName, testCurrentName, undefined);
});
it('ruft onDelete korrekt auf', async () => {
@@ -117,7 +117,7 @@ describe('NameItemEditor - Funktionalität', () => {
expect(screen.getByTestId('edit-button')).toBeInTheDocument();
});
it('triggert Save bei Enter-Taste', async () => {
it('triggert Save bei Enter-Taste: Tatort/Crime', async () => {
render(NameItemEditor, { props: baseProps });
await fireEvent.click(screen.getByTestId('edit-button'));
@@ -125,7 +125,7 @@ describe('NameItemEditor - Funktionalität', () => {
await fireEvent.input(input, { target: { value: 'ViaEnter' } });
await fireEvent.keyDown(input, { key: 'Enter' });
expect(onSave).toHaveBeenCalledWith('ViaEnter', testCurrentName);
expect(onSave).toHaveBeenCalledWith('ViaEnter', testCurrentName, undefined);
});
it('bricht ab bei Escape-Taste', async () => {

View File

@@ -13,9 +13,8 @@ describe('Home-Page View', () => {
expect(linkElement).toBeInTheDocument();
expect(linkElement).toHaveAttribute('href', ROUTE_NAMES.LIST);
linkElement = screen.getByText('Hinzufügen');
expect(linkElement).toBeInTheDocument();
expect(linkElement).toHaveAttribute('href', ROUTE_NAMES.UPLOAD);
linkElement = screen.queryByText('Hinzufügen');
expect(linkElement).not.toBeInTheDocument();
linkElement = screen.getByText('Benutzerverwaltung');
expect(linkElement).toBeInTheDocument();

View File

@@ -9,6 +9,21 @@ import { API_ROUTES } from '../../src/routes';
vi.spyOn(nav, 'invalidateAll').mockResolvedValue();
global.fetch = vi.fn().mockResolvedValue({ ok: true });
async function clickPlusButton() {
// mock animation features of the browser
window.HTMLElement.prototype.scrollIntoView = vi.fn();
window.HTMLElement.prototype.animate = vi.fn(() => ({
finished: Promise.resolve(),
cancel: vi.fn(),
}))
// button is visible
const button = screen.getByRole('button', { name: /add item/i })
expect(button).toBeInTheDocument();
await fireEvent.click(button)
}
describe('Seite: Vorgangsansicht', () => {
test.todo('Share Link disabled wenn Liste leer');
@@ -83,3 +98,42 @@ describe('Seite: Vorgangsansicht', () => {
});
});
});
describe('Hinzufügen Button', () => {
it('Unexpandierter Button', () => {
const testData = { ...baseData, vorgangList: [] };
const { getByTestId } = render(TatortListPage, { props: { data: testData } });
const container = getByTestId('expand-container')
expect(container).toBeInTheDocument();
// button is visible
const button = within(container).getByRole('button')
expect(button).toBeInTheDocument();
// input fields are not visible
let label = screen.queryByText('Modellname');
expect(label).not.toBeInTheDocument();
});
it('Expandierter Button nach Klick', async () => {
const testData = { ...baseData, vorgangList: [] };
render(TatortListPage, { props: { data: testData } });
await clickPlusButton();
// input fields are visible
let label = screen.queryByText('Modellname');
expect(label).toBeInTheDocument();
});
it.todo('Check Validation: missing name', async () => {
console.log(`test: input field validation`);
});
it.todo('Create Tatort successful', async () => {
console.log(`test: tatort upload`);
});
});

View File

@@ -100,4 +100,16 @@ describe('Seite: Vorgangsansicht', () => {
expect(linkElement).toHaveAttribute('href', expectedURL);
});
});
describe('PIN Anzeige & Button', () => {
it('Teste korrekte Anzeige von PIN Komponente', () => {
const testData = { ...baseData};
render(TatortListPage, { props: { data: testData } });
const vorgObj = baseData.vorgangList[0]
// PIN is being displayed within ´NameItemEditor´
let label = screen.queryByText(vorgObj.vorgangPIN);
expect(label).toBeInTheDocument();
});
});
});

View File

@@ -1,8 +1,18 @@
import { render, screen, within } from '@testing-library/svelte';
import { describe, expect, it } from 'vitest';
import { render, fireEvent, screen, within } from '@testing-library/svelte';
import { describe, expect, it, vi } from 'vitest';
import VorgangListPage from '$root/routes/(angemeldet)/list/+page.svelte';
import { baseData } from '../fixtures';
import { ROUTE_NAMES } from '../../src/routes';
import { actions } from '../../src/routes/(angemeldet)/list/+page.server';
import { createVorgang } from '$lib/server/vorgangService';
// mock animation features of the browser
window.HTMLElement.prototype.scrollIntoView = vi.fn();
window.HTMLElement.prototype.animate = vi.fn(() => ({
finished: Promise.resolve(),
cancel: vi.fn(),
}))
describe('Vorgänge Liste Page EmptyList-Komponente View', () => {
it('zeigt EmptyList-Komponente an, wenn Liste leer ist', () => {
@@ -43,3 +53,132 @@ describe('Teste Links auf Korrektheit', () => {
expect(linkElement.getAttribute('href')?.toLowerCase()).not.toContain('pin');
});
});
async function clickPlusButton() {
// button is visible
const button = screen.getByTestId('expand-button')
expect(button).toBeInTheDocument();
await fireEvent.click(button)
}
async function inputVorgang() {
const input = document.getElementById("vorgang");
input.value = 'test-vorgang';
// firing the event manually for Svelte
await fireEvent.input(input)
expect(input).toHaveValue('test-vorgang');
}
async function inputVorgangPIN() {
const input = document.getElementById("pin");
input.value = 'test-pin';
// firing the event manually for Svelte
await fireEvent.input(input)
expect(input).toHaveValue('test-pin');
}
describe('Hinzufügen Buton', () => {
it('Unexpandierter Button', () => {
const testData = { ...baseData, vorgangList: [] };
const { getByTestId } = render(VorgangListPage, { props: { data: testData } });
const container = getByTestId('expand-container')
expect(container).toBeInTheDocument();
// button is visible
const button = within(container).getByRole('button')
expect(button).toBeInTheDocument();
// input fields are not visible
let label = screen.queryByText('Vorgangsname');
expect(label).not.toBeInTheDocument();
});
it('Expandierter Button nach Klick', async () => {
const testData = { ...baseData, vorgangList: [] };
render(VorgangListPage, { props: { data: testData } });
await clickPlusButton()
// input fields are visible
let label = screen.queryByText('Vorgangsname');
expect(label).toBeInTheDocument();
});
it('Check Validation: missing PIN', async () => {
const testData = { ...baseData, vorgangList: [] };
render(VorgangListPage, { props: { data: testData } });
await clickPlusButton()
// input
inputVorgang();
// submit
const button = screen.getByText('Neuen Vorgang hinzufügen')
expect(button).toBeInTheDocument()
await fireEvent.click(button);
const errorMsg = 'Bitte einen Vorgangs-PIN eingeben.';
let para = await screen.getByText(errorMsg);
expect(para).toBeInTheDocument();
});
it('Create Vorgang successful', async () => {
const testData = { ...baseData, vorgangList: [] };
render(VorgangListPage, { props: { data: testData } });
await clickPlusButton();
// input fields are visible
let label = screen.queryByText('Vorgangsname');
expect(label).toBeInTheDocument();
inputVorgang();
inputVorgangPIN();
// emulate button click
const button = screen.getByText('Neuen Vorgang hinzufügen');
expect(button).toBeInTheDocument();
await fireEvent.click(button);
// no error message
label = screen.queryByText('Bitte');
expect(label).not.toBeInTheDocument();
});
it('Test default action', async () => {
vi.mock('$lib/server/vorgangService', () => ({
createVorgang: vi.fn(),
}));
const formData = new FormData(); // no data as we are mocking createVorgang
const mockRequest = {
formData: vi.fn().mockResolvedValue(formData)
};
const event = {
request: mockRequest,
};
const testVorgangToken = 'c322f26f-8c5e-4cb9-94b3-b5433bf5109e'
vi.mocked(createVorgang).mockReturnValueOnce(testVorgangToken);
const result = await actions.default(event);
expect(result).toEqual({ token: testVorgangToken });
});
});
describe('Vorgang-Operationen', () => {
it('Teste korrekte Anzeige von Vorgang-Input Komponente', () => {
const testData = { ...baseData};
const { getAllByTestId } = render(VorgangListPage, { props: { data: testData } });
let buttons = getAllByTestId('edit-button')
expect(buttons.length).toBeGreaterThan(1);
});
});