feat: Added Super & HTML import options in Import modal. Google Keep notes will now also be imported as Super notes, with attachments if importing from HTML (#2433)

This commit is contained in:
Aman Harwara
2023-08-18 16:41:25 +05:30
committed by GitHub
parent 18b7728145
commit ca9895cac1
22 changed files with 432 additions and 101 deletions

View File

@@ -2,37 +2,56 @@
* @jest-environment jsdom
*/
import { jsonTestData, htmlTestData } from './testData'
import { jsonTextContentData, htmlTestData, jsonListContentData } from './testData'
import { GoogleKeepConverter } from './GoogleKeepConverter'
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { GenerateUuid } from '@standardnotes/services'
import { SuperConverterServiceInterface } from '@standardnotes/snjs'
describe('GoogleKeepConverter', () => {
const crypto = {
generateUUID: () => String(Math.random()),
} as unknown as PureCryptoInterface
const superConverterService: SuperConverterServiceInterface = {
isValidSuperString: () => true,
convertOtherFormatToSuperString: (data: string) => data,
convertSuperStringToOtherFormat: (data: string) => data,
}
const generateUuid = new GenerateUuid(crypto)
it('should parse json data', () => {
const converter = new GoogleKeepConverter(generateUuid)
const converter = new GoogleKeepConverter(superConverterService, generateUuid)
const result = converter.tryParseAsJson(jsonTestData)
const textContent = converter.tryParseAsJson(jsonTextContentData, false)
expect(result).not.toBeNull()
expect(result?.created_at).toBeInstanceOf(Date)
expect(result?.updated_at).toBeInstanceOf(Date)
expect(result?.uuid).not.toBeNull()
expect(result?.content_type).toBe('Note')
expect(result?.content.title).toBe('Testing 1')
expect(result?.content.text).toBe('This is a test.')
expect(result?.content.trashed).toBe(false)
expect(result?.content.archived).toBe(false)
expect(result?.content.pinned).toBe(false)
expect(textContent).not.toBeNull()
expect(textContent?.created_at).toBeInstanceOf(Date)
expect(textContent?.updated_at).toBeInstanceOf(Date)
expect(textContent?.uuid).not.toBeNull()
expect(textContent?.content_type).toBe('Note')
expect(textContent?.content.title).toBe('Testing 1')
expect(textContent?.content.text).toBe('This is a test.')
expect(textContent?.content.trashed).toBe(false)
expect(textContent?.content.archived).toBe(false)
expect(textContent?.content.pinned).toBe(false)
const listContent = converter.tryParseAsJson(jsonListContentData, false)
expect(listContent).not.toBeNull()
expect(listContent?.created_at).toBeInstanceOf(Date)
expect(listContent?.updated_at).toBeInstanceOf(Date)
expect(listContent?.uuid).not.toBeNull()
expect(listContent?.content_type).toBe('Note')
expect(listContent?.content.title).toBe('Testing 1')
expect(listContent?.content.text).toBe('- [ ] Test 1\n- [x] Test 2')
expect(textContent?.content.trashed).toBe(false)
expect(textContent?.content.archived).toBe(false)
expect(textContent?.content.pinned).toBe(false)
})
it('should parse html data', () => {
const converter = new GoogleKeepConverter(generateUuid)
const converter = new GoogleKeepConverter(superConverterService, generateUuid)
const result = converter.tryParseAsHtml(
htmlTestData,