mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-02-06 09:56:03 +00:00
Add: saving comments with their postId as key
This commit is contained in:
parent
0d397655ee
commit
828f79b6f3
@ -157,6 +157,10 @@ describe('Editor.vue', () => {
|
||||
value,
|
||||
}
|
||||
}
|
||||
|
||||
beforeAll(() => jest.useFakeTimers())
|
||||
afterAll(() => jest.useRealTimers())
|
||||
|
||||
describe('when false', () => {
|
||||
let routerWrapper
|
||||
|
||||
@ -170,9 +174,8 @@ describe('Editor.vue', () => {
|
||||
})
|
||||
|
||||
it('does nothing', () => {
|
||||
jest.useFakeTimers()
|
||||
|
||||
const content = '<p>NOOP WIP</p>'
|
||||
|
||||
routerWrapper.vm.editor.setContent(content, true)
|
||||
jest.runAllTimers()
|
||||
|
||||
@ -181,31 +184,52 @@ describe('Editor.vue', () => {
|
||||
})
|
||||
|
||||
describe('when editing a post', () => {
|
||||
let routerWrapper
|
||||
const content = '<p>Post WIP</p>'
|
||||
const setItemSpy = jest.spyOn(Storage.prototype, 'setItem')
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
router = new VueRouter({
|
||||
routes: [{ path: 'post/create' }],
|
||||
})
|
||||
router.push('/post/create')
|
||||
routerWrapper = Wrapper()
|
||||
|
||||
Wrapper().vm.editor.setContent(content, true)
|
||||
await jest.runAllTimers()
|
||||
})
|
||||
|
||||
afterEach(setItemSpy.mockReset)
|
||||
afterEach(() => {
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
it('saves editor content to localStorage on input', async () => {
|
||||
jest.useFakeTimers()
|
||||
|
||||
routerWrapper.vm.editor.setContent(content, true)
|
||||
await jest.runAllTimers()
|
||||
|
||||
const { storageKey, value } = getFirst()
|
||||
expect(setItemSpy).toHaveBeenCalled()
|
||||
expect(storageKey.startsWith('draft:post:')).toBe(true)
|
||||
expect(value).toBe(content)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when editing a comment', () => {
|
||||
const postId = '33739246-fa27-42ae-94de-2f590a2d92c4'
|
||||
const content = '<p>Comment WIP</p>'
|
||||
|
||||
beforeEach(async () => {
|
||||
router = new VueRouter({
|
||||
routes: [{ path: `/post/${postId}/foo-title-slug` }],
|
||||
})
|
||||
router.push(`/post/${postId}/foo-title-slug`)
|
||||
|
||||
Wrapper().vm.editor.setContent(content, true)
|
||||
await jest.runAllTimers()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
it('saves editor content to localStorage on input', async () => {
|
||||
const { storageKey, value } = getFirst()
|
||||
expect(storageKey).toBe(`draft:${postId}`)
|
||||
expect(value).toBe(content)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -23,6 +23,13 @@ export default class AutoSave extends Extension {
|
||||
if (this.route.path === '/post/create') {
|
||||
return `draft:post:${this._postId}`
|
||||
}
|
||||
|
||||
const commentMatch = this.route.path.match(/^\/post\/([0-9a-f-]*)\/[\w-]*$/)
|
||||
if (commentMatch) {
|
||||
const key = `draft:${commentMatch[1]}`
|
||||
return key
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
@ -39,16 +46,6 @@ export default class AutoSave extends Extension {
|
||||
}
|
||||
return tr
|
||||
},
|
||||
state: {
|
||||
init() {
|
||||
return {
|
||||
saveNextUpdate: false,
|
||||
}
|
||||
},
|
||||
apply(_, prev) {
|
||||
return { ...prev }
|
||||
},
|
||||
},
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user