Skip to content

Commit

Permalink
Merge pull request #2 from devex-web-frontend/feature/disabled_modifier
Browse files Browse the repository at this point in the history
seems fine
  • Loading branch information
mankdev committed Jan 21, 2016
2 parents c13e85e + ec315d5 commit 4d69b69
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/js/colorpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var Colorpicker = (function(DX, window, document, undefined) {
var event = DX.Event,
CN_COLORPICKER = 'colorPicker',
M_OPEN = 'opened',
M_DISABLED = 'disabled',
CN_COLORPICKER_LABEL = CN_COLORPICKER + '--label',
CN_COLORPICKER_VALUE = CN_COLORPICKER + '--value',
defaultColors = {
Expand Down Expand Up @@ -79,7 +80,9 @@ var Colorpicker = (function(DX, window, document, undefined) {
});
initListeners();
setColorListHandler();

if (disabled) {
setDisabled();
}
DX.Event.trigger(input, Colorpicker.E_CREATED, {
detail: {
block: block,
Expand All @@ -103,7 +106,6 @@ var Colorpicker = (function(DX, window, document, undefined) {

function initAppearance() {
var parent = DX.Dom.getParent(input);

block = DX.Dom.createElement('div', {
className: CN_COLORPICKER,
innerHTML: DX.Tmpl.process(config.INNER_TMPL, config)
Expand Down Expand Up @@ -277,10 +279,12 @@ var Colorpicker = (function(DX, window, document, undefined) {
function setDisabled() {
hideDropDown();
disabled = true;
DX.Bem.addModifier(block, M_DISABLED);
}

function setEnabled() {
disabled = false;
DX.Bem.removeModifier(block, M_DISABLED);
}

/**
Expand Down
41 changes: 35 additions & 6 deletions test/js/colorpicker.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*/
describe('Colorpicker', function() {
var elementTmpl = [
'<input type="text" value="" id="test" />'
].join(''),
defaultColorList = ['#511717', '#000000', '#fefefe'],
colorPicker,
testElement;
'<input type="text" value="" id="test" />'
].join(''),
defaultColorList = ['#511717', '#000000', '#fefefe'],
colorPicker,
testElement;

beforeEach(function() {
document.body.innerHTML = elementTmpl;
Expand All @@ -22,12 +22,41 @@ describe('Colorpicker', function() {
window.Colorpicker.colorList = [];
});

describe('disabled', function() {

var getDisabled;

beforeEach(function(){
testElement.disabled = true;
getDisabled = function() {
return document.querySelectorAll('.colorPicker-disabled');
}
});

it('should has modifier `disabled` if input has attribute `disabled`', function() {
new Colorpicker(testElement);
expect(getDisabled().length).toEqual(1)
});

it('sholud remove modifier `disabled` on method `setEnabled`', function() {
var colorPicker = new Colorpicker(testElement);
colorPicker.setEnabled();
expect(getDisabled().length).toEqual(0)
});

it('sholud add modifier `disabled` on method `setDisabled`', function() {
test.disabled = false;
var colorPicker = new Colorpicker(testElement);
colorPicker.setDisabled();
expect(getDisabled().length).toEqual(1)
})

});

describe('dropDownData', function() {

var dropDown,
dataList,
temp,
initColorPicker;

beforeEach(function(){
Expand Down

0 comments on commit 4d69b69

Please sign in to comment.