Skip to content

Commit d7706ac

Browse files
committed
Add unit-tests and some refactoring
1 parent e4da6cb commit d7706ac

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

common.blocks/cut/cut.deps.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
[{
22
mustDeps : [
3-
{ block : 'i-bem', elem : 'dom' }
3+
{ block : 'i-bem', mods : { 'elem-instances' : true }, elem : 'dom' }
44
],
55
shouldDeps : [
66
{ elems : ['switcher', 'container'] },
77
{ block : 'link', mods : { theme : 'islands', pseudo : true } }
88
]
9+
},
10+
{
11+
tech : 'spec.js',
12+
mustDeps : [
13+
{ tech : 'bemhtml', block : 'cut', mods : { theme : 'hackaton' } },
14+
{ block : 'link', mods : { theme : 'islands', type : 'pseudo' } }
15+
]
16+
},
17+
{
18+
tech : 'tmpl-spec.js',
19+
mustDeps : [
20+
{ tech : 'bemhtml', block : 'cut', mods : { theme : 'hackaton' } },
21+
{ block : 'link', mods : { theme : 'islands', type : 'pseudo' } }
22+
]
923
}]

common.blocks/cut/cut.spec.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
modules.define(
2+
'spec',
3+
['cut', 'i-bem__dom', 'jquery', 'BEMHTML'],
4+
function(provide, Cut, BEMDOM, $, BEMHTML) {
5+
6+
describe('cut', function() {
7+
var body = $('body'),
8+
cut;
9+
10+
beforeEach(function() {
11+
cut = BEMDOM.init($(BEMHTML.apply({
12+
block : 'cut',
13+
expandedText : 'Hide',
14+
mods : { theme : 'hackaton' },
15+
switcher : 'Show',
16+
content : 'Text here'
17+
}))
18+
.appendTo(body))
19+
.bem('cut');
20+
});
21+
22+
afterEach(function() {
23+
BEMDOM.destruct(cut.domElem);
24+
});
25+
26+
describe('open/close', function() {
27+
it('should show/hide container on open/close', function() {
28+
var container = cut.elemInstance('container');
29+
30+
container.hasMod('visible').should.be.false;
31+
cut.setMod('showed');
32+
container.hasMod('visible').should.be.true;
33+
cut.delMod('showed');
34+
container.hasMod('visible').should.be.false;
35+
});
36+
});
37+
38+
describe('change switcher text', function() {
39+
it('should change switcher text on open/close', function() {
40+
cut.elem('switcher').text().should.be.equal('Show');
41+
cut.setMod('showed');
42+
cut.elem('switcher').text().should.be.equal('Hide');
43+
cut.delMod('showed');
44+
cut.elem('switcher').text().should.be.equal('Show');
45+
});
46+
});
47+
});
48+
49+
provide();
50+
51+
});

0 commit comments

Comments
 (0)