Skip to content

Commit

Permalink
ADD: test for indentation in code block
Browse files Browse the repository at this point in the history
  • Loading branch information
farthinker committed Oct 8, 2015
1 parent 46e7cec commit fa8f885
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
16 changes: 15 additions & 1 deletion spec/indentation-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
expect(parseInt($p1.css('margin-left'))).toBe(0);
return expect(parseInt($p2.css('margin-left'))).toBe(0);
});
return it('should indent list when pressing tab in ul', function() {
it('should indent list when pressing tab in ul', function() {
var $li, $li1, $li2, $ul, range;
editor = spec.generateSimditor({
content: '<ul>\n <li>item 1</li>\n <li>item 2</li>\n <li>item 3</li>\n</ul>'
Expand All @@ -52,6 +52,20 @@
expect($li1.parentsUntil(editor.body, 'ul').length).toBe(1);
return expect($li2.parentsUntil(editor.body, 'ul').length).toBe(1);
});
return it('should insert two spaces while pressing tab in code block', function() {
var $pre, range;
editor = spec.generateSimditor({
content: '<pre><code>var test = 1;</code></pre>',
toolbar: ['code']
});
editor.focus();
$pre = editor.body.find('> pre');
range = document.createRange();
editor.selection.setRangeAtStartOf($pre, range);
expect($pre.html()).toBe('var test = 1;');
editor.indentation.indent();
return expect($pre.html()).toBe('&nbsp;&nbsp;var test = 1;');
});
});

}).call(this);
16 changes: 16 additions & 0 deletions spec/src/indentation-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,19 @@ describe 'A Simditor instance with indentation manager', ->
editor.indentation.indent(true)
expect($li1.parentsUntil(editor.body, 'ul').length).toBe(1)
expect($li2.parentsUntil(editor.body, 'ul').length).toBe(1)

it 'should insert two spaces while pressing tab in code block', ->
editor = spec.generateSimditor
content: '''
<pre><code>var test = 1;</code></pre>
'''
toolbar: ['code']
editor.focus()

$pre = editor.body.find '> pre'
range = document.createRange()
editor.selection.setRangeAtStartOf $pre, range

expect($pre.html()).toBe('var test = 1;')
editor.indentation.indent()
expect($pre.html()).toBe('&nbsp;&nbsp;var test = 1;')

0 comments on commit fa8f885

Please sign in to comment.