Skip to content

Commit 49ebedb

Browse files
committed
fixed jest unit tests
1 parent cb5b43a commit 49ebedb

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

__tests__/shared/components/__snapshots__/Content.jsx.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,19 @@ exports[`Matches shallow shapshot 1`] = `
374374
</code>
375375
.
376376
</li>
377+
<li>
378+
<Link
379+
replace={false}
380+
to="/examples/tags/"
381+
>
382+
Tags
383+
</Link>
384+
- Demo/test of standard tags already available in the code, and customizable with help of
385+
<code>
386+
react-css-themr
387+
</code>
388+
.
389+
</li>
377390
<li>
378391
<Link
379392
replace={false}

__tests__/shared/components/challenge-listing/ChallengeCard/index.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React from 'react';
2+
import ReactDOM from 'react-dom';
23
import Renderer from 'react-test-renderer/shallow';
34
import TU from 'react-dom/test-utils';
45
import ChallengeCard from 'components/challenge-listing/ChallengeCard';
56
import MockDate from 'mockdate';
67
import { Provider } from 'react-redux';
78
import mockReduxStore from 'redux-mock-store';
9+
import { Tag } from 'components/tags';
810

911
const store = mockReduxStore()();
1012

@@ -152,16 +154,16 @@ describe('render properly', () => {
152154

153155
test('click', () => {
154156
instance = TU.renderIntoDocument((<Wrapper {...mockData4} />));
155-
const tags = TU.findAllInRenderedTree(instance, item =>
156-
item && item.className && item.className.match('technology'));
157-
expect(tags).toHaveLength(4);
158-
TU.Simulate.click(tags[0]);
157+
const tags = TU.scryRenderedComponentsWithType(instance, Tag);
158+
const el = ReactDOM.findDOMNode(tags[0]);
159+
expect(tags).toHaveLength(4);
160+
TU.Simulate.click(el);
159161
});
160162

161163
test('click + tag', () => {
162164
instance = TU.renderIntoDocument((<Wrapper {...mockData5} />));
163-
const tags = TU.findAllInRenderedTree(instance, item =>
164-
item && item.className && item.className.match('technology'));
165-
TU.Simulate.click(tags[0]);
165+
const tags = TU.scryRenderedComponentsWithType(instance, Tag);
166+
const el = ReactDOM.findDOMNode(tags[0]);
167+
TU.Simulate.click(el);
166168
});
167169
});

__tests__/shared/components/challenge-listing/Listing/Bucket.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React from 'react';
2+
import ReactDOM from 'react-dom';
23
import _ from 'lodash';
34
import Renderer from 'react-test-renderer/shallow';
45
import TU from 'react-dom/test-utils';
56
import Bucket from 'components/challenge-listing/Listing/Bucket';
67
import reduxStoreFactory from 'redux-mock-store';
78
import { Provider } from 'react-redux';
9+
import { Tag } from 'components/tags';
810

911
const store = reduxStoreFactory()();
1012

@@ -176,14 +178,13 @@ class Wrapper extends React.Component {
176178
const instance = TU.renderIntoDocument((<Wrapper {...mockDatas[0]} />));
177179

178180
test('setFilterState', () => {
179-
const matches = TU.findAllInRenderedTree(instance, item =>
180-
item && item.className && item.className.match('technology'));
181+
const matches = TU.scryRenderedComponentsWithType(instance, Tag);
181182
expect(matches).toHaveLength(3);
182-
TU.Simulate.click(matches[0]);
183+
TU.Simulate.click(ReactDOM.findDOMNode(matches[0]));
183184
expect(setFilterState).toHaveBeenCalledTimes(1);
184-
TU.Simulate.click(matches[1]);
185+
TU.Simulate.click(ReactDOM.findDOMNode(matches[1]));
185186
expect(setFilterState).toHaveBeenCalledTimes(2);
186-
TU.Simulate.click(matches[2]);
187+
TU.Simulate.click(ReactDOM.findDOMNode(matches[2]));
187188
expect(setFilterState).toHaveBeenCalledTimes(3);
188189
});
189190

src/shared/components/challenge-listing/ChallengeCard/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class Tags extends React.Component {
232232
<Tag
233233
onClick={() => this.onClick(c.trim())}
234234
key={c}
235+
role="button"
235236
>{c}</Tag>
236237
));
237238
}

src/shared/components/tags/index.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export function GenericTag({
1616
onClick,
1717
openNewTab,
1818
replace,
19+
role,
20+
tabIndex,
1921
theme,
2022
to,
2123
}) {
@@ -35,8 +37,8 @@ export function GenericTag({
3537
<a
3638
className={`${theme.tag}`}
3739
onClick={onClick}
38-
role="button"
39-
tabIndex={0}
40+
role={role}
41+
tabIndex={tabIndex}
4042
>{children}</a>
4143
);
4244
}
@@ -47,6 +49,8 @@ GenericTag.defaultProps = {
4749
onClick: null,
4850
openNewTab: false,
4951
replace: false,
52+
role: "button",
53+
tabIndex: 0,
5054
to: null,
5155
};
5256

@@ -56,6 +60,8 @@ GenericTag.propTypes = {
5660
onClick: PT.func,
5761
openNewTab: PT.bool,
5862
replace: PT.bool,
63+
role: PT.string,
64+
tabIndex: PT.number,
5965
theme: PT.shape({
6066
tag: PT.string.isRequired,
6167
}).isRequired,

0 commit comments

Comments
 (0)