All files / app/codeCharta/state/store/fileSettings/markedPackages/util addMarkedPackage.ts

92.85% Statements 13/14
80% Branches 8/10
100% Functions 1/1
92.3% Lines 12/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 25 26 27 28  44x   44x 12x   12x 12x           12x 25x 12x     13x   6x 6x 2x          
import { MarkedPackage } from "../../../../../codeCharta.model"
import { getParent } from "../../../../../util/nodePathHelper"
 
export const addMarkedPackage = (markedPackagesMap: Map<string, MarkedPackage>, { path, color }: MarkedPackage) => {
    const directMarkedParentPackage = getParent(markedPackagesMap, path)
 
    if (!directMarkedParentPackage || directMarkedParentPackage.color !== color) {
        markedPackagesMap.set(path, {
            path,
            color
        })
    }
 
    for (const [key, markedPackage] of markedPackagesMap) {
        if (markedPackage.path === path) {
            Iif (markedPackage.color !== color) {
                markedPackagesMap.delete(key)
            }
        } else if (markedPackage.path.startsWith(path)) {
            // Remove marked packages with color identical to their parent marked package
            const markedPackageParent = getParent(markedPackagesMap, markedPackage.path)
            if (markedPackageParent && markedPackageParent.color === markedPackage.color) {
                markedPackagesMap.delete(key)
            }
        }
    }
}