-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
102 lines (83 loc) · 3.53 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>BemBone test page</title>
<meta name="description" content="BemBone test page">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
<script src="bem.backbone.js"></script>
</head>
<body>
<!-- HTML for testing -->
<article class="news" id="sample">
<header class="news__header">
<h1 class="news__title"></h1>
<time class="news__date"></time>
</header>
<div class="news__teaser news__teaser_mod1_val1
news__teaser_mod-2_val-2
news__teaser_mod3_wrong_val"></div>
<footer class="news__controlls">
<a class="news__more" href=""></a>
<span class="news__add-to-favorites"></span>
<span class="news__rate"></span>
</footer>
</article>
<!-- Test suite -->
<script>
$(function(){
var NewsView = Backbone.BemView.extend({
blockName: 'news'
});
var view = new NewsView({
el: $('#sample')
});
console.info('Test modifier setting to view element');
view.setMod('importance', 'high');
if (!view.$el.is('article.news.news_importance_high')) {
console.error("view.setMod set wrong classes:", view.$el.attr('class'));
}
console.info('Test modifier remove from view element');
view.removeMod('importance');
if (view.$el.hasClass('news_importance_high')) {
console.error("view.removeMod do not removed modifier class:", view.$el.attr('class'));
}
console.info('Test element getting');
var $titleElement = view.element('title');
if (!$titleElement.is('h1.news__title')) {
console.error("view.element return wrong element:", $titleElement);
}
console.info('Test modifiers setting');
$titleElement.setMod({
size: 'big',
bordered: 'yes'
});
if (!$titleElement.hasClass('news__title_size_big') || !$titleElement.hasClass('news__title_bordered_yes')) {
console.error("view.element('title').setMod set wrong classes:", $titleElement.attr('class'));
}
console.info('Test modifier change');
$titleElement.setMod('size', 'small');
if (!$titleElement.hasClass('news__title_size_small') || $titleElement.hasClass('news__title_size_big')) {
console.error("view.element('title').setMod set wrong classes:", $titleElement.attr('class'));
}
console.info('Test modifier remove');
$titleElement.removeMod('bordered');
if ($titleElement.hasClass('news__title_bordered_yes')) {
console.error("view.element('title').removeMod do not removed modifier class:", $titleElement.attr('class'));
}
console.info('Test modifiers restore');
var $teaserElement = view.element('teaser');
$teaserElement.removeMod('mod-2');
if ($teaserElement.hasClass('news__teaser_mod-2_val-2')) {
console.error("view.element('teaser') has modifier mod-2, but removeMod('mod-2') do not remove it");
}
$teaserElement.removeMod('mod3');
if (!$teaserElement.hasClass('news__teaser_mod3_wrong_val')) {
console.error("view.element('teaser') has wrong modifier mod3, but removeMod('mod-2') remove it");
}
});
</script>
</body>
</html>