split the code to fix rendering issues

This commit is contained in:
2026-06-06 20:40:58 +02:00
parent 556aa527c8
commit 334776da5a
+18 -16
View File
@@ -53,7 +53,7 @@ final class InMemoryStorageProvider: StorageProvider {
Na bazie powyższego kodu zbudowałem pięć przypadków testowych klasy `NotesStorageTests` (program 4.2). Pierwszy z nich weryfikuje, że przy pustym katalogu metoda `loadNotes()` zwraca pustą tablicę. Kolejne dwa testy sprawdzają poprawność tworzenia pliku oraz odczytu istniejącej notatki. Ostatni test sprawdza, czy dwukrotne wywołanie metody tworzącej notatkę o tej samej nazwie generuje dwa odrębne obiekty.
#let notes_storage_tests = [```swift
#let notes_storage_tests_part_1 = [```swift
@Suite
struct NotesStorageTests {
private func makeStorage(root: URL = URL(filePath: "/test")) -> (NotesStorage, InMemoryStorageProvider) {
@@ -99,21 +99,22 @@ struct NotesStorageTests {
let paths = provider.files.keys
#expect(paths.contains(where: { $0.contains("Note 1") }))
}
@Test
func createNoteTwiceCreatesTwoFiles() {
let root = URL(filePath: "/test")
let (storage, _) = makeStorage(root: root)
storage.createNote(name: "Note")
storage.createNote(name: "Note")
let notes = storage.loadNotes()
#expect(notes.count == 2)
}
}
```]
#let notes_storage_tests_part_2 = [```swift
@Test
func createNoteTwiceCreatesTwoFiles() {
let root = URL(filePath: "/test")
let (storage, _) = makeStorage(root: root)
storage.createNote(name: "Note")
storage.createNote(name: "Note")
let notes = storage.loadNotes()
#expect(notes.count == 2)
}
}
```]
#figure(
notes_storage_tests,
[#notes_storage_tests_part_1, #notes_storage_tests_part_2],
kind: raw,
caption: [Testy jednostkowe dla NotesStorage],
)
@@ -195,7 +196,7 @@ struct NoteContentCodableTests {
`NoteInvitationTests` (program 4.5) obejmuje siedem przypadków testowych. Dwa pierwsze weryfikują, czy metody `accept()` oraz `decline()` przekazują odpowiednio wartości logiczne `true` i `false` do handlera. Kolejne dwa testy sprawdzają czy wielokrotne wywołanie tej samej metody nie powoduje powtórnego wywołania handlera. Piąty test gwarantuje, że po zaakceptowaniu zaproszenia próba jego odrzucenia jest ignorowana. Ostatnie dwa testy weryfikują poprawność obliczanych właściwości: `noteName` zwraca tytuł notatki, a `id` jest tożsame z identyfikatorem nadawcy (`MCPeerID`).
#let note_invitation_tests = [```swift
#let note_invitation_tests_part_1 = [```swift
@Suite
struct NoteInvitationTests {
@Test
@@ -246,7 +247,8 @@ struct NoteInvitationTests {
let invitation = NoteInvitation { _ in }
#expect(invitation.noteName == "Shared note")
}
```]
#let note_invitation_tests_part_2 = [```swift
@Test
func idIsInvitatorPeerID() {
let peerID = MCPeerID(displayName: "host")
@@ -260,7 +262,7 @@ struct NoteInvitationTests {
```]
#figure(
note_invitation_tests,
[#note_invitation_tests_part_1, #note_invitation_tests_part_2],
kind: raw,
caption: [Testy jednostkowe NoteInvitation],
)