mirror of
https://github.com/pebble-dev/clay.git
synced 2026-09-01 22:57:41 -04:00
Allow floats in the slider component and update docs
This commit is contained in:
@@ -112,7 +112,8 @@ describe('ClayConfig', function() {
|
||||
{label: 'label-1', value: 'cb-1'},
|
||||
{label: 'label-2', value: 'cb-2'},
|
||||
{label: 'label-2', value: 'cb-3'}
|
||||
]}
|
||||
]},
|
||||
{type: 'slider', appKey: 'test5', step: 0.05, defaultValue: 12.5}
|
||||
];
|
||||
var settings = {
|
||||
test2: 'val-2'
|
||||
@@ -121,10 +122,11 @@ describe('ClayConfig', function() {
|
||||
var clayConfig = fixtures.clayConfig(config, true, true, settings);
|
||||
|
||||
assert.deepEqual(clayConfig.serialize(), {
|
||||
test1: 'default val',
|
||||
test2: 'val-2',
|
||||
test3: false,
|
||||
test4: []
|
||||
test1: {value: 'default val'},
|
||||
test2: {value: 'val-2'},
|
||||
test3: {value: false},
|
||||
test4: {value: []},
|
||||
test5: {value: 12.5, precision: 2}
|
||||
});
|
||||
|
||||
clayConfig.getItemByAppKey('test1').set('val-1');
|
||||
@@ -132,17 +134,29 @@ describe('ClayConfig', function() {
|
||||
clayConfig.getItemByAppKey('test4').set(['cb-1', 'cb-3']);
|
||||
|
||||
assert.deepEqual(clayConfig.serialize(), {
|
||||
test1: 'val-1',
|
||||
test2: 'val-2',
|
||||
test3: true,
|
||||
test4: ['cb-1', 'cb-3']
|
||||
test1: {value: 'val-1'},
|
||||
test2: {value: 'val-2'},
|
||||
test3: {value: true},
|
||||
test4: {value: ['cb-1', 'cb-3']},
|
||||
test5: {value: 12.5, precision: 2}
|
||||
});
|
||||
|
||||
// make sure the result of serialize() can actually be fed back in to
|
||||
// a new instance of ClayConfig
|
||||
var clay = fixtures.clay(config);
|
||||
var response = encodeURIComponent(JSON.stringify(clayConfig.serialize()));
|
||||
clay.getSettings(response);
|
||||
var loadedSettings = JSON.parse(localStorage.getItem('clay-settings'));
|
||||
|
||||
assert.deepEqual(loadedSettings, {
|
||||
test1: 'val-1',
|
||||
test2: 'val-2',
|
||||
test3: true,
|
||||
test4: ['cb-1', 'cb-3'],
|
||||
test5: 12.5
|
||||
});
|
||||
assert.doesNotThrow(function() {
|
||||
settings = clayConfig.serialize();
|
||||
fixtures.clayConfig(config, true, true, settings);
|
||||
fixtures.clayConfig(config, true, true, loadedSettings);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,60 +26,5 @@ describe('Utils', function() {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.prepareForAppMessage', function() {
|
||||
it('converts an array correctly when array contains strings', function() {
|
||||
assert.deepEqual(
|
||||
utils.prepareForAppMessage(['one', 'two']),
|
||||
['one', 0, 'two', 0]
|
||||
);
|
||||
});
|
||||
|
||||
it('converts an array correctly when array contains numbers', function() {
|
||||
assert.deepEqual(utils.prepareForAppMessage([1, 2, 3]), [1, 2, 3]);
|
||||
});
|
||||
|
||||
it('converts an array correctly when array contains booleans', function() {
|
||||
assert.deepEqual(utils.prepareForAppMessage([true, false, true]), [1, 0, 1]);
|
||||
});
|
||||
|
||||
it('converts booleans to ints', function() {
|
||||
assert.strictEqual(utils.prepareForAppMessage(false), 0);
|
||||
assert.strictEqual(utils.prepareForAppMessage(true), 1);
|
||||
});
|
||||
|
||||
it('leaves strings alone', function() {
|
||||
assert.strictEqual(utils.prepareForAppMessage('test'), 'test');
|
||||
});
|
||||
|
||||
it('leaves numbers alone', function() {
|
||||
assert.strictEqual(utils.prepareForAppMessage(123), 123);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.prepareSettingsForAppMessage', function() {
|
||||
it('converts the settings correctly', function() {
|
||||
var settings = {
|
||||
test1: false,
|
||||
test2: 'val-2',
|
||||
test3: true,
|
||||
test4: ['cb-1', 'cb-3'],
|
||||
test5: 12345,
|
||||
test6: [1, 2, 3, 4],
|
||||
test7: [true, false, true]
|
||||
};
|
||||
var expected = {
|
||||
test1: 0,
|
||||
test2: 'val-2',
|
||||
test3: 1,
|
||||
test4: ['cb-1', 0, 'cb-3', 0],
|
||||
test5: 12345,
|
||||
test6: [1, 2, 3, 4],
|
||||
test7: [1, 0, 1]
|
||||
};
|
||||
|
||||
assert.deepEqual(utils.prepareSettingsForAppMessage(settings), expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user