Skip to content
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
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ function MultiDecorator(decorators) {
@param {ContentBlock}
@return {List<String>}
*/
MultiDecorator.prototype.getDecorations = function(block) {
MultiDecorator.prototype.getDecorations = function(block, contentState) {
var decorations = Array(block.getText().length).fill(null);

this.decorators.forEach(function(decorator, i) {
var _decorations = decorator.getDecorations(block);
var _decorations = decorator.getDecorations(block, contentState);

_decorations.forEach(function(key, offset) {
if (!key) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"immutable": "*"
},
"devDependencies": {
"draft-js": "^0.7.0",
"draft-js": "^0.10.0",
"expect": "^1.20.1",
"mocha": "^2.5.3",
"react": "^15.1.0",
Expand Down
20 changes: 16 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ describe('MultiDecorator', function() {
text: 'AAA BBB CCC ABC'
});

var firstDecoratorStrategy = expect.createSpy().andCall(
function(block, callback, contentState) {
callback(0, 3);
callback(12, 15);
}
)

var firstDecorator = new Draft.CompositeDecorator([
{
strategy: function(block, callback) {
callback(0, 3);
callback(12, 15);
},
strategy: firstDecoratorStrategy,
component: function() { return 'a'; }
}
]);
Expand Down Expand Up @@ -44,6 +48,14 @@ describe('MultiDecorator', function() {
thirdDecorator
]);

it('should pass contentState through to decorators', function() {
const contentState = 'mockContentState'
decorator.getDecorations(block, contentState);
expect(firstDecoratorStrategy.calls[0].arguments[0]).toBe(block)
expect(firstDecoratorStrategy.calls[0].arguments[2]).toBe(contentState)
firstDecoratorStrategy.reset()
})

it('should correctly decorate text', function() {
var out = decorator.getDecorations(block);

Expand Down