Adding tests for CharsetRange nodes
This commit is contained in:
parent
d27831a265
commit
8a9a129856
60
spec/parser/javascript/charset_range_spec.js
Normal file
60
spec/parser/javascript/charset_range_spec.js
Normal file
@ -0,0 +1,60 @@
|
||||
import javascript from 'src/js/parser/javascript/parser.js';
|
||||
import util from 'src/js/util.js';
|
||||
import Q from 'q';
|
||||
|
||||
describe('parser/javascript/charset_range.js', function() {
|
||||
|
||||
it('parses "a-z" as a CharsetRange', function() {
|
||||
var parser = new javascript.Parser('a-z');
|
||||
expect(parser.__consume__charset_range()).toEqual(jasmine.objectContaining({
|
||||
type: 'charset-range',
|
||||
first: jasmine.objectContaining({
|
||||
textValue: 'a'
|
||||
}),
|
||||
last: jasmine.objectContaining({
|
||||
textValue: 'z'
|
||||
})
|
||||
}));
|
||||
});
|
||||
|
||||
describe('#_render', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
var parser = new javascript.Parser('a-z');
|
||||
this.node = parser.__consume__charset_range();
|
||||
|
||||
this.node.container = jasmine.createSpyObj('cotnainer', ['addClass', 'text', 'group']);
|
||||
this.node.container.text.and.returnValue('hyphen');
|
||||
|
||||
this.firstDeferred = Q.defer();
|
||||
this.lastDeferred = Q.defer();
|
||||
|
||||
spyOn(this.node.first, 'render').and.returnValue(this.firstDeferred.promise);
|
||||
spyOn(this.node.last, 'render').and.returnValue(this.lastDeferred.promise);
|
||||
spyOn(util, 'spaceHorizontally');
|
||||
});
|
||||
|
||||
it('renders a hyphen', function() {
|
||||
this.node._render();
|
||||
expect(this.node.container.text).toHaveBeenCalledWith(0, 0, '-');
|
||||
});
|
||||
|
||||
it('spaces the items horizontally', function(done) {
|
||||
this.firstDeferred.resolve();
|
||||
this.lastDeferred.resolve();
|
||||
|
||||
this.node._render()
|
||||
.then(() => {
|
||||
expect(util.spaceHorizontally).toHaveBeenCalledWith([
|
||||
this.node.first,
|
||||
'hyphen',
|
||||
this.node.last
|
||||
], { padding: 5 });
|
||||
})
|
||||
.finally(done)
|
||||
.done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@ -1,4 +1,4 @@
|
||||
import { spaceHorizontally } from '../../util.js';
|
||||
import util from '../../util.js';
|
||||
import _ from 'lodash';
|
||||
import Q from 'q';
|
||||
|
||||
@ -8,8 +8,7 @@ export default {
|
||||
_render() {
|
||||
var contents = [
|
||||
this.first,
|
||||
this.container.text()
|
||||
.attr({ text: '-' }),
|
||||
this.container.text(0, 0, '-'),
|
||||
this.last
|
||||
];
|
||||
|
||||
@ -17,9 +16,11 @@ export default {
|
||||
this.first.render(this.container.group()),
|
||||
this.last.render(this.container.group())
|
||||
])
|
||||
.then(spaceHorizontally.bind(this, contents, {
|
||||
padding: 5
|
||||
}));
|
||||
.then(() => {
|
||||
util.spaceHorizontally(contents, {
|
||||
padding: 5
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
setup() {
|
||||
|
@ -70,3 +70,10 @@ export function spaceVertically(items, options) {
|
||||
.translate(horizontalCenter - item.getBBox().cx, 0));
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
customEvent,
|
||||
normalizeBBox,
|
||||
spaceHorizontally,
|
||||
spaceVertically
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user