forked from NodeSecure/vis-network
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add ut for utils (NodeSecure#16)
- Loading branch information
1 parent
aad66ad
commit 3a4f40c
Showing
2 changed files
with
71 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import tap from "tap"; | ||
import { getFlagsEmojisInlined, getJSON, getNodeColor } from "../src/utils.js"; | ||
import * as CONSTANTS from "../src/constants.js"; | ||
|
||
const response = { message: "test should works" }; | ||
global.fetch = () => Promise.resolve({ json: () => response }); | ||
const json = await getJSON("random"); | ||
|
||
tap.equal(json, response, "getJSON should works"); | ||
|
||
const FLAGS = [ | ||
{ | ||
emoji: "π", | ||
title: "hasExternalCapacity", | ||
}, | ||
{ | ||
emoji: "π§", | ||
title: "hasWarnings", | ||
}, | ||
{ | ||
emoji: "π²", | ||
title: "hasNativeCode", | ||
}, | ||
]; | ||
|
||
const titles = FLAGS.map((flag) => flag.title); | ||
|
||
tap.equal( | ||
getFlagsEmojisInlined(titles, new Set()), | ||
" π π§ π²", | ||
"getFlagsEmojisInlined without flag to ignore" | ||
); | ||
|
||
tap.equal( | ||
getFlagsEmojisInlined(titles, new Set(["hasWarnings"])), | ||
" π π²", | ||
"getFlagsEmojisInlined with flag to ignore" | ||
); | ||
|
||
tap.equal( | ||
getNodeColor(0), | ||
CONSTANTS.COLORS["LIGHT"].SELECTED, | ||
"id 0 is the root package (so by default he is highlighted as selected)." | ||
); | ||
|
||
tap.equal( | ||
getNodeColor(1, true), | ||
CONSTANTS.COLORS["LIGHT"].WARN, | ||
"hasWarnings is true, so the node is highlighted as warning." | ||
); | ||
|
||
tap.equal( | ||
getNodeColor(1, false), | ||
CONSTANTS.COLORS["LIGHT"].DEFAULT, | ||
"the node is highlighted as default." | ||
); | ||
|
||
tap.equal( | ||
getNodeColor(1, false, "DARK"), | ||
CONSTANTS.COLORS["DARK"].DEFAULT, | ||
"the node is highlighted as default and the theme is DARK." | ||
); |