forked from galr52/react-extreme-json-view
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add keyboard handler and aria attributes to
collapse/expand braces, strings and functions Fixes mac-s-g#355
- Loading branch information
1 parent
b6ae661
commit fbd30d8
Showing
7 changed files
with
229 additions
and
105 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,86 +1,120 @@ | ||
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 JsonFunction from "./../../../../../src/js/components/DataTypes/Function" | ||
import JsonFunction from './../../../../../src/js/components/DataTypes/Function'; | ||
|
||
import AttributeStore from "./../../../../../src/js/stores/ObjectAttributes" | ||
import AttributeStore from './../../../../../src/js/stores/ObjectAttributes'; | ||
|
||
describe("<JsonFunction />", function() { | ||
const rjvId = 1 | ||
describe('<JsonFunction />', function () { | ||
const rjvId = 1; | ||
|
||
it("function component should have a data type label", function() { | ||
it('function component should have a data type label', function () { | ||
const wrapper = mount( | ||
<JsonFunction | ||
value={function() {}} | ||
value={function () {}} | ||
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("function component should not have a data type label", function() { | ||
it('function component should not have a data type label', function () { | ||
const wrapper = mount( | ||
<JsonFunction | ||
value={function() {}} | ||
value={function () {}} | ||
rjvId={rjvId} | ||
displayDataTypes={false} | ||
theme="rjv-default" | ||
/> | ||
) | ||
expect(wrapper.find(".data-type-label")).to.have.length(0) | ||
}) | ||
); | ||
expect(wrapper.find('.data-type-label')).to.have.length(0); | ||
}); | ||
|
||
it("function component expanded", function() { | ||
AttributeStore.set(rjvId, "function-test", "collapsed", false) | ||
it('function component expanded', function () { | ||
AttributeStore.set(rjvId, 'function-test', 'collapsed', false); | ||
|
||
const wrapper = shallow( | ||
<JsonFunction | ||
value={function() {}} | ||
value={function () {}} | ||
namespace="function-test" | ||
rjvId={rjvId} | ||
displayDataTypes={true} | ||
theme="rjv-default" | ||
/> | ||
) | ||
expect(wrapper.find(".function-collapsed")).to.have.length(0) | ||
}) | ||
); | ||
expect(wrapper.find('.function-collapsed')).to.have.length(0); | ||
}); | ||
|
||
it("function component collapsed", function() { | ||
AttributeStore.set(rjvId, "function-test", "collapsed", true) | ||
it('function component collapsed', function () { | ||
AttributeStore.set(rjvId, 'function-test', 'collapsed', true); | ||
|
||
const wrapper = shallow( | ||
<JsonFunction | ||
value={function() {}} | ||
value={function () {}} | ||
namespace="function-test" | ||
rjvId={rjvId} | ||
displayDataTypes={true} | ||
theme="rjv-default" | ||
/> | ||
) | ||
); | ||
|
||
expect(wrapper.find(".function-collapsed")).to.have.length(1) | ||
}) | ||
expect(wrapper.find('.function-collapsed')).to.have.length(1); | ||
}); | ||
|
||
it("function component click to expand", function() { | ||
AttributeStore.set(rjvId, "function-test", "collapsed", true) | ||
it('function component click to expand', function () { | ||
AttributeStore.set(rjvId, 'function-test', 'collapsed', true); | ||
|
||
const wrapper = shallow( | ||
<JsonFunction | ||
value={function() {}} | ||
value={function () {}} | ||
namespace="function-test" | ||
rjvId={rjvId} | ||
displayDataTypes={true} | ||
theme="rjv-default" | ||
/> | ||
) | ||
); | ||
|
||
expect(wrapper.find(".function-collapsed")).to.have.length(1) | ||
expect(wrapper.find('.function-collapsed')).to.have.length(1); | ||
expect( | ||
wrapper.find('.rjv-function-container').prop('aria-expanded') | ||
).to.equal(false); | ||
|
||
wrapper.find(".rjv-function-container").simulate("click") | ||
wrapper.find('.rjv-function-container').simulate('click'); | ||
|
||
expect(wrapper.find(".function-collapsed")).to.have.length(0) | ||
}) | ||
}) | ||
expect(wrapper.find('.function-collapsed')).to.have.length(0); | ||
expect( | ||
wrapper.find('.rjv-function-container').prop('aria-expanded') | ||
).to.equal(true); | ||
}); | ||
|
||
it('function component keydown to expand', function () { | ||
AttributeStore.set(rjvId, 'function-test', 'collapsed', true); | ||
|
||
const wrapper = shallow( | ||
<JsonFunction | ||
value={function () {}} | ||
namespace="function-test" | ||
rjvId={rjvId} | ||
displayDataTypes={true} | ||
theme="rjv-default" | ||
/> | ||
); | ||
|
||
expect(wrapper.find('.function-collapsed')).to.have.length(1); | ||
expect( | ||
wrapper.find('.rjv-function-container').prop('aria-expanded') | ||
).to.equal(false); | ||
|
||
wrapper | ||
.find('.rjv-function-container') | ||
.simulate('keydown', { key: 'Enter' }); | ||
|
||
expect(wrapper.find('.function-collapsed')).to.have.length(0); | ||
expect( | ||
wrapper.find('.rjv-function-container').prop('aria-expanded') | ||
).to.equal(true); | ||
}); | ||
}); |
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
Oops, something went wrong.