Skip to content

Commit

Permalink
Fix tests #2
Browse files Browse the repository at this point in the history
  • Loading branch information
denysvitali committed May 15, 2019
2 parents e2f7d98 + 3707d82 commit 94d2793
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
18 changes: 2 additions & 16 deletions src/app/shared/components/tag/tag.component.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TagComponent } from "./tag.component";
import { ElementRef } from "@angular/core";


test("setContent", () => {
let tag : TagComponent = new TagComponent();
let tag : TagComponent = new TagComponent(null);
let content = document.createElement("p");
tag.content = new ElementRef(document.createElement("div"));
content.innerHTML = "test node";
Expand All @@ -13,17 +12,4 @@ test("setContent", () => {
content.innerHTML = "test 2";
expect(natEl.children[0]).toBe(content);
expect(natEl.children[0].innerHTML).toBe(content.innerHTML);
});

/*
test("setType", () => {
let tag : TagComponent = new TagComponent();
let inner = document.createElement("p");
tag.tag = new ElementRef(document.createElement("div"));
let natEl : HTMLElement = tag.tag.nativeElement;
tag.setType(1);
expect(natEl.style.backgroundColor).toBe("rgb(216, 27, 96)"); // #D81B60 Hex -> 216, 27, 96 RGB
tag.setType(2);
expect(natEl.style.backgroundColor).toBe("rgb(251, 140, 0)"); // #FB8C00 Hex -> 251, 140, 0 RGB
});
*/
});
6 changes: 4 additions & 2 deletions src/app/shared/components/tag/tag.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HSLColor } from "Models/hslcolor/HSLColor";
import { ColorizedNode } from "Models/tree/ColorizedTree";
import { CustomTextareaComponent } from "Components/textedit/components/customtextarea.component";
import { Document } from "Models/document/document";
import { DocumentService } from "Services/document/DocumentService";

@Component({
selector: "doctt-tag",
Expand All @@ -19,7 +20,7 @@ export class TagComponent implements OnInit {
@ViewChild("tag") tag: ElementRef | undefined;
@ViewChild("tagInner") content: ElementRef | undefined;

constructor() { }
constructor(private documentService : DocumentService) { }

ngOnInit(): void { }

Expand Down Expand Up @@ -75,7 +76,8 @@ export class TagComponent implements OnInit {
}

let id = Number.parseInt(spanContainer.getAttribute("data-segment-id"));
CustomTextareaComponent.removeFeaturesBySegmentId(this.document, id);
//CustomTextareaComponent.removeFeaturesBySegmentId(this.document, id);
CustomTextareaComponent.removeFeaturesFromSegmentID(id, this.documentService, this.document);

if(father != null){
father.insertBefore(docFragment, spanContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,36 @@ export class CustomTextareaComponent implements OnInit {
return true;
}

public static removeFeaturesFromSegmentID(id : number, documentService : DocumentService, document : Document){
let docs : Document[] = documentService.loadDocuments();
document.body.segments = this.recursiveFeatuersRemoval(document.body.segments, id);
docs[document.header.id] = document;
documentService.storeDocuments(docs);
}

private static recursiveFeatuersRemoval(segments : Segment[], id : number) : Segment[]{
if(segments.length == 0){
return [];
}

for(let s of segments){
if(s.id == id){
s.features = [];
return segments;
}
if(s.children != null && s.children != []){
s.children = this.recursiveFeatuersRemoval(s.children, id);
}
}
return segments;
}
/*
public static removeFeaturesBySegmentId(document: Document, id: number){
let s = this.findSegmentById(document.body.segments, id);
s.features = [];
this.replaceSegmentInDocument(document, s, id);
}

*/
private static findSegmentById(segments: Segment[], id : number) : Segment {
if(segments.length == 0){
return null;
Expand Down Expand Up @@ -593,7 +617,7 @@ export class CustomTextareaComponent implements OnInit {
let tag = this.findTagByFeatures(ct, s.features);

if (tag == null) {
console.error("Invalid tag!");
console.info("Features null!");
content.setAttribute("data-segment-id", s.id.toString());
el.appendChild(content);
return;
Expand All @@ -604,6 +628,7 @@ export class CustomTextareaComponent implements OnInit {
let element: ComponentRef<TagComponent> = ref;
element.instance.setContent(content);
element.instance.setTag(tag);
element.instance.setDocument(this.document);

el.appendChild(divSegment);
}
Expand Down

0 comments on commit 94d2793

Please sign in to comment.