-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
209 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Specs hides cross 1`] = `"<div><div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">hide me 1</div><div>not me 2</div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\"><div>not me 3</div></div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">hide me 4</div><div aria-hidden=\\"true\\" data-aria-hidden=\\"true\\">I am already hidden! 5</div></div><div>dont touch me 6</div></div>"`; | ||
exports[`Specs hides cross 2`] = `"<div><div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">hide me 1</div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">not me 2</div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\"><div>not me 3</div></div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">hide me 4</div><div aria-hidden=\\"true\\" data-aria-hidden=\\"true\\">I am already hidden! 5</div></div><div>dont touch me 6</div></div>"`; | ||
exports[`Specs hides cross 3`] = `"<div><div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">hide me 1</div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">not me 2</div><div><div>not me 3</div></div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">hide me 4</div><div aria-hidden=\\"true\\" data-aria-hidden=\\"true\\">I am already hidden! 5</div></div><div>dont touch me 6</div></div>"`; | ||
exports[`Specs hides cross markers 1`] = `"<div><div><div aria-hidden=\\"true\\" marker2=\\"true\\">hide me 1</div><div marker2=\\"true\\" aria-hidden=\\"true\\">not me 2</div><div><div>not me 3</div></div><div aria-hidden=\\"true\\" marker2=\\"true\\">hide me 4</div><div aria-hidden=\\"true\\" marker2=\\"true\\">I am already hidden! 5</div></div><div>dont touch me 6</div></div>"`; | ||
exports[`Specs hides multiple 1`] = `"<div><div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">hide me 1</div><div>not me 2</div><div><div>not me 3</div></div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">hide me 4</div><div aria-hidden=\\"true\\" data-aria-hidden=\\"true\\">I am already hidden! 5</div></div><div>dont touch me 6</div></div>"`; | ||
exports[`Specs hides single 1`] = `"<div><div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">hide me 1</div><div>not me 2</div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\"><div>not me 3</div></div><div data-aria-hidden=\\"true\\" aria-hidden=\\"true\\">hide me 4</div><div aria-hidden=\\"true\\" data-aria-hidden=\\"true\\">I am already hidden! 5</div></div><div>dont touch me 6</div></div>"`; |
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,14 +1,132 @@ | ||
import * as React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
import {mount} from 'enzyme'; | ||
import {hideOthers} from "../src"; | ||
|
||
describe('Specs', () => { | ||
const setup = () => { | ||
const factory = () => { | ||
const parent = React.createRef<any>(); | ||
const target1 = React.createRef<any>(); | ||
const target2 = React.createRef<any>(); | ||
const targetOutside1 = React.createRef<any>(); | ||
const wrapper = mount( | ||
<div> | ||
<div ref={parent}> | ||
<div>hide me 1</div> | ||
<div ref={target1}>not me 2</div> | ||
<div> | ||
<div ref={target2}>not me 3</div> | ||
</div> | ||
<div ref={targetOutside1}>hide me 4</div> | ||
<div aria-hidden>I am already hidden! 5</div> | ||
</div> | ||
<div>dont touch me 6</div> | ||
</div> | ||
); | ||
const base = wrapper.html(); | ||
|
||
return { | ||
|
||
}; | ||
base, wrapper, | ||
parent, target1, target2, targetOutside1, | ||
} | ||
}; | ||
|
||
it('Foo', () => { | ||
expect(1).toEqual(1); | ||
|
||
const getNearestAttribute = (node, name, parent) => { | ||
const attr = node.getAttribute(name); | ||
if (attr) { | ||
return attr; | ||
} | ||
if (node === parent || !node.parentNode) { | ||
return null; | ||
} | ||
return getNearestAttribute(node.parentNode, name, parent) | ||
} | ||
|
||
it('hides single', () => { | ||
const { | ||
base, parent, target1, target2, targetOutside1, wrapper | ||
} = factory(); | ||
|
||
const unhide = hideOthers(target1.current, parent.current); | ||
expect(wrapper.update().html()).toMatchSnapshot(); | ||
|
||
expect(getNearestAttribute(target1.current, 'aria-hidden', parent)).toBe(null); | ||
expect(getNearestAttribute(target2.current, 'aria-hidden', parent)).toBe("true"); | ||
expect(getNearestAttribute(targetOutside1.current, 'aria-hidden', parent)).toBe("true"); | ||
|
||
unhide(); | ||
expect(wrapper.html()).toEqual(base); | ||
}); | ||
|
||
it('hides multiple', () => { | ||
const { | ||
base, parent, target1, target2, targetOutside1, wrapper | ||
} = factory(); | ||
|
||
const unhide = hideOthers([target1.current, target2.current], parent.current); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
|
||
expect(getNearestAttribute(target1.current, 'aria-hidden', parent)).toBe(null); | ||
expect(getNearestAttribute(target2.current, 'aria-hidden', parent)).toBe(null); | ||
expect(getNearestAttribute(targetOutside1.current, 'aria-hidden', parent)).toBe("true"); | ||
|
||
unhide(); | ||
expect(wrapper.html()).toEqual(base); | ||
}); | ||
|
||
it('hides cross', () => { | ||
const { | ||
base, parent, target1, target2, targetOutside1, wrapper | ||
} = factory(); | ||
|
||
const unhide1 = hideOthers(target1.current, parent.current); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
|
||
expect(getNearestAttribute(target1.current, 'aria-hidden', parent)).toBe(null); | ||
expect(getNearestAttribute(target2.current, 'aria-hidden', parent)).toBe("true"); | ||
expect(getNearestAttribute(targetOutside1.current, 'aria-hidden', parent)).toBe("true"); | ||
expect(getNearestAttribute(targetOutside1.current, 'data-aria-hidden', parent)).toBe("true"); | ||
|
||
const unhide2 = hideOthers(target2.current, parent.current); | ||
|
||
expect(getNearestAttribute(target1.current, 'aria-hidden', parent)).toBe("true"); | ||
expect(getNearestAttribute(target2.current, 'aria-hidden', parent)).toBe("true"); | ||
expect(getNearestAttribute(targetOutside1.current, 'aria-hidden', parent)).toBe("true"); | ||
expect(getNearestAttribute(targetOutside1.current, 'data-aria-hidden', parent)).toBe("true"); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
unhide1(); | ||
|
||
expect(getNearestAttribute(target1.current, 'aria-hidden', parent)).toBe("true"); | ||
expect(getNearestAttribute(target2.current, 'aria-hidden', parent)).toBe(null); | ||
expect(getNearestAttribute(targetOutside1.current, 'aria-hidden', parent)).toBe("true"); | ||
expect(getNearestAttribute(targetOutside1.current, 'data-aria-hidden', parent)).toBe("true"); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
unhide2(); | ||
|
||
expect(wrapper.html()).toEqual(base) | ||
}); | ||
|
||
it('hides cross markers', () => { | ||
const { | ||
base, parent, target1, target2, targetOutside1, wrapper | ||
} = factory(); | ||
|
||
const unhide1 = hideOthers(target1.current, parent.current, 'marker1'); | ||
expect(getNearestAttribute(targetOutside1.current, 'marker1', parent)).toBe("true"); | ||
|
||
const unhide2 = hideOthers(target2.current, parent.current, 'marker2'); | ||
|
||
expect(getNearestAttribute(targetOutside1.current, 'marker1', parent)).toBe("true"); | ||
expect(getNearestAttribute(targetOutside1.current, 'marker2', parent)).toBe("true"); | ||
|
||
unhide1(); | ||
|
||
expect(getNearestAttribute(targetOutside1.current, 'marker1', parent)).toBe(null); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
unhide2(); | ||
|
||
expect(wrapper.html()).toEqual(base) | ||
}); | ||
}); |
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