Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pzdr7 committed Oct 20, 2024
1 parent fd0e919 commit dfaf51c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, OnChanges, OnInit, computed, inject, input, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnChanges, OnInit, inject, input, signal } from '@angular/core';
import { LinkPreview, LinkPreviewService } from 'app/shared/link-preview/services/link-preview.service';
import { Link, LinkifyService } from 'app/shared/link-preview/services/linkify.service';
import { User } from 'app/core/user/user.model';
Expand All @@ -20,7 +20,6 @@ export class LinkPreviewContainerComponent implements OnInit, OnChanges {
readonly isEdited = input<boolean>();
readonly isReply = input<boolean>();

readonly dataSafe = computed<string>(() => this.data() ?? '');
readonly linkPreviews = signal<LinkPreview[]>([]);
readonly hasError = signal<boolean>(false);
readonly loaded = signal<boolean>(false);
Expand All @@ -43,7 +42,7 @@ export class LinkPreviewContainerComponent implements OnInit, OnChanges {
}

private findPreviews() {
const links: Link[] = this.linkifyService.find(this.dataSafe());
const links: Link[] = this.linkifyService.find(this.data() ?? '');
// TODO: The limit of 5 link previews should be configurable (maybe in course level)
links
.filter((link) => !link.isLinkPreviewRemoved)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('LinkPreviewContainerComponent', () => {

component.ngOnInit();

expect(linkifyServiceSpy).toHaveBeenCalledWith(component.dataSafe());
expect(linkifyServiceSpy).toHaveBeenCalledWith(component.data());
expect(linkPreviewServiceSpy).toHaveBeenCalledTimes(2);
expect(linkPreviewServiceSpy).toHaveBeenCalledWith('https://example.com/link1');
expect(linkPreviewServiceSpy).toHaveBeenCalledWith('https://example.com/link2');
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('LinkPreviewContainerComponent', () => {

component.ngOnInit();

expect(linkifyServiceSpy).toHaveBeenCalledWith(component.dataSafe());
expect(linkifyServiceSpy).toHaveBeenCalledWith(component.data());
expect(linkPreviewServiceSpy).toHaveBeenCalledOnce();
expect(linkPreviewServiceSpy).toHaveBeenCalledWith('https://example.com/link1');
expect(component.linkPreviews()).toHaveLength(1);
Expand Down

0 comments on commit dfaf51c

Please sign in to comment.