Skip to content

Commit

Permalink
adds dedup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Nov 9, 2023
1 parent a91ebad commit e6d43c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ describe('helpers', () => {
expect(getNumOfCoveredSubtechniques(payload)).toEqual(0);
});

it('returns total number of enabled and disabled subtechniques when no filter is passed', () => {
it('returns total number of unique enabled and disabled subtechniques when no filter is passed', () => {
const payload = {
...getMockCoverageOverviewMitreTechnique(),
subtechniques: [
getMockCoverageOverviewMitreSubTechnique(),
getMockCoverageOverviewMitreSubTechnique(),
{ ...getMockCoverageOverviewMitreSubTechnique(), id: 'test-id' },
],
};
expect(getNumOfCoveredSubtechniques(payload)).toEqual(4);
expect(getNumOfCoveredSubtechniques(payload)).toEqual(2);
});

it('returns total number of enabled and disabled subtechniques when both filters are passed', () => {
it('returns total number of unique enabled and disabled subtechniques when both filters are passed', () => {
const payload = {
...getMockCoverageOverviewMitreTechnique(),
subtechniques: [
getMockCoverageOverviewMitreSubTechnique(),
getMockCoverageOverviewMitreSubTechnique(),
{ ...getMockCoverageOverviewMitreSubTechnique(), id: 'test-id' },
],
};
expect(
getNumOfCoveredSubtechniques(payload, [
CoverageOverviewRuleActivity.Enabled,
CoverageOverviewRuleActivity.Disabled,
])
).toEqual(4);
).toEqual(2);
});

it('returns total number of enabled subtechniques when enabled filter is passed', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@ export const getNumOfCoveredSubtechniques = (
technique: CoverageOverviewMitreTechnique,
activity?: CoverageOverviewRuleActivity[]
): number => {
let coveredSubtechniqueCount = 0;
if (activity === undefined) {
return (
technique.subtechniques.filter((subtechnique) => subtechnique.enabledRules.length !== 0)
.length +
technique.subtechniques.filter((subtechnique) => subtechnique.disabledRules.length !== 0)
.length
);
}
if (activity.includes(CoverageOverviewRuleActivity.Enabled)) {
coveredSubtechniqueCount += technique.subtechniques.filter(
(subtechnique) => subtechnique.enabledRules.length !== 0
).length;
const coveredSubtechniques = new Set();
if (!activity || activity.includes(CoverageOverviewRuleActivity.Enabled)) {
for (const subtechnique of technique.subtechniques) {
if (subtechnique.enabledRules.length) {
coveredSubtechniques.add(subtechnique.id);
}
}
}
if (activity.includes(CoverageOverviewRuleActivity.Disabled)) {
coveredSubtechniqueCount += technique.subtechniques.filter(
(subtechnique) => subtechnique.disabledRules.length !== 0
).length;

if (!activity || activity.includes(CoverageOverviewRuleActivity.Disabled)) {
for (const subtechnique of technique.subtechniques) {
if (subtechnique.disabledRules.length) {
coveredSubtechniques.add(subtechnique.id);
}
}
}
return coveredSubtechniqueCount;
return coveredSubtechniques.size;
};

export const getCardBackgroundColor = (value: number) => {
Expand Down

0 comments on commit e6d43c0

Please sign in to comment.