mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
test: coverage
This commit is contained in:
parent
e4ff4a78cc
commit
943bdecd3e
6 changed files with 271 additions and 5 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import {test} from 'supertape';
|
||||
import {convert} from './input.js';
|
||||
import {test, stub} from 'supertape';
|
||||
import {convert, getName, getValue, setValue} from './input.js';
|
||||
|
||||
test('cloudcmd: client: config: input: convert', (t) => {
|
||||
const result = convert({
|
||||
|
|
@ -13,3 +13,106 @@ test('cloudcmd: client: config: input: convert', (t) => {
|
|||
t.deepEqual(result, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: config: input: convert: bool', (t) => {
|
||||
const result = convert({
|
||||
auth: true,
|
||||
});
|
||||
|
||||
const expected = {
|
||||
auth: ' checked',
|
||||
};
|
||||
|
||||
t.deepEqual(result, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: config: input: convert: bool false', (t) => {
|
||||
const result = convert({
|
||||
auth: false,
|
||||
});
|
||||
|
||||
const expected = {
|
||||
auth: '',
|
||||
};
|
||||
|
||||
t.deepEqual(result, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: config: input: getName', (t) => {
|
||||
const getAttribute = stub().returns('js-hello');
|
||||
const element = {getAttribute};
|
||||
|
||||
const result = getName(element);
|
||||
|
||||
t.equal(result, 'hello', 'should strip js- prefix');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: config: input: getValue: checkbox', (t) => {
|
||||
const querySelector = stub().returns({
|
||||
type: 'checkbox',
|
||||
checked: true,
|
||||
});
|
||||
const element = {querySelector};
|
||||
|
||||
const result = getValue('auth', element);
|
||||
|
||||
t.ok(result, 'should return checked value');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: config: input: getValue: number', (t) => {
|
||||
const querySelector = stub().returns({
|
||||
type: 'number',
|
||||
value: '42',
|
||||
});
|
||||
const element = {querySelector};
|
||||
|
||||
const result = getValue('port', element);
|
||||
|
||||
t.equal(result, 42, 'should return number');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: config: input: getValue: default', (t) => {
|
||||
const querySelector = stub().returns({
|
||||
type: 'text',
|
||||
value: 'hello',
|
||||
});
|
||||
const element = {querySelector};
|
||||
|
||||
const result = getValue('name', element);
|
||||
|
||||
t.equal(result, 'hello', 'should return value as is');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: config: input: setValue: checkbox', (t) => {
|
||||
const el = {
|
||||
type: 'checkbox',
|
||||
checked: false,
|
||||
};
|
||||
const querySelector = stub().returns(el);
|
||||
const element = {querySelector};
|
||||
|
||||
setValue('auth', true, element);
|
||||
|
||||
t.ok(el.checked, 'should set checked');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: config: input: setValue: default', (t) => {
|
||||
const el = {
|
||||
type: 'text',
|
||||
value: 'old',
|
||||
};
|
||||
const querySelector = stub().returns(el);
|
||||
const element = {querySelector};
|
||||
|
||||
setValue('name', 'new', element);
|
||||
|
||||
t.equal(el.value, 'new', 'should set value');
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue