Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: exclude protected previews from linking search #2853

Merged
merged 1 commit into from Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,58 @@
import { ContentType } from '@standardnotes/domain-core'
import { getItemTitleInContextOfLinkBubble, doesItemMatchSearchQuery } from './doesItemMatchSearchQuery'
import { DecryptedItemInterface, ItemContent, SNNote, SNTag, isNote, isTag } from '@standardnotes/snjs'

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused imports SNTag, isNote, isTag.
import { WebApplicationInterface } from '@standardnotes/ui-services'

describe('getItemTitleInContextOfLinkBubble', () => {
it('returns the title if present', () => {
const item = { title: 'Test Title', content_type: ContentType.TYPES.Note } as jest.Mocked<SNNote>
expect(getItemTitleInContextOfLinkBubble(item as DecryptedItemInterface<ItemContent>)).toBe('Test Title')
})

it('returns the note preview if title is empty and item is a note', () => {
const item = {
preview_plain: 'Note Preview',
title: '',
content_type: ContentType.TYPES.Note,
} as jest.Mocked<SNNote>
expect(getItemTitleInContextOfLinkBubble(item as DecryptedItemInterface<ItemContent>)).toBe('Note Preview')
})

it('returns empty string if title is empty and item is not a note', () => {
const item = { title: '', content_type: ContentType.TYPES.Tag } as jest.Mocked<SNNote>
expect(getItemTitleInContextOfLinkBubble(item as DecryptedItemInterface<ItemContent>)).toBe('')
})
})

describe('doesItemMatchSearchQuery', () => {
const application = {} as WebApplicationInterface

it('returns false for a protected note even if the title matches the search query', () => {
const item = {
title: '',
preview_plain: 'Protected Note Content',
protected: true,
archived: false,
trashed: false,
content_type: ContentType.TYPES.Note,
} as jest.Mocked<SNNote>
expect(
doesItemMatchSearchQuery(item as DecryptedItemInterface<ItemContent>, 'protected note content', application),
).toBeFalsy()
})

it('returns true if the item title matches the search query', () => {
const item = { title: 'Matched Item', archived: false, trashed: false }
expect(doesItemMatchSearchQuery(item as DecryptedItemInterface<ItemContent>, 'matched', application)).toBeTruthy()
})

it('returns false if the item is archived', () => {
const item = { title: 'Archived Item', archived: true, trashed: false }
expect(doesItemMatchSearchQuery(item as DecryptedItemInterface<ItemContent>, 'archived', application)).toBeFalsy()
})

it('returns false if the item is trashed', () => {
const item = { title: 'Trashed Item', archived: false, trashed: true }
expect(doesItemMatchSearchQuery(item as DecryptedItemInterface<ItemContent>, 'trashed', application)).toBeFalsy()
})
})
Expand Up @@ -7,7 +7,11 @@ export function getItemTitleInContextOfLinkBubble(item: DecryptedItemInterface<I

function getItemSearchableString(item: DecryptedItemInterface<ItemContent>, application: WebApplicationInterface) {
if (isNote(item)) {
return item.title.length > 0 ? item.title : item.preview_plain
if (item.title.length > 0) {
return item.title
} else if (!item.protected) {
return item.preview_plain
}
} else if (isTag(item)) {
return application.items.getTagLongTitle(item)
}
Expand Down