All files / app/codeCharta/state/effects/addBlacklistItemsIfNotResultsInEmptyMap resultsInEmptyMap.ts

93.75% Statements 15/16
100% Branches 5/5
100% Functions 3/3
93.33% Lines 14/15

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 25 26 27 28 29 30 315x     5x   5x         2x 2x 1x 1x     1x     5x 1x 5x 1x           5x 5x  
import { hierarchy, HierarchyNode } from "d3-hierarchy"
import { BlacklistItem, CCFile, CodeMapNode } from "../../../codeCharta.model"
import { FileState } from "../../../model/files/files"
import { isLeaf, isPathBlacklisted } from "../../../util/codeMapHelper"
 
export const resultsInEmptyMap = (
    visibleFiles: FileState[],
    currentBlacklist: BlacklistItem[],
    itemsToBeBlackListened: BlacklistItem[]
) => {
    const newBlacklist = [...currentBlacklist, ...itemsToBeBlackListened]
    for (const { file } of visibleFiles) {
        if (!resultsInEmptyFile(file, newBlacklist)) {
            return false
        }
    }
    return true
}
 
const resultsInEmptyFile = (file: CCFile, blacklist: BlacklistItem[]) => {
    for (const node of hierarchy(file.map)) {
        if (isNodeIncluded(node, blacklist)) {
            return false
        }
    }
    return true
}
 
const isNodeIncluded = (node: HierarchyNode<CodeMapNode>, blacklist: Array<BlacklistItem>) =>
    isLeaf(node) && node.data.path && !isPathBlacklisted(node.data.path, blacklist, "exclude")