|
| 1 | +import { ContentType } from '@standardnotes/domain-core' |
| 2 | +import { getItemTitleInContextOfLinkBubble, doesItemMatchSearchQuery } from './doesItemMatchSearchQuery' |
| 3 | +import { DecryptedItemInterface, ItemContent, SNNote, SNTag, isNote, isTag } from '@standardnotes/snjs' |
| 4 | +import { WebApplicationInterface } from '@standardnotes/ui-services' |
| 5 | + |
| 6 | +describe('getItemTitleInContextOfLinkBubble', () => { |
| 7 | + it('returns the title if present', () => { |
| 8 | + const item = { title: 'Test Title', content_type: ContentType.TYPES.Note } as jest.Mocked<SNNote> |
| 9 | + expect(getItemTitleInContextOfLinkBubble(item as DecryptedItemInterface<ItemContent>)).toBe('Test Title') |
| 10 | + }) |
| 11 | + |
| 12 | + it('returns the note preview if title is empty and item is a note', () => { |
| 13 | + const item = { |
| 14 | + preview_plain: 'Note Preview', |
| 15 | + title: '', |
| 16 | + content_type: ContentType.TYPES.Note, |
| 17 | + } as jest.Mocked<SNNote> |
| 18 | + expect(getItemTitleInContextOfLinkBubble(item as DecryptedItemInterface<ItemContent>)).toBe('Note Preview') |
| 19 | + }) |
| 20 | + |
| 21 | + it('returns empty string if title is empty and item is not a note', () => { |
| 22 | + const item = { title: '', content_type: ContentType.TYPES.Tag } as jest.Mocked<SNNote> |
| 23 | + expect(getItemTitleInContextOfLinkBubble(item as DecryptedItemInterface<ItemContent>)).toBe('') |
| 24 | + }) |
| 25 | +}) |
| 26 | + |
| 27 | +describe('doesItemMatchSearchQuery', () => { |
| 28 | + const application = {} as WebApplicationInterface |
| 29 | + |
| 30 | + it('returns false for a protected note even if the title matches the search query', () => { |
| 31 | + const item = { |
| 32 | + title: '', |
| 33 | + preview_plain: 'Protected Note Content', |
| 34 | + protected: true, |
| 35 | + archived: false, |
| 36 | + trashed: false, |
| 37 | + content_type: ContentType.TYPES.Note, |
| 38 | + } as jest.Mocked<SNNote> |
| 39 | + expect( |
| 40 | + doesItemMatchSearchQuery(item as DecryptedItemInterface<ItemContent>, 'protected note content', application), |
| 41 | + ).toBeFalsy() |
| 42 | + }) |
| 43 | + |
| 44 | + it('returns true if the item title matches the search query', () => { |
| 45 | + const item = { title: 'Matched Item', archived: false, trashed: false } |
| 46 | + expect(doesItemMatchSearchQuery(item as DecryptedItemInterface<ItemContent>, 'matched', application)).toBeTruthy() |
| 47 | + }) |
| 48 | + |
| 49 | + it('returns false if the item is archived', () => { |
| 50 | + const item = { title: 'Archived Item', archived: true, trashed: false } |
| 51 | + expect(doesItemMatchSearchQuery(item as DecryptedItemInterface<ItemContent>, 'archived', application)).toBeFalsy() |
| 52 | + }) |
| 53 | + |
| 54 | + it('returns false if the item is trashed', () => { |
| 55 | + const item = { title: 'Trashed Item', archived: false, trashed: true } |
| 56 | + expect(doesItemMatchSearchQuery(item as DecryptedItemInterface<ItemContent>, 'trashed', application)).toBeFalsy() |
| 57 | + }) |
| 58 | +}) |
0 commit comments