mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
Unit tests for to-electron-background-color (#1409)
* add initial unit tests for to-electron-background-color * extract isHexFile to test/testUtils
This commit is contained in:
parent
78709d93cf
commit
67d6963296
3 changed files with 59 additions and 0 deletions
|
|
@ -7,6 +7,8 @@
|
|||
"build": "cross-env NODE_ENV=production webpack",
|
||||
"lint": "xo",
|
||||
"test": "npm run lint",
|
||||
"test:unit": "ava test/unit",
|
||||
"test:unit:watch": "npm run test:unit -- --watch",
|
||||
"prepush": "npm test",
|
||||
"postinstall": "install-app-deps && npm run rebuild-node-pty",
|
||||
"rebuild-node-pty": "electron-rebuild -f -w app/node_modules/node-pty -m app",
|
||||
|
|
|
|||
5
test/testUtils/is-hex-color.js
Normal file
5
test/testUtils/is-hex-color.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function isHexColor(color) {
|
||||
return /(^#[0-9A-F]{6,8}$)|(^#[0-9A-F]{3}$)/i.test(color); // https://regex101.com/
|
||||
}
|
||||
|
||||
module.exports.isHexColor = isHexColor;
|
||||
52
test/unit/to-electron-background-color.test.js
Normal file
52
test/unit/to-electron-background-color.test.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import test from 'ava';
|
||||
import toElectronBackgroundColor from '../../app/utils/to-electron-background-color';
|
||||
import {isHexColor} from '../testUtils/is-hex-color';
|
||||
|
||||
test('toElectronBackgroundColor', t => {
|
||||
t.false(false);
|
||||
});
|
||||
|
||||
test(`returns a color that's in hex`, t => {
|
||||
const hexColor = '#BADA55';
|
||||
const rgbColor = 'rgb(0,0,0)';
|
||||
const rgbaColor = 'rgb(0,0,0, 55)';
|
||||
const hslColor = 'hsl(15, 100%, 50%)';
|
||||
const hslaColor = 'hsl(15, 100%, 50%, 1)';
|
||||
const colorKeyword = 'pink';
|
||||
|
||||
t.true(
|
||||
isHexColor(
|
||||
toElectronBackgroundColor(hexColor)
|
||||
)
|
||||
);
|
||||
|
||||
t.true(
|
||||
isHexColor(
|
||||
toElectronBackgroundColor(rgbColor)
|
||||
)
|
||||
);
|
||||
|
||||
t.true(
|
||||
isHexColor(
|
||||
toElectronBackgroundColor(rgbaColor)
|
||||
)
|
||||
);
|
||||
|
||||
t.true(
|
||||
isHexColor(
|
||||
toElectronBackgroundColor(hslColor)
|
||||
)
|
||||
);
|
||||
|
||||
t.true(
|
||||
isHexColor(
|
||||
toElectronBackgroundColor(hslaColor)
|
||||
)
|
||||
);
|
||||
|
||||
t.true(
|
||||
isHexColor(
|
||||
toElectronBackgroundColor(colorKeyword)
|
||||
)
|
||||
);
|
||||
});
|
||||
Loading…
Reference in a new issue