internal: incomplete vault systems behind feature flag (#2340)
This commit is contained in:
@@ -9,7 +9,11 @@ import {
|
||||
FileToNoteReference,
|
||||
InternalEventBus,
|
||||
SNNote,
|
||||
ItemsClientInterface,
|
||||
ItemManagerInterface,
|
||||
VaultListingInterface,
|
||||
ItemInterface,
|
||||
InternalFeatureService,
|
||||
InternalFeature,
|
||||
} from '@standardnotes/snjs'
|
||||
import { FilesController } from './FilesController'
|
||||
import { ItemListController } from './ItemList/ItemListController'
|
||||
@@ -53,12 +57,20 @@ describe('LinkingController', () => {
|
||||
let subscriptionController: SubscriptionController
|
||||
|
||||
beforeEach(() => {
|
||||
application = {} as jest.Mocked<WebApplication>
|
||||
application = {
|
||||
vaults: {} as jest.Mocked<WebApplication['vaults']>,
|
||||
alerts: {} as jest.Mocked<WebApplication['alerts']>,
|
||||
sync: {} as jest.Mocked<WebApplication['sync']>,
|
||||
mutator: {} as jest.Mocked<WebApplication['mutator']>,
|
||||
} as unknown as jest.Mocked<WebApplication>
|
||||
|
||||
application.getPreference = jest.fn()
|
||||
application.addSingleEventObserver = jest.fn()
|
||||
application.streamItems = jest.fn()
|
||||
application.itemControllerGroup = {} as jest.Mocked<WebApplication['itemControllerGroup']>
|
||||
application.sync.sync = jest.fn()
|
||||
|
||||
Object.defineProperty(application, 'items', { value: {} as jest.Mocked<ItemsClientInterface> })
|
||||
Object.defineProperty(application, 'items', { value: {} as jest.Mocked<ItemManagerInterface> })
|
||||
|
||||
navigationController = {} as jest.Mocked<NavigationController>
|
||||
|
||||
@@ -181,38 +193,73 @@ describe('LinkingController', () => {
|
||||
})
|
||||
|
||||
it('should be true if active item & result are different content type & active item references result', () => {
|
||||
const activeFile = createNote('test', {
|
||||
uuid: 'active-file',
|
||||
const activeNote = createNote('test', {
|
||||
uuid: 'active-note',
|
||||
references: [
|
||||
{
|
||||
reference_type: ContentReferenceType.FileToNote,
|
||||
uuid: 'note-result',
|
||||
uuid: 'file-result',
|
||||
} as FileToNoteReference,
|
||||
],
|
||||
})
|
||||
|
||||
const noteResult = createFile('test', {
|
||||
uuid: 'note-result',
|
||||
const fileResult = createFile('test', {
|
||||
uuid: 'file-result',
|
||||
references: [],
|
||||
})
|
||||
|
||||
const isNoteResultAlreadyLinked = isSearchResultAlreadyLinkedToItem(noteResult, activeFile)
|
||||
const isNoteResultAlreadyLinked = isSearchResultAlreadyLinkedToItem(fileResult, activeNote)
|
||||
expect(isNoteResultAlreadyLinked).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should be false if active item & result are different content type & neither references the other', () => {
|
||||
const activeFile = createNote('test', {
|
||||
const activeNote = createNote('test', {
|
||||
uuid: 'active-file',
|
||||
references: [],
|
||||
})
|
||||
|
||||
const noteResult = createFile('test', {
|
||||
const fileResult = createFile('test', {
|
||||
uuid: 'note-result',
|
||||
references: [],
|
||||
})
|
||||
|
||||
const isNoteResultAlreadyLinked = isSearchResultAlreadyLinkedToItem(noteResult, activeFile)
|
||||
const isNoteResultAlreadyLinked = isSearchResultAlreadyLinkedToItem(fileResult, activeNote)
|
||||
expect(isNoteResultAlreadyLinked).toBeFalsy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('linkItems', () => {
|
||||
it('should move file to same vault as note if file does not belong to any vault', async () => {
|
||||
InternalFeatureService.get().enableFeature(InternalFeature.Vaults)
|
||||
|
||||
application.mutator.associateFileWithNote = jest.fn().mockReturnValue({})
|
||||
|
||||
const moveToVaultSpy = (application.vaults.moveItemToVault = jest.fn())
|
||||
|
||||
const note = createNote('test', {
|
||||
uuid: 'note',
|
||||
references: [],
|
||||
})
|
||||
|
||||
const file = createFile('test', {
|
||||
uuid: 'file',
|
||||
references: [],
|
||||
})
|
||||
|
||||
const noteVault = {
|
||||
uuid: 'note-vault',
|
||||
} as jest.Mocked<VaultListingInterface>
|
||||
|
||||
application.vaults.getItemVault = jest.fn().mockImplementation((item: ItemInterface) => {
|
||||
if (item.uuid === note.uuid) {
|
||||
return noteVault
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
|
||||
await linkingController.linkItems(note, file)
|
||||
|
||||
expect(moveToVaultSpy).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user