All files / app/codeCharta/ui/copyToClipboardButton copyToClipboard.service.ts

85.71% Statements 12/14
100% Branches 0/0
66.66% Functions 2/3
84.61% Lines 11/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 254x 4x   4x 4x 4x     4x 3x     1x 1x 1x   1x                
import { Injectable } from "@angular/core"
import { State } from "@ngrx/store"
import { CcState } from "../../codeCharta.model"
import { accumulatedDataSelector } from "../../state/selectors/accumulatedData/accumulatedData.selector"
import { buildTextOfFiles } from "./util/clipboardString"
import { getFilenamesWithHighestMetrics } from "./util/getFilenamesWithHighestMetrics"
 
@Injectable({ providedIn: "root" })
export class CopyToClipboardService {
    constructor(private state: State<CcState>) {}
 
    getClipboardText(): string {
        const node = this.getUnifiedMapNode()
        const attributeDescriptors = this.state.getValue().fileSettings.attributeDescriptors
        const filesByAttribute = getFilenamesWithHighestMetrics(node, attributeDescriptors)
 
        return buildTextOfFiles(filesByAttribute)
    }
 
    private getUnifiedMapNode() {
        const { unifiedMapNode } = accumulatedDataSelector(this.state.getValue())
        return unifiedMapNode
    }
}