summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2017-12-19 10:31:24 +0100
committerAndrej Mihajlov <and@mullvad.net>2017-12-19 10:31:24 +0100
commit383a48638198accef99e987cd3297283ed25398b (patch)
tree4e1f1c3e0b6421d36d2c6ab159f9adc1b4e33d5d /test
parentf5d2f70b62f435f85f1f3bc1ded25e101d145442 (diff)
parentd2a472b0aee0822277c1b9ae3b6bba18beb51697 (diff)
downloadmullvadvpn-383a48638198accef99e987cd3297283ed25398b.tar.xz
mullvadvpn-383a48638198accef99e987cd3297283ed25398b.zip
Merge branch 'add-accordion'
Diffstat (limited to 'test')
-rw-r--r--test/components/Accordion.spec.js96
1 files changed, 96 insertions, 0 deletions
diff --git a/test/components/Accordion.spec.js b/test/components/Accordion.spec.js
new file mode 100644
index 0000000000..2357e27dfc
--- /dev/null
+++ b/test/components/Accordion.spec.js
@@ -0,0 +1,96 @@
+// @flow
+/* eslint react/no-find-dom-node: off */
+
+import { expect } from 'chai';
+import React from 'react';
+import ReactDOM from 'react-dom';
+import Accordion from '../../app/components/Accordion';
+
+import type { AccordionProps } from '../../app/components/Accordion';
+
+describe('components/Accordion', () => {
+
+ let container: ?HTMLElement;
+
+ function renderIntoDocument(instance: React.Element<AccordionProps>) {
+ if(!container) {
+ container = document.createElement('div');
+ if(!document.documentElement) {
+ throw new Error('document.documentElement cannot be null.');
+ }
+ document.documentElement.appendChild(container);
+ }
+ return ReactDOM.render(instance, container);
+ }
+
+ // unmount container and clean up DOM
+ afterEach(() => {
+ if(container) {
+ ReactDOM.unmountComponentAtNode(container);
+ container = null;
+ }
+ });
+
+ it('should be collapsed upon mount', () => {
+ const component = renderIntoDocument(
+ <Accordion height={ 0 }>
+ <div style={{ height: 100 }}></div>
+ </Accordion>
+ );
+ const domNode = ReactDOM.findDOMNode(component);
+ expect(domNode).to.have.property('clientHeight', 0);
+ });
+
+ it('should be expanded to provided height upon mount', () => {
+ const component = renderIntoDocument(
+ <Accordion height={ 100 } />
+ );
+ const domNode = ReactDOM.findDOMNode(component);
+ expect(domNode).to.have.property('clientHeight', 100);
+ });
+
+ it('should be expanded using layout upon mount', () => {
+ const component = renderIntoDocument(
+ <Accordion height={ 'auto' }>
+ <div style={{ height: 100 }}></div>
+ </Accordion>
+ );
+ const domNode = ReactDOM.findDOMNode(component);
+ expect(domNode).to.have.property('clientHeight', 100);
+ });
+
+ it('should collapse', () => {
+ const component = renderIntoDocument(
+ <Accordion height={ 'auto' }>
+ <div style={{ height: 100 }}></div>
+ </Accordion>
+ );
+
+ renderIntoDocument(
+ <Accordion height={ 0 } transitionStyle="none">
+ <div style={{ height: 100 }}></div>
+ </Accordion>
+ );
+
+ const domNode = ReactDOM.findDOMNode(component);
+ expect(domNode).to.have.property('clientHeight', 0);
+ });
+
+ it('should expand', () => {
+ const component = renderIntoDocument(
+ <Accordion height={ 0 }>
+ <div style={{ height: 100 }}></div>
+ </Accordion>
+ );
+
+ renderIntoDocument(
+ <Accordion height="auto" transitionStyle="none">
+ <div style={{ height: 100 }}></div>
+ </Accordion>
+ );
+
+ const domNode = ReactDOM.findDOMNode(component);
+ expect(domNode).to.have.property('clientHeight', 100);
+ });
+
+}); \ No newline at end of file