-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Escape special characters in strings to render as expected for json
- Loading branch information
1 parent
392fa79
commit aa2fcb0
Showing
7 changed files
with
448 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,80 @@ | ||
import React from "react" | ||
import { shallow, mount } from "enzyme" | ||
import { expect } from "chai" | ||
import React from 'react'; | ||
import { shallow, mount } from 'enzyme'; | ||
import { expect } from 'chai'; | ||
|
||
import JsonString from "./../../../../../src/js/components/DataTypes/String" | ||
import JsonString from './../../../../../src/js/components/DataTypes/String'; | ||
|
||
describe("<JsonString />", function() { | ||
it("string component should have a data type label", function() { | ||
const rjvId = 1 | ||
describe('<JsonString />', function () { | ||
it('string component should have a data type label', function () { | ||
const rjvId = 1; | ||
const wrapper = mount( | ||
<JsonString | ||
value="test" | ||
rjvId={rjvId} | ||
displayDataTypes={true} | ||
theme="rjv-default" | ||
/> | ||
) | ||
expect(wrapper.find(".data-type-label")).to.have.length(1) | ||
}) | ||
); | ||
expect(wrapper.find('.data-type-label')).to.have.length(1); | ||
}); | ||
|
||
it("string with hidden data type", function() { | ||
const rjvId = 1 | ||
it('string with hidden data type', function () { | ||
const rjvId = 1; | ||
const props = { | ||
value: "test", | ||
value: 'test', | ||
rjvId: 1, | ||
theme: "rjv-default", | ||
theme: 'rjv-default', | ||
displayDataTypes: false | ||
} | ||
const component = mount(<JsonString {...props} />).render() | ||
expect(component.find(".data-type-label")).to.have.length(0) | ||
}) | ||
}; | ||
const component = mount(<JsonString {...props} />).render(); | ||
expect(component.find('.data-type-label')).to.have.length(0); | ||
}); | ||
|
||
//test collapsed string and expand click | ||
it("string displaying data type", function() { | ||
const rjvId = 1 | ||
it('string displaying data type', function () { | ||
const rjvId = 1; | ||
const props = { | ||
value: "test", | ||
value: 'test', | ||
rjvId: 1, | ||
displayDataTypes: false, | ||
theme: "rjv-default" | ||
} | ||
const component = mount(<JsonString {...props} />).render() | ||
expect(component.find(".data-type-label")).to.have.length(0) | ||
}) | ||
theme: 'rjv-default' | ||
}; | ||
const component = mount(<JsonString {...props} />).render(); | ||
expect(component.find('.data-type-label')).to.have.length(0); | ||
}); | ||
|
||
it("collapsed string content", function() { | ||
const rjvId = 1 | ||
it('collapsed string content', function () { | ||
const rjvId = 1; | ||
const props = { | ||
value: "123456789", | ||
value: '123456789', | ||
collapseStringsAfterLength: 3, | ||
rjvId: 1, | ||
displayDataTypes: false, | ||
theme: "rjv-default" | ||
} | ||
const component = shallow(<JsonString {...props} />) | ||
expect( | ||
component | ||
.render() | ||
.find(".string-value") | ||
.text() | ||
).to.equal('"123 ..."') | ||
component.find(".string-value").simulate("click") | ||
expect( | ||
component | ||
.render() | ||
.find(".string-value") | ||
.text() | ||
).to.equal('"123456789"') | ||
}) | ||
}) | ||
theme: 'rjv-default' | ||
}; | ||
const component = shallow(<JsonString {...props} />); | ||
expect(component.render().find('.string-value').text()).to.equal( | ||
'"123 ..."' | ||
); | ||
component.find('.string-value').simulate('click'); | ||
expect(component.render().find('.string-value').text()).to.equal( | ||
'"123456789"' | ||
); | ||
}); | ||
|
||
//test rendering strings with special escape sequences | ||
|
||
it('string with special escape sequences', function () { | ||
const rjvId = 1; | ||
const props = { | ||
value: '\\\n\t\r\f\\n', | ||
rjvId: 1, | ||
displayDataTypes: false, | ||
theme: 'rjv-default' | ||
}; | ||
const component = mount(<JsonString {...props} />).render(); | ||
expect(component.find('.string-value').text()).to.equal( | ||
'"\\\\\\n\\t\\r\\f\\\\n"' | ||
); | ||
}); | ||
}); |
Oops, something went wrong.