Skip to content

Commit 2f7da80

Browse files
committed
feat: add Playwright creation test, toast, search component and trigger toast on create
1 parent 26e15b4 commit 2f7da80

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

e2e/notes.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ test('Note editor is accessible', async ({ page }) => {
1414
await expect(page.locator('label[for="title"]')).toBeVisible()
1515
await expect(page.locator('#title')).toBeVisible()
1616
})
17+
18+
test('Note creation works', async ({ page }) => {
19+
await page.goto('/create')
20+
await page.fill('#title', 'Neue Testnotiz')
21+
await page.fill('#content', 'Dies ist ein Testinhalt')
22+
await page.click('button[type="submit"]')
23+
await expect(page).toHaveURL(/\/notes\/\d+/)
24+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div v-if="visible" role="status" class="toast">Notiz erfolgreich erstellt!</div>
3+
</template>
4+
5+
<script setup lang="ts">
6+
import { ref } from 'vue'
7+
const visible = ref(false)
8+
9+
function showToast() {
10+
visible.value = true
11+
setTimeout(() => visible.value = false, 3000)
12+
}
13+
14+
defineExpose({ showToast })
15+
</script>
16+
17+
<style scoped>
18+
.toast { background: #222; color: #fff; padding: 0.5rem 1rem; border-radius: 6px }
19+
</style>

src/components/NoteSearch.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<input v-model="query" placeholder="Notiz suchen..." />
3+
</template>
4+
5+
<script setup lang="ts">
6+
import { ref, computed } from 'vue'
7+
import { useNoteStore } from '../stores/noteStore'
8+
9+
const query = ref('')
10+
const store = useNoteStore()
11+
const filteredNotes = computed(() =>
12+
store.notes.filter((n: any) => n.title.includes(query.value) || n.content.includes(query.value))
13+
)
14+
15+
defineExpose({ filteredNotes })
16+
</script>

src/views/NoteCreate.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88

99
<button type="submit">Neue Notiz erstellen</button>
1010
</form>
11+
<NoteCreatedToast ref="toastRef" />
1112
</template>
1213

1314
<script setup lang="ts">
1415
import { ref } from 'vue'
1516
import { useRouter } from 'vue-router'
1617
import { useNoteStore } from '../stores/noteStore'
18+
import NoteCreatedToast from '../components/NoteCreatedToast.vue'
1719
1820
const store = useNoteStore()
1921
const router = useRouter()
2022
const title = ref('')
2123
const content = ref('')
24+
const toastRef = ref<any>(null)
2225
2326
function create() {
2427
const id = store.createNote(title.value, content.value)
2528
title.value = ''
2629
content.value = ''
2730
// optimistic redirect to newly created note
31+
toastRef.value?.showToast()
2832
router.push(`/notes/${id}`)
2933
}
3034
</script>

0 commit comments

Comments
 (0)