Skip to content

Commit

Permalink
Add test for getting selected text
Browse files Browse the repository at this point in the history
  • Loading branch information
securingsincity committed May 28, 2017
1 parent 56fa7c0 commit 8cecf02
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tests/src/ace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,23 @@ describe('Ace Component', () => {
expect(onFocusCallback.callCount).to.equal(1);
});

it('should call the onSelectionChange method callback', () => {
const onSelectionChangeCallback = sinon.spy();
const wrapper = mount(<AceEditor onSelectionChange={onSelectionChangeCallback}/>, mountOptions);

// Check is not previously called
expect(onSelectionChangeCallback.callCount).to.equal(0);

// Trigger the focus event
it('should call the onSelectionChange method callback', (done) => {
let onSelectionChange = function(){}
const value = `
function main(value) {
console.log('hi james')
return value;
}
`;
const wrapper = mount(<AceEditor value={value} />, mountOptions);

onSelectionChange = function(selection) {
const content = wrapper.instance().editor.session.getTextRange(selection.getRange());
expect(content).to.equal(value)
done()
}
wrapper.setProps({onSelectionChange})
wrapper.instance().editor.getSession().selection.selectAll()

expect(onSelectionChangeCallback.callCount).to.equal(1);
});

it('should call the onBlur method callback', () => {
Expand Down

0 comments on commit 8cecf02

Please sign in to comment.