Skip to content

Commit

Permalink
Remove snippets from viewport on tag removal
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Aug 29, 2024
1 parent c887952 commit 5beefc2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5beefc2

Please sign in to comment.