diff --git a/scilog/src/app/logbook/widgets/logbook-item/logbook-item.component.spec.ts b/scilog/src/app/logbook/widgets/logbook-item/logbook-item.component.spec.ts index 91241e2e..b5dec81f 100644 --- a/scilog/src/app/logbook/widgets/logbook-item/logbook-item.component.spec.ts +++ b/scilog/src/app/logbook/widgets/logbook-item/logbook-item.component.spec.ts @@ -265,17 +265,7 @@ describe('LogbookItemComponent', () => { component.parseNotification(notificationMock[0]); expect(component["logbookScrollService"].updateViewportEstimate).toHaveBeenCalledTimes(1); }) - // it('should remove snippet if notification has _delete_ tag', ()=>{ - // component.dash - // component.datasource = new DatasourceMock(); - // spyOn(component.datasource.adapter, 'check'); - // let notificationMock:ChangeStreamNotification[] = [ - // {id: "123", operationType: "update", content: {id: "123", parentId:"wrongID", snippetType: "image", tags:["_delete_123"], linkType:"quote"}} - // ]; - // component.parseNotification(notificationMock[0]); - // expect(component.datasource.adapter.check).toHaveBeenCalledTimes(1); - - // }) + it('should parse new paragraph insert notification', () => { spyOn(component["logbookScrollService"], "appendToEOF"); let notificationMock: ChangeStreamNotification[] = [ @@ -514,14 +504,32 @@ describe('LogbookItemComponent', () => { it('Should remove from index', () => { component.isDescending = true; expect(component["_indexOrder"](2)).toEqual(8); - }) + }); - it('should delete logbook and update logbook count', () => { - spyOn(component["logbookScrollService"], "remove"); - let notificationMock: ChangeStreamNotification = { operationType: "update", content: { deleted: true } }; - component.parseNotification(notificationMock); - expect(component.logbookCount).toEqual(9); - expect(component["logbookScrollService"].remove).toHaveBeenCalled(); + [ + {input: [{ deleted: true }], expected: 1}, + {input: [{ tags: [] }, {tags: ['a']}], expected: 1}, + {input: [{ tags: ['a'] }, {tags: ['a']}], expected: 0}, + {input: [{ tags: ['a', 'b'] }, {tags: ['a']}], expected: 0}, + {input: [{ tags: ['a'] }, {tags: ['a', 'b']}], expected: 0}, + {input: [{ tags: [] }, {tags: []}], expected: 0}, + {input: [{ tags: ['c'] }, {excludeTags: ['c']}], expected: 1}, + {input: [{ tags: ['c'] }, {excludeTags: ['c', 'd']}], expected: 1}, + {input: [{ tags: ['c'] }, {excludeTags: ['d']}], expected: 0}, + {input: [{ tags: ['c', 'd'] }, {excludeTags: ['d']}], expected: 1}, + ].forEach((t, i) => { + it(`should delete logbook and update logbook count: ${i}`, () => { + spyOn(component["logbookScrollService"], "remove"); + let originalFilter = JSON.parse(JSON.stringify(component.config.filter)) + let notificationMock: ChangeStreamNotification = { operationType: "update", content: t.input[0] }; + if (t.input[1]) + component.config.filter = {...originalFilter, ...t.input[1]}; + component.parseNotification(notificationMock); + expect(component["logbookScrollService"].remove).toHaveBeenCalledTimes(t.expected); + if (t.expected > 0) + expect(component.logbookCount).toEqual(9); + component.config.filter = originalFilter; + }) }) it('should prepare POST edit message', () => { diff --git a/scilog/src/app/logbook/widgets/logbook-item/logbook-item.component.ts b/scilog/src/app/logbook/widgets/logbook-item/logbook-item.component.ts index 106eadff..29431d2a 100644 --- a/scilog/src/app/logbook/widgets/logbook-item/logbook-item.component.ts +++ b/scilog/src/app/logbook/widgets/logbook-item/logbook-item.component.ts @@ -299,7 +299,12 @@ export class LogbookItemComponent implements OnInit { console.log(subPos); } // deleting elements is communicated by special tags. If they are present, delete the element - if (notification.content.deleted) { + if ( + notification.content.deleted || + (this.config.filter?.tags?.length > 0 && + !this.config.filter.tags.some((tag: string) => notification.content.tags?.includes(tag))) || + this.config.filter.excludeTags?.some((tag: string) => notification.content.tags?.includes(tag)) + ) { if (isSubsnippet && subPos.length == 2) { // subsnippets don't have a viewport index so we can / have to update the childSnippet directly. // However, afterwards we need to make sure that viewport's height is updated