From a3334a01a221877d3e06e02f960fda441f3460bd Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 31 Mar 2023 13:17:26 -0500 Subject: Lex refactor (#362) * Remove the hackcheck for upgrades * Rename the PostEmbeds folder to match the codebase style * Updates to latest lex refactor * Update to use new bsky agent * Update to use api package's richtext library * Switch to upsertProfile * Add TextEncoder/TextDecoder polyfill * Add Intl.Segmenter polyfill * Update composer to calculate lengths by grapheme * Fix detox * Fix login in e2e * Create account e2e passing * Implement an e2e mocking framework * Don't use private methods on mobx models as mobx can't track them * Add tooling for e2e-specific builds and add e2e media-picker mock * Add some tests and fix some bugs around profile editing * Add shell tests * Add home screen tests * Add thread screen tests * Add tests for other user profile screens * Add search screen tests * Implement profile imagery change tools and tests * Update to new embed behaviors * Add post tests * Fix to profile-screen test * Fix session resumption * Update web composer to new api * 1.11.0 * Fix pagination cursor parameters * Add quote posts to notifications * Fix embed layouts * Remove youtube inline player and improve tap handling on link cards * Reset minimal shell mode on all screen loads and feed swipes (close #299) * Update podfile.lock * Improve post notfound UI (close #366) * Bump atproto packages --- __tests__/lib/strings/rich-text-sanitize.ts | 123 ---------------------------- 1 file changed, 123 deletions(-) delete mode 100644 __tests__/lib/strings/rich-text-sanitize.ts (limited to '__tests__/lib/strings/rich-text-sanitize.ts') diff --git a/__tests__/lib/strings/rich-text-sanitize.ts b/__tests__/lib/strings/rich-text-sanitize.ts deleted file mode 100644 index d0bbae5e8..000000000 --- a/__tests__/lib/strings/rich-text-sanitize.ts +++ /dev/null @@ -1,123 +0,0 @@ -import {AppBskyFeedPost} from '@atproto/api' -type Entity = AppBskyFeedPost.Entity -import {RichText} from '../../../src/lib/strings/rich-text' -import {removeExcessNewlines} from '../../../src/lib/strings/rich-text-sanitize' - -describe('removeExcessNewlines', () => { - it('removes more than two consecutive new lines', () => { - const input = new RichText( - 'test\n\n\n\n\ntest\n\n\n\n\n\n\ntest\n\n\n\n\n\n\ntest\n\n\n\n\n\n\ntest', - ) - const output = removeExcessNewlines(input) - expect(output.text).toEqual('test\n\ntest\n\ntest\n\ntest\n\ntest') - }) - - it('removes more than two consecutive new lines with spaces', () => { - const input = new RichText( - 'test\n\n\n\n\ntest\n \n \n \n \n\n\ntest\n\n\n\n\n\n\ntest\n\n\n\n\n \n\ntest', - ) - const output = removeExcessNewlines(input) - expect(output.text).toEqual('test\n\ntest\n\ntest\n\ntest\n\ntest') - }) - - it('returns original string if there are no consecutive new lines', () => { - const input = new RichText('test\n\ntest\n\ntest\n\ntest\n\ntest') - const output = removeExcessNewlines(input) - expect(output.text).toEqual(input.text) - }) - - it('returns original string if there are no new lines', () => { - const input = new RichText('test test test test test') - const output = removeExcessNewlines(input) - expect(output.text).toEqual(input.text) - }) - - it('returns empty string if input is empty', () => { - const input = new RichText('') - const output = removeExcessNewlines(input) - expect(output.text).toEqual('') - }) - - it('works with different types of new line characters', () => { - const input = new RichText( - 'test\r\ntest\n\rtest\rtest\n\n\n\ntest\n\r \n \n \n \n\n\ntest', - ) - const output = removeExcessNewlines(input) - expect(output.text).toEqual('test\r\ntest\n\rtest\rtest\n\ntest\n\ntest') - }) - - it('removes more than two consecutive new lines with zero width space', () => { - const input = new RichText( - 'test\n\n\n\n\ntest\n\u200B\u200B\n\n\n\ntest\n \u200B\u200B \n\n\n\ntest\n\n\n\n\n\n\ntest', - ) - const output = removeExcessNewlines(input) - expect(output.text).toEqual('test\n\ntest\n\ntest\n\ntest\n\ntest') - }) - - it('removes more than two consecutive new lines with zero width non-joiner', () => { - const input = new RichText( - 'test\n\n\n\n\ntest\n\u200C\u200C\n\n\n\ntest\n \u200C\u200C \n\n\n\ntest\n\n\n\n\n\n\ntest', - ) - const output = removeExcessNewlines(input) - expect(output.text).toEqual('test\n\ntest\n\ntest\n\ntest\n\ntest') - }) - - it('removes more than two consecutive new lines with zero width joiner', () => { - const input = new RichText( - 'test\n\n\n\n\ntest\n\u200D\u200D\n\n\n\ntest\n \u200D\u200D \n\n\n\ntest\n\n\n\n\n\n\ntest', - ) - const output = removeExcessNewlines(input) - expect(output.text).toEqual('test\n\ntest\n\ntest\n\ntest\n\ntest') - }) - - it('removes more than two consecutive new lines with soft hyphen', () => { - const input = new RichText( - 'test\n\n\n\n\ntest\n\u00AD\u00AD\n\n\n\ntest\n \u00AD\u00AD \n\n\n\ntest\n\n\n\n\n\n\ntest', - ) - const output = removeExcessNewlines(input) - expect(output.text).toEqual('test\n\ntest\n\ntest\n\ntest\n\ntest') - }) - - it('removes more than two consecutive new lines with word joiner', () => { - const input = new RichText( - 'test\n\n\n\n\ntest\n\u2060\u2060\n\n\n\ntest\n \u2060\u2060 \n\n\n\ntest\n\n\n\n\n\n\ntest', - ) - const output = removeExcessNewlines(input) - expect(output.text).toEqual('test\n\ntest\n\ntest\n\ntest\n\ntest') - }) -}) - -describe('removeExcessNewlines w/entities', () => { - it('preserves entities as expected', () => { - const input = new RichText( - 'test\n\n\n\n\ntest\n\n\n\n\n\n\ntest\n\n\n\n\n\n\ntest\n\n\n\n\n\n\ntest', - [ - {index: {start: 0, end: 13}, type: '', value: ''}, - {index: {start: 13, end: 24}, type: '', value: ''}, - {index: {start: 9, end: 15}, type: '', value: ''}, - {index: {start: 4, end: 9}, type: '', value: ''}, - ], - ) - const output = removeExcessNewlines(input) - expect(entToStr(input.text, input.entities?.[0])).toEqual( - 'test\n\n\n\n\ntest', - ) - expect(entToStr(input.text, input.entities?.[1])).toEqual( - '\n\n\n\n\n\n\ntest', - ) - expect(entToStr(input.text, input.entities?.[2])).toEqual('test\n\n') - expect(entToStr(input.text, input.entities?.[3])).toEqual('\n\n\n\n\n') - expect(output.text).toEqual('test\n\ntest\n\ntest\n\ntest\n\ntest') - expect(entToStr(output.text, output.entities?.[0])).toEqual('test\n\ntest') - expect(entToStr(output.text, output.entities?.[1])).toEqual('test') - expect(entToStr(output.text, output.entities?.[2])).toEqual('test') - expect(output.entities?.[3]).toEqual(undefined) - }) -}) - -function entToStr(str: string, ent?: Entity) { - if (!ent) { - return '' - } - return str.slice(ent.index.start, ent.index.end) -} -- cgit 1.4.1