Skip to content

Commit cdbe674

Browse files
committed
up
1 parent 59c8047 commit cdbe674

File tree

7 files changed

+30
-45
lines changed

7 files changed

+30
-45
lines changed

src/app/src/composables/useDraftDocuments.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createStorage } from 'unstorage'
22
import indexedDbDriver from 'unstorage/drivers/indexedb'
33
import { ref } from 'vue'
4-
import type { DatabaseItem, DraftItem, StudioHost, GithubFile, DatabasePageItem, RawFile } from '../types'
4+
import type { DatabaseItem, DraftItem, StudioHost, GithubFile, RawFile } from '../types'
55
import { DraftStatus } from '../types/draft'
66
import type { useGit } from './useGit'
77
import { generateContentFromDocument } from '../utils/content'
@@ -173,16 +173,11 @@ export const useDraftDocuments = createSharedComposable((host: StudioHost, git:
173173
}
174174

175175
async function rename(id: string, newFsPath: string) {
176-
let currentDbItem: DatabaseItem = await host.document.get(id)
176+
const currentDbItem: DatabaseItem = await host.document.get(id)
177177
if (!currentDbItem) {
178178
throw new Error(`Database item not found for document ${id}`)
179179
}
180180

181-
const currentDraftItem: DraftItem<DatabaseItem> | undefined = list.value.find(item => item.id === id)
182-
if (currentDraftItem) {
183-
currentDbItem = currentDraftItem.modified as DatabasePageItem
184-
}
185-
186181
const nameWithoutExtension = newFsPath.split('/').pop()!.split('.').slice(0, -1).join('.')
187182
const newRoutePath = `${currentDbItem.path!.split('/').slice(0, -1).join('/')}/${nameWithoutExtension}`
188183
const content = await generateContentFromDocument(currentDbItem)

src/app/src/utils/database.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type DatabasePageItem, ContentFileExtension } from '../types'
2-
// import { stringify } from 'minimark/stringify'
2+
import { stringify } from 'minimark/stringify'
33

44
export function isEqual(document1: DatabasePageItem, document2: DatabasePageItem) {
55
function removeLastStyle(document: DatabasePageItem) {
@@ -22,11 +22,7 @@ export function isEqual(document1: DatabasePageItem, document2: DatabasePageItem
2222
document2 = removeLastStyle(document2)
2323
}
2424

25-
// TODO: fix issue with created files
26-
// if (stringify(body1) !== stringify(body2)) {
27-
// return false
28-
// }
29-
if (JSON.stringify(body1) !== JSON.stringify(body2)) {
25+
if (stringify(body1) !== stringify(body2)) {
3026
return false
3127
}
3228
}

src/app/test/integration/composables/useDraftDocuments.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, beforeEach, vi } from 'vitest'
2-
import { type StudioHost, type DatabaseItem, DraftStatus } from '../../../src/types'
2+
import { type StudioHost, DraftStatus } from '../../../src/types'
33
import { createMockDocument, createMockStorage, createMockHooks } from '../../mocks/document'
44
import { createMockHost } from '../../mocks/host'
55
import { createMockGit } from '../../mocks/git'
@@ -15,7 +15,7 @@ vi.mock('unstorage/drivers/indexedb', () => ({
1515
async getItem(key: string) {
1616
return mockStorage.get(key) || null
1717
},
18-
async setItem(key: string, value: DatabaseItem) {
18+
async setItem(key: string, value: string) {
1919
mockStorage.set(key, value)
2020
},
2121
async removeItem(key: string) {
@@ -72,7 +72,7 @@ describe('useDraftDocuments - Action Chains Integration Tests', () => {
7272

7373
// Storage
7474
expect(mockStorage.size).toEqual(1)
75-
const storedDraft = JSON.parse(mockStorage.get(normalizeKey(documentId ))!)
75+
const storedDraft = JSON.parse(mockStorage.get(normalizeKey(documentId))!)
7676
expect(storedDraft).toHaveProperty('status', DraftStatus.Created)
7777

7878
// In memory
@@ -165,7 +165,7 @@ describe('useDraftDocuments - Action Chains Integration Tests', () => {
165165
const updatedDocument = createMockDocument(documentId, {
166166
body: {
167167
type: 'minimark',
168-
value: [{ type: 'text', text: 'Updated content' }],
168+
value: ['Updated content'],
169169
},
170170
})
171171
await update(documentId, updatedDocument)
@@ -199,7 +199,7 @@ describe('useDraftDocuments - Action Chains Integration Tests', () => {
199199
const { selectById, rename, update, list } = draftDocuments
200200

201201
const mockDocument = createMockDocument(documentId)
202-
const fsPath = mockHost.document.getFileSystemPath(documentId )
202+
const fsPath = mockHost.document.getFileSystemPath(documentId)
203203
const createdDocument = await mockHost.document.create(fsPath, mockDocument.path, '')
204204

205205
/*
@@ -256,7 +256,7 @@ describe('useDraftDocuments - Action Chains Integration Tests', () => {
256256
const updatedDocument = createMockDocument(newId, {
257257
body: {
258258
type: 'minimark',
259-
value: [{ type: 'text', text: 'Updated content' }],
259+
value: ['Updated content'],
260260
},
261261
})
262262
await update(newId, updatedDocument)

src/app/test/mocks/document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const createMockDocument = (id: string, overrides?: Partial<DatabasePageI
88
extension: 'md',
99
body: {
1010
type: 'minimark',
11-
value: [{ type: 'text', text: 'Test content' }],
11+
value: ['Test content'],
1212
},
1313
meta: {},
1414
...overrides,

src/app/test/mocks/draft.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const draftItemsList: DraftItem[] = [
1414
extension: 'md',
1515
body: {
1616
type: 'minimark',
17-
value: [{ type: 'text', text: 'Original' }],
17+
value: ['Original'],
1818
},
1919
},
2020
modified: {
@@ -24,7 +24,7 @@ const draftItemsList: DraftItem[] = [
2424
extension: 'md',
2525
body: {
2626
type: 'minimark',
27-
value: [{ type: 'text', text: 'Modified' }],
27+
value: ['Modified'],
2828
},
2929
},
3030
},
@@ -39,7 +39,7 @@ const draftItemsList: DraftItem[] = [
3939
extension: 'md',
4040
body: {
4141
type: 'minimark',
42-
value: [{ type: 'text', text: 'Original' }],
42+
value: ['Original'],
4343
},
4444
},
4545
modified: {
@@ -49,7 +49,7 @@ const draftItemsList: DraftItem[] = [
4949
extension: 'md',
5050
body: {
5151
type: 'minimark',
52-
value: [{ type: 'text', text: 'Original' }],
52+
value: ['Original'],
5353
},
5454
},
5555
},
@@ -66,7 +66,7 @@ const draftItemsList: DraftItem[] = [
6666
extension: 'md',
6767
body: {
6868
type: 'minimark',
69-
value: [{ type: 'text', text: 'Original' }],
69+
value: ['Original'],
7070
},
7171
},
7272
modified: {
@@ -76,7 +76,7 @@ const draftItemsList: DraftItem[] = [
7676
extension: 'md',
7777
body: {
7878
type: 'minimark',
79-
value: [{ type: 'text', text: 'Modified' }],
79+
value: ['Modified'],
8080
},
8181
},
8282
},
@@ -91,7 +91,7 @@ const draftItemsList: DraftItem[] = [
9191
extension: 'md',
9292
body: {
9393
type: 'minimark',
94-
value: [{ type: 'text', text: 'Original' }],
94+
value: ['Original'],
9595
},
9696
},
9797
modified: {
@@ -101,7 +101,7 @@ const draftItemsList: DraftItem[] = [
101101
extension: 'md',
102102
body: {
103103
type: 'minimark',
104-
value: [{ type: 'text', text: 'Modified' }],
104+
value: ['Modified'],
105105
},
106106
},
107107
},
@@ -117,7 +117,7 @@ const draftItemsList: DraftItem[] = [
117117
extension: 'md',
118118
body: {
119119
type: 'minimark',
120-
value: [{ type: 'text', text: 'Original' }],
120+
value: ['Original'],
121121
},
122122
},
123123
},
@@ -134,7 +134,7 @@ const draftItemsList: DraftItem[] = [
134134
extension: 'md',
135135
body: {
136136
type: 'minimark',
137-
value: [{ type: 'text', text: 'Original' }],
137+
value: ['Original'],
138138
},
139139
},
140140
modified: {
@@ -144,7 +144,7 @@ const draftItemsList: DraftItem[] = [
144144
extension: 'md',
145145
body: {
146146
type: 'minimark',
147-
value: [{ type: 'text', text: 'Modified' }],
147+
value: ['Modified'],
148148
},
149149
},
150150
},
@@ -159,7 +159,7 @@ const draftItemsList: DraftItem[] = [
159159
extension: 'md',
160160
body: {
161161
type: 'minimark',
162-
value: [{ type: 'text', text: 'Original' }],
162+
value: ['Original'],
163163
},
164164
},
165165
modified: {
@@ -169,7 +169,7 @@ const draftItemsList: DraftItem[] = [
169169
extension: 'md',
170170
body: {
171171
type: 'minimark',
172-
value: [{ type: 'text', text: 'Original' }],
172+
value: ['Original'],
173173
},
174174
},
175175
},

src/app/test/mocks/host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const createMockHost = (): StudioHost => ({
1717
stem: fsPath.split('/').pop()?.replace('.md', ''),
1818
body: {
1919
type: 'minimark',
20-
value: [{ type: 'text', text: content || 'Test content' }],
20+
value: [content || 'Test content'],
2121
},
2222
})
2323
}),

src/app/test/unit/utils/tree.test.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ describe('buildTree with one level of depth', () => {
5656
fsPath: createdDbItem.fsPath,
5757
status: DraftStatus.Created,
5858
original: undefined,
59-
modified: {
60-
...dbItemsList[0],
61-
body: {
62-
type: 'minimark',
63-
value: [['text', 'Created']],
64-
},
65-
},
59+
modified: createdDbItem,
6660
}]
6761

6862
const tree = buildTree(dbItemsList, draftList)
@@ -157,7 +151,7 @@ describe('buildTree with one level of depth', () => {
157151
...updatedDbItem,
158152
body: {
159153
type: 'minimark',
160-
value: [['text', 'Modified']],
154+
value: ['Modified'],
161155
},
162156
},
163157
}]
@@ -348,7 +342,7 @@ describe('buildTree with two levels of depth', () => {
348342
...updatedDbItem,
349343
body: {
350344
type: 'minimark',
351-
value: [['text', 'Modified']],
345+
value: ['Modified'],
352346
},
353347
},
354348
}]
@@ -377,7 +371,7 @@ describe('buildTree with two levels of depth', () => {
377371
...updatedDbItem,
378372
body: {
379373
type: 'minimark',
380-
value: [['text', 'Modified']],
374+
value: ['Modified'],
381375
},
382376
},
383377
}]
@@ -473,7 +467,7 @@ describe('getTreeStatus', () => {
473467
const original: DatabaseItem = dbItemsList[0]
474468
const modified: DatabaseItem = {
475469
...original,
476-
body: { type: 'minimark', value: ['text', 'New body'] },
470+
body: { type: 'minimark', value: ['New body'] },
477471
}
478472

479473
const status = getTreeStatus(modified, original)

0 commit comments

Comments
 (0)