From 394728f482b8561416bb610a9cf0ccdd16a44efe Mon Sep 17 00:00:00 2001 From: surunzi Date: Sun, 1 Oct 2017 14:49:02 +0800 Subject: [PATCH] Dev: Settings karma test --- doc/TOOL_API.md | 8 ++++++-- karma.conf.js | 2 +- src/Settings/Settings.js | 5 +++++ test/settings.js | 11 ++++++++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/doc/TOOL_API.md b/doc/TOOL_API.md index 559281c..aac57dd 100644 --- a/doc/TOOL_API.md +++ b/doc/TOOL_API.md @@ -162,11 +162,11 @@ Allow you to register small functions that can be triggered multiple times. ### clear -Clear Snippets. +Clear snippets. ### add -Add Snippet. +Add snippet. |Name|Type |Desc | |----|--------|------------------------| @@ -203,6 +203,10 @@ related materials in [Can I Use](http://caniuse.com/) website. Customization for all tools. +### clear + +Clear settings. + ### text Add text. diff --git a/karma.conf.js b/karma.conf.js index b4acd1c..ce33e5a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -18,7 +18,7 @@ module.exports = function (config) 'test/resources.js', 'test/snippets.js', 'test/sources.js', - // 'test/settings.js' + 'test/settings.js' ], plugins: [ 'karma-jasmine', diff --git a/src/Settings/Settings.js b/src/Settings/Settings.js index a913c07..a942eb8 100644 --- a/src/Settings/Settings.js +++ b/src/Settings/Settings.js @@ -20,6 +20,11 @@ export default class Settings extends Tool this._bindEvent(); } + clear() + { + this._settings = []; + this._$el.html(''); + } switch(config, key, desc) { this._settings.push({config, key}); diff --git a/test/settings.js b/test/settings.js index b56c3bb..6e1a093 100644 --- a/test/settings.js +++ b/test/settings.js @@ -7,6 +7,11 @@ cfg.set({ testSelect: ['1'] }); +beforeEach(function () +{ + tool.clear(); +}); + describe('switch', function () { it('ui', function () @@ -14,7 +19,7 @@ describe('switch', function () var text = 'Test Switch'; tool.switch(cfg, 'testSwitch', text); - expect($tool.find('.eruda-switch').eq(3)).toContainText(text); + expect($tool.find('.eruda-switch')).toContainText(text); }); }); @@ -23,7 +28,7 @@ describe('separator', function () it('ui', function () { tool.separator(); - expect($tool.find('.eruda-separator').length).toEqual(4); + expect($tool.find('.eruda-separator').length).toEqual(1); }); }); @@ -34,7 +39,7 @@ describe('select', function () var text = 'Test Select'; tool.select(cfg, 'testSelect', text, ['1', '2', '3']); - var $el = $tool.find('.eruda-select').eq(2); + var $el = $tool.find('.eruda-select'); expect($el.find('ul li').length).toEqual(3); expect($el.find('.eruda-val')).toContainText('1'); });