<commit_before>import React from 'react';
import { shallow } from 'enzyme';
import { assert } from 'chai';

import TreeNode from '../src/js/TreeNode';

describe('<TreeNode />', () => {
	describe('component', () => {
		it('should render the rct-node container', () => {
			const wrapper = shallow(
				<TreeNode
					checked={0}
					expanded={false}
					label="Europa"
					optimisticToggle
					treeId="id"
					value="europa"
					onCheck={() => {}}
					onExpand={() => {}}
				/>,
			);

			assert.isTrue(wrapper.find('.rct-node').exists());
		});
	});

	describe('label', () => {
		it('should render the node\'s label', () => {
			const wrapper = shallow(
				<TreeNode
					checked={0}
					expanded={false}
					label="Europa"
					optimisticToggle
					treeId="id"
					value="europa"
					onCheck={() => {}}
					onExpand={() => {}}
				/>,
			);

			assert.isTrue(wrapper.contains(
				<span className="rct-title">Europa</span>,
			));
		});
	});

	describe('expanded', () => {
		it('should render children when set to true', () => {
			const wrapper = shallow(
				<TreeNode
					checked={0}
					expanded
					label="Jupiter"
					optimisticToggle
					rawChildren={[{ value: 'europa', label: 'Europa' }]}
					treeId="id"
					value="jupiter"<commit_msg>Add tests for TreeNode.props.checked<commit_after>import React from 'react';
import { shallow } from 'enzyme';
import { assert } from 'chai';

import TreeNode from '../src/js/TreeNode';

const baseProps = {
	checked: 0,
	expanded: false,
	label: 'Jupiter',
	optimisticToggle: true,
	treeId: 'id',
	value: 'jupiter',
	onCheck: () => {},
	onExpand: () => {},
};

describe('<TreeNode />', () => {
	describe('component', () => {
		it('should render the rct-node container', () => {
			const wrapper = shallow(
				<TreeNode
					checked={0}
					expanded={false}
					label="Europa"
					optimisticToggle
					treeId="id"
					value="europa"
					onCheck={() => {}}
					onExpand={() => {}}
				/>,
			);

			assert.isTrue(wrapper.find('.rct-node').exists());
		});
	});

	describe('label', () => {
		it('should render the node\'s label', () => {
			const wrapper = shallow(
				<TreeNode
					checked={0}
					expanded={false}
					label="Europa"
					optimisticToggle
					treeId="id"
					value="europa"
					onCheck={() => {}}
					onExpand={() => {}}
				/>,
			);

			assert.isTrue(wrapper.contains(
				<span className="rct-title">Europa</span>,
			));
		});
	});

	describe('checked', () => {
		it('should render icons associated with each check state', () => {
			const iconMap = {
				0: <i className="fa fa-square-o" />,
				1: <i className="fa fa-check-square-o" />,
				2: <i className="fa fa-check-square-o rct-half-checked" />,
			};

			Object.keys(iconMap).forEach((state) => {
				const wrapper = shallow(
					<TreeNode {...baseProps} checked={parseInt(state, 10)} />,
				);

				assert.isTrue(wrapper.contains(iconMap[state]));
			});
		});

		it('should render an unchecked input element when not set to 1', () => {
			const wrapper1 = shallow(
				<TreeNode {...baseProps} checked={0} />,
			);
			const wrapper2 = shallow(
				<TreeNode {...baseProps} checked={2} />,
			);

			assert.isFalse(wrapper1.find('input[type="checkbox"]').prop('checked'));
			assert.isFalse(wrapper2.find('input[type="checkbox"]').prop('checked'));
		});

		it('should render a checked input element when set to 1', () => {
			const wrapper = shallow(
				<TreeNode {...baseProps} checked={1} />,
			);

			assert.isTrue(wrapper.find('input[type="checkbox"]').prop('checked'));
		});
	});

	describe('expanded', () => {
		it('should render children when set to true', () => {
			const wrapper = shallow(
				<TreeNode
					checked={0}
					expanded
					label="Jupiter"
					optimisticToggle
					rawChildren={[{ value: 'europa', label: 'Europa' }]}
					treeId="id"
					value="jupiter"
{'fraction_non_alphanumeric': 0.19880612509732676, 'fraction_numerical': 0.005450298468725669, 'mean_word_length': 3.0440713536201467, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2080839', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1275, 'n_words': 253}