Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should update the text area value', () => {
let model = editor.model;
expect(model.value.text).to.equal('No data!');
editor.source = new ObservableJSON();
expect(model.value.text).to.equal('{}');
});
});
it('should bail if the input is focused', () => {
Widget.attach(editor, document.body);
editor.model.value.text = '{}';
editor.source = new ObservableJSON();
editor.editor.focus();
editor.source.set('foo', 2);
expect(editor.model.value.text).to.equal('{}');
});
});
it('should allow a key to be removed programmatically that was not set by the user', () => {
editor.source = new ObservableJSON();
editor.source.set('foo', 1);
editor.source.set('bar', 1);
editor.model.value.text = '{"foo": 1, "bar": 3}';
editor.source.delete('foo');
simulate(editor.commitButtonNode, 'click');
expect(editor.model.value.text).to.equal('{\n "bar": 3\n}');
});
it('should serialize the model to JSON', () => {
const item = new ObservableJSON();
item.set('foo', 1);
expect(item.toJSON()['foo']).to.equal(1);
});
it('should revert the current data', () => {
editor.source = new ObservableJSON();
editor.model.value.text = 'foo';
simulate(editor.revertButtonNode, 'click');
expect(editor.model.value.text).to.equal('{}');
});
it('should bail if the input is focused', () => {
Widget.attach(editor, document.body);
editor.model.value.text = '{}';
editor.source = new ObservableJSON();
editor.editor.focus();
editor.source.set('foo', 2);
expect(editor.model.value.text).to.equal('{}');
});
});
it('should allow a key to be removed programmatically that was not set by the user', () => {
editor.source = new ObservableJSON();
editor.source.set('foo', 1);
editor.source.set('bar', 1);
editor.model.value.text = '{"foo": 1, "bar": 3}';
editor.source.delete('foo');
simulate(editor.commitButtonNode, 'click');
expect(editor.model.value.text).to.equal('{\n "bar": 3\n}');
});
it('should not revert to current data if there was a change', () => {
editor.source = new ObservableJSON();
editor.model.value.text = 'foo';
editor.source.set('foo', 1);
let model = editor.model;
expect(model.value.text).to.equal('foo');
simulate(editor.editorHostNode, 'blur');
expect(model.value.text).to.equal('foo');
expect(editor.commitButtonNode.hidden).to.be.true;
expect(editor.revertButtonNode.hidden).to.be.false;
});
});
it('should be settable', () => {
let source = new ObservableJSON();
editor.source = source;
expect(editor.source).to.equal(source);
});
it('should return a copy of the data', () => {
const item = new ObservableJSON();
item.set('foo', { bar: 1 });
const value = item.toJSON();
value['bar'] = 2;
expect((item.get('foo') as any)['bar']).to.equal(1);
});
});