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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
packages/web/src/javascripts/Utils/Items/Search/doesItemMatchSearchQuery.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note