Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests for Cut block #8

Open
wants to merge 2 commits into
base: hackaton
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions common.blocks/cut/_switcher/cut_switcher_button.bemhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
block('cut').mod('switcher', 'button')(

js()(function(){
return { expandedText : this.ctx.expandedText || 'Hide' };
}),

content()(function() {
return [
{ elem : 'container', content : this.ctx.content || 'Text here' },
{
block : 'button',
mods : { type : 'button', theme : 'islands', size : this.ctx.mods.size || 's' },
mix : { block : 'cut', elem : 'switcher' },
text : this.ctx.switcher || 'Show'
}
];
})

);
17 changes: 17 additions & 0 deletions common.blocks/cut/_switcher/cut_switcher_button.deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[{
shouldDeps : [
{ block : 'button', mods : { theme : 'islands', type : 'button' } }
]
},
{
tech : 'spec.js',
mustDeps : [
{ tech : 'bemhtml', block : 'button' }
]
},
{
tech : 'tmpl-spec.js',
mustDeps : [
{ tech : 'bemhtml', block : 'button' }
]
}]
33 changes: 33 additions & 0 deletions common.blocks/cut/_switcher/cut_switcher_button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @module cut
*/

modules.define('cut', ['button'], function(provide, _, Cut) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что нужно сделать, чтобы заставить работать код из этого файла? У меня кончились варианты.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

так ты ж этот модификатор ен указал нигде - ни в bemjson, ни в deps. В зависимостях у тебя вообще указан элемент switcher, которого не существует


/**
* @exports
* @class cut
* @bem
*/
provide(Cut.decl({ modName : 'switcher', modVal : 'button' }, /** @lends cut.prototype */{
onSetMod : {
'showed' : function(_, modVal) {
this.__base.apply(this, arguments);
this._changeSwitcherButtonText(_, modVal);
}
},

_changeSwitcherButtonText : function(modName, modVal) {
var button = this.findBlockOn(this.getSwitcher(), 'button');
this.__base.apply(this, arguments);

button.setText(modVal? this._switcherText.expanded : this._switcherText.collapsed);
}
}, /** @lends cut */{
live : function() {
this.liveInitOnBlockInsideEvent('click', 'button', this.onSwitcherClick);
return this.__base.apply(this, arguments);
}
}));

});
6 changes: 4 additions & 2 deletions common.blocks/cut/cut.bemhtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
block('cut')(

js()(true),
js()(function(){
return { expandedText : this.ctx.expandedText || 'Hide' };
}),

content()(function() {
return [
{ elem : 'container', content : applyNext() },
{ elem : 'container', content : this.ctx.content || 'Text here' },
{
block : 'link',
mods : { pseudo : true, theme : 'islands' },
Expand Down
2 changes: 1 addition & 1 deletion common.blocks/cut/cut.bh.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function(bh) {

bh.match('cut', function(ctx, json) {
ctx
.js(true)
.js({ expandedText : json.expandedText || 'Hide' })
.content([
{ elem : 'container', content : json.content },
{
Expand Down
19 changes: 17 additions & 2 deletions common.blocks/cut/cut.deps.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
[{
mustDeps : [
{ block : 'i-bem', elem : 'dom' }
{ block : 'i-bem', mods : { 'elem-instances' : true }, elem : 'dom' }
],
shouldDeps : [
{ elems : ['switcher', 'container'] },
{ block : 'link', mods : { theme : 'islands', pseudo : true } }
{ block : 'link', mods : { theme : 'islands', pseudo : true } }/*,
{ block : 'button', mods : { theme : 'islands' } }*/
]
},
{
tech : 'spec.js',
mustDeps : [
{ tech : 'bemhtml', block : 'cut', mods : { theme : 'hackaton' } },
{ tech : 'bemhtml', block : 'link', mods : { theme : 'islands', type : 'pseudo' } }
]
},
{
tech : 'tmpl-spec.js',
mustDeps : [
{ tech : 'bemhtml', block : 'cut', mods : { theme : 'hackaton' } },
{ tech : 'bemhtml', block : 'link', mods : { theme : 'islands', type : 'pseudo' } }
]
}]
28 changes: 14 additions & 14 deletions common.blocks/cut/cut.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ provide(BEMDOM.decl(this.name, {
'inited' : function() {
this._switcher = null;
this._popup = null;
this._params = {
this._switcherText = {
expanded : this.params.expandedText || 'Hide',
collapsed : this.getSwitcher().text() || 'Show'
};
}
},

'opened' : function(modName, modVal) {
'showed' : function(modName, modVal) {
this.setMod((this.getSwitcher()), 'opened', modVal);
this.setMod((this.getContainer()), 'visible', modVal);

this._switcherTextChange();
if(this.hasMod('switcher')) return false;

this._changeSwitcherText(modName, modVal);
}
},

_switcherTextChange : function() {
var text = this.hasMod('opened')? this._params.expanded : this._params.collapsed;

this._switcher.html(text);
_changeSwitcherText : function(modName, modVal) {
this.getSwitcher().html(modVal? this._switcherText.expanded : this._switcherText.collapsed);
},

/**
Expand All @@ -52,8 +52,13 @@ provide(BEMDOM.decl(this.name, {
getContainer : function() {
return this._container ||
(this._container = this.findElem('container', true));
},
}

}, {
live : function() {
this.liveBindTo('switcher', 'click', this.onSwitcherClick);
return this.__base.apply(this, arguments);
},
/**
* On BEM click event handler
* @param {events:Event} e
Expand All @@ -62,12 +67,7 @@ provide(BEMDOM.decl(this.name, {
onSwitcherClick : function(e) {
e.preventDefault();

this.toggleMod('opened');
}

}, {
live : function() {
this.liveBindTo('switcher', 'click', this.prototype.onSwitcherClick);
this.toggleMod('showed');
}
}));

Expand Down
51 changes: 51 additions & 0 deletions common.blocks/cut/cut.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
modules.define(
'spec',
['cut', 'i-bem__dom', 'jquery', 'BEMHTML'],
function(provide, Cut, BEMDOM, $, BEMHTML) {

describe('cut', function() {
var body = $('body'),
cut;

beforeEach(function() {
cut = BEMDOM.init($(BEMHTML.apply({
block : 'cut',
expandedText : 'Hide',
mods : { theme : 'hackaton' },
switcher : 'Show',
content : 'Text here'
}))
.appendTo(body))
.bem('cut');
});

afterEach(function() {
BEMDOM.destruct(cut.domElem);
});

describe('open/close', function() {
it('should show/hide container on open/close', function() {
var container = cut.elemInstance('container');

container.hasMod('visible').should.be.false;
cut.setMod('showed');
container.hasMod('visible').should.be.true;
cut.delMod('showed');
container.hasMod('visible').should.be.false;
});
});

describe('change switcher text', function() {
it('should change switcher text on open/close', function() {
cut.elem('switcher').text().should.be.equal('Show');
cut.setMod('showed');
cut.elem('switcher').text().should.be.equal('Hide');
cut.delMod('showed');
cut.elem('switcher').text().should.be.equal('Show');
});
});
});

provide();

});
6 changes: 2 additions & 4 deletions common.blocks/cut/cut.tests/simple.bemjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
{ tag : 'h2', content : 'Cut' },
{
block : 'cut',
js : {
expandedText : 'Hide'
},
mods : { theme : 'simple' },
expandedText : 'Hide',
mods : { theme : 'hackaton' },
switcher : 'Show',
content : 'Text here'
}
Expand Down
3 changes: 2 additions & 1 deletion common.blocks/cut/cut.tmpl-specs/10-default.bemjson.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
block : 'cut',
js : { expandedText : 'cut-hide' },
mods : { theme : 'hackaton' },
switcher : 'cut-show',
expandedText : 'cut-hide',
content : 'cut-text'
})
2 changes: 1 addition & 1 deletion common.blocks/cut/cut.tmpl-specs/10-default.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="cut i-bem" data-bem="{&quot;cut&quot;:{&quot;expandedText&quot;:&quot;cut-hide&quot;}}"><div class="cut__container">cut-text</div><a class="link link_type_pseudo link_theme_islands link__control cut__switcher i-bem" data-bem="{&quot;link&quot;:{}}" tabindex="0">cut-show</a></div>
<div class="cut cut_theme_hackaton i-bem" data-bem="{&quot;cut&quot;:{&quot;expandedText&quot;:&quot;cut-hide&quot;}}"><div class="cut__container">cut-text</div><span class="link link_pseudo link_theme_islands link__control cut__switcher i-bem" data-bem="{&quot;link&quot;:{}}" tabindex="0">cut-show</span></div>
10 changes: 4 additions & 6 deletions common.blocks/cut/cut.tmpl-specs/20-nested.bemjson.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
({
block : 'cut',
js : {
expandedText : 'cut-hide'
},
mods : { theme : 'hackaton' },
expandedText : 'cut-hide',
switcher : 'cut-show',
content : [
'cut-text',
{
block : 'cut',
js : {
expandedText : 'subcut-hide'
},
mods : { theme : 'hackaton' },
expandedText : 'subcut-hide',
switcher : 'subcut-show',
content : 'subcut-text'
}
Expand Down
2 changes: 1 addition & 1 deletion common.blocks/cut/cut.tmpl-specs/20-nested.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="cut i-bem" data-bem="{&quot;cut&quot;:{&quot;expandedText&quot;:&quot;cut-hide&quot;}}"><div class="cut__container">cut-text<div class="cut i-bem" data-bem="{&quot;cut&quot;:{&quot;expandedText&quot;:&quot;subcut-hide&quot;}}"><div class="cut__container">subcut-text</div><a class="link link_type_pseudo link_theme_islands link__control cut__switcher i-bem" data-bem="{&quot;link&quot;:{}}" tabindex="0">subcut-show</a></div></div><a class="link link_type_pseudo link_theme_islands link__control cut__switcher i-bem" data-bem="{&quot;link&quot;:{}}" tabindex="0">cut-show</a></div>
<div class="cut cut_theme_hackaton i-bem" data-bem="{&quot;cut&quot;:{&quot;expandedText&quot;:&quot;cut-hide&quot;}}"><div class="cut__container">cut-text<div class="cut cut_theme_hackaton i-bem" data-bem="{&quot;cut&quot;:{&quot;expandedText&quot;:&quot;subcut-hide&quot;}}"><div class="cut__container">subcut-text</div><span class="link link_pseudo link_theme_islands link__control cut__switcher i-bem" data-bem="{&quot;link&quot;:{}}" tabindex="0">subcut-show</span></div></div><span class="link link_pseudo link_theme_islands link__control cut__switcher i-bem" data-bem="{&quot;link&quot;:{}}" tabindex="0">cut-show</span></div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.cut_theme_simple {
.cut_theme_hackaton {

>.cut__container {
display: none;
Expand Down
6 changes: 2 additions & 4 deletions desktop.pages/cut/cut.bemjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
},
{
block : 'cut',
js : {
expandedText : 'Скрыть'
},
mods : { type: 'inline', theme : 'simple', size: 's' },
mods : { theme : 'hackaton', switcher : 'button', size : 'm' },
switcher : 'Подробнее',
expandedText : 'Скрыть',
content : [
'Время шло, сервисы развивались и всё больше разработчиков ',
'интерфейсов вкладывали свои усилия в развитие Яндекса.'
Expand Down