Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
test: add unit tests for github user organism (#70)
Browse files Browse the repository at this point in the history
* fix: render label instead of children in github user keyword highlight

* test: add unit tests for github user highlights

* test: add unit test for github user organism

Because of inline render functions being used, we have to compare the actual HTML instead of validating the component with `.find()`...
  • Loading branch information
byCedric committed Oct 20, 2018
1 parent 84eb513 commit 4023dc1
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/organisms/github-user/github-user.test.js
@@ -0,0 +1,36 @@
import React from 'react';
import { mount } from 'enzyme';
import UserMolecule from 'src/molecules/user';
import GithubUser from './github-user';
import highlights from './highlights';

const data = {
name: 'Cedric van Putten',
login: 'byCedric',
avatar_url: 'https://github.com/bycedric.png',
bio: 'Lead developer @Peakfijn.',
};

describe('organisms/github-user/github-user', () => {
it('renders the user molecule component', async () => {
const promise = Promise.resolve({ json: () => data });

global.fetch = jest.fn().mockReturnValue(promise);

const parentComponent = mount(<GithubUser />);
const childComponent = mount(
<UserMolecule
name={data.name}
username={data.login}
avatarUrl={data.avatar_url}
description={data.bio}
highlights={highlights}
/>
);

await promise;

// because of the inline render function we can't use `.find()`
expect(parentComponent.html()).toContain(childComponent.html());
});
});
2 changes: 1 addition & 1 deletion src/organisms/github-user/highlights/keyword.js
Expand Up @@ -5,7 +5,7 @@ import { GithubUserKeywordHighlight } from '../elements';
export default function GithubUserOrganismKeyword(props) {
return (
<GithubUserKeywordHighlight>
{props.children}
{props.label}
</GithubUserKeywordHighlight>
);
}
Expand Down
21 changes: 21 additions & 0 deletions src/organisms/github-user/highlights/keywords.test.js
@@ -0,0 +1,21 @@
import React from 'react';
import { mount } from 'enzyme';
import HighlightKeyword from './keyword';

describe('organisms/github-user/highlights/keyword', () => {
it('renders a simple element with keyword', () => {
const component = mount(
<HighlightKeyword label='#repo' />
);

expect(component).toHaveText('#repo');
});

it('defines a (partial) decorator for "#" character', () => {
const component = mount(
HighlightKeyword.decorator['#']('match', 'text', '1337')
);

expect(component).toHaveText('text');
});
});
29 changes: 29 additions & 0 deletions src/organisms/github-user/highlights/mention.test.js
@@ -0,0 +1,29 @@
import React from 'react';
import { mount } from 'enzyme';
import HighlightMention from './mention';

describe('organisms/github-user/highlights/mention', () => {
it('renders a link element with github link', () => {
const component = mount(
<HighlightMention
label='@byCedric'
username='byCedric'
/>
);

expect(component.find('a'))
.toHaveText('@byCedric')
.toMatchSelector('[href="https://github.com/byCedric"]')
.toMatchSelector('[target="_blank"]');
});

it('defines a (partial) decorator for "@" character', () => {
const component = mount(
HighlightMention.decorator['@']('match', 'text', '1337')
);

expect(component.find('a'))
.toHaveText('match')
.toMatchSelector('[href="https://github.com/text"]');
});
});

0 comments on commit 4023dc1

Please sign in to comment.