-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract mapTreeViewLevelItemIcon.component
refs #2318
- Loading branch information
1 parent
e233102
commit 22ca325
Showing
11 changed files
with
120 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...odeCharta/ui/mapTreeView/mapTreeViewLevelItemIcon/mapTreeViewLevelItemIcon.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<span | ||
role="img" | ||
[class]="node | mapTreeViewLevelItemIconClass: isFolderOpen" | ||
[style.color]="node | mapTreeViewLevelItemIconColor" | ||
aria-hidden="true" | ||
></span> |
11 changes: 11 additions & 0 deletions
11
.../codeCharta/ui/mapTreeView/mapTreeViewLevelItemIcon/mapTreeViewLevelItemIcon.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Component, Input } from "@angular/core" | ||
import { CodeMapNode } from "../../../codeCharta.model" | ||
|
||
@Component({ | ||
selector: "cc-map-tree-view-level-item-icon", | ||
template: require("./mapTreeViewLevelItemIcon.component.html") | ||
}) | ||
export class MapTreeViewLevelItemIcon { | ||
@Input() node: CodeMapNode | ||
@Input() isFolderOpen: boolean | ||
} |
19 changes: 19 additions & 0 deletions
19
...Charta/ui/mapTreeView/mapTreeViewLevelItemIcon/mapTreeViewLevelItemIconClass.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { CodeMapNode } from "../../../codeCharta.model" | ||
import { MapTreeViewLevelItemIconClassPipe } from "./mapTreeViewLevelItemIconClass.pipe" | ||
|
||
describe("MapTreeViewLevelItemIconClassPipe", () => { | ||
it("should return 'fa fa-file-o' for leaf nodes", () => { | ||
const fakeNode = {} as unknown as CodeMapNode | ||
expect(new MapTreeViewLevelItemIconClassPipe().transform(fakeNode, true)).toBe("fa fa-file-o") | ||
}) | ||
|
||
it("should return 'fa fa-folder-open' for open folders", () => { | ||
const fakeNode = { children: [{}] } as unknown as CodeMapNode | ||
expect(new MapTreeViewLevelItemIconClassPipe().transform(fakeNode, true)).toBe("fa fa-folder-open") | ||
}) | ||
|
||
it("should return 'fa fa-folder' for closed folders", () => { | ||
const fakeNode = { children: [{}] } as unknown as CodeMapNode | ||
expect(new MapTreeViewLevelItemIconClassPipe().transform(fakeNode, false)).toBe("fa fa-folder") | ||
}) | ||
}) |
13 changes: 13 additions & 0 deletions
13
.../codeCharta/ui/mapTreeView/mapTreeViewLevelItemIcon/mapTreeViewLevelItemIconClass.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Pipe, PipeTransform } from "@angular/core" | ||
|
||
import { CodeMapNode } from "../../../codeCharta.model" | ||
import { isLeaf } from "../../../util/codeMapHelper" | ||
|
||
@Pipe({ name: "mapTreeViewLevelItemIconClass" }) | ||
export class MapTreeViewLevelItemIconClassPipe implements PipeTransform { | ||
transform(value: CodeMapNode, isOpen: boolean): string { | ||
if (isLeaf(value)) return "fa fa-file-o" | ||
if (isOpen) return "fa fa-folder-open" | ||
return "fa fa-folder" | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...Charta/ui/mapTreeView/mapTreeViewLevelItemIcon/mapTreeViewLevelItemIconColor.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { CodeMapNode } from "../../../codeCharta.model" | ||
import { Store } from "../../../state/store/store" | ||
import * as codeMapHelper from "../../../util/codeMapHelper" | ||
import { MapTreeViewLevelItemIconColorPipe } from "./mapTreeViewLevelItemIconColor.pipe" | ||
|
||
describe("MapTreeViewLevelItemIconColorPipe", () => { | ||
beforeEach(() => { | ||
Store["initialize"]() | ||
}) | ||
|
||
it("should return undefined for leaf nodes", () => { | ||
const fakeNode = {} as unknown as CodeMapNode | ||
expect(new MapTreeViewLevelItemIconColorPipe().transform(fakeNode)).toBe(undefined) | ||
}) | ||
|
||
it("should return default color if getMarkingColor returns undefined", () => { | ||
const fakeNode = { children: [{}] } as unknown as CodeMapNode | ||
jest.spyOn(codeMapHelper, "getMarkingColor").mockImplementation(() => {}) | ||
expect(new MapTreeViewLevelItemIconColorPipe().transform(fakeNode)).toBe(MapTreeViewLevelItemIconColorPipe.defaultColor) | ||
}) | ||
|
||
it("should return color of getMarkingColor", () => { | ||
const fakeNode = { children: [{}] } as unknown as CodeMapNode | ||
jest.spyOn(codeMapHelper, "getMarkingColor").mockImplementation(() => "#123456") | ||
expect(new MapTreeViewLevelItemIconColorPipe().transform(fakeNode)).toBe("#123456") | ||
}) | ||
}) |
17 changes: 17 additions & 0 deletions
17
.../codeCharta/ui/mapTreeView/mapTreeViewLevelItemIcon/mapTreeViewLevelItemIconColor.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Pipe, PipeTransform } from "@angular/core" | ||
|
||
import { CodeMapNode } from "../../../codeCharta.model" | ||
import { Store } from "../../../state/store/store" | ||
import { getMarkingColor, isLeaf } from "../../../util/codeMapHelper" | ||
|
||
@Pipe({ name: "mapTreeViewLevelItemIconColor" }) | ||
export class MapTreeViewLevelItemIconColorPipe implements PipeTransform { | ||
static defaultColor = "#000000" | ||
static store = Store.store | ||
|
||
transform(value: CodeMapNode): string | undefined { | ||
if (isLeaf(value)) return undefined | ||
const markingColor = getMarkingColor(value, MapTreeViewLevelItemIconColorPipe.store.getState().fileSettings.markedPackages) | ||
return markingColor ? markingColor : MapTreeViewLevelItemIconColorPipe.defaultColor | ||
} | ||
} |