diff --git a/src/organisms/github-user/github-user.test.js b/src/organisms/github-user/github-user.test.js new file mode 100644 index 0000000..0114208 --- /dev/null +++ b/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(); + const childComponent = mount( + + ); + + await promise; + + // because of the inline render function we can't use `.find()` + expect(parentComponent.html()).toContain(childComponent.html()); + }); +}); diff --git a/src/organisms/github-user/highlights/keyword.js b/src/organisms/github-user/highlights/keyword.js index 095f950..3ff4f99 100644 --- a/src/organisms/github-user/highlights/keyword.js +++ b/src/organisms/github-user/highlights/keyword.js @@ -5,7 +5,7 @@ import { GithubUserKeywordHighlight } from '../elements'; export default function GithubUserOrganismKeyword(props) { return ( - {props.children} + {props.label} ); } diff --git a/src/organisms/github-user/highlights/keywords.test.js b/src/organisms/github-user/highlights/keywords.test.js new file mode 100644 index 0000000..d02479c --- /dev/null +++ b/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( + + ); + + expect(component).toHaveText('#repo'); + }); + + it('defines a (partial) decorator for "#" character', () => { + const component = mount( + HighlightKeyword.decorator['#']('match', 'text', '1337') + ); + + expect(component).toHaveText('text'); + }); +}); diff --git a/src/organisms/github-user/highlights/mention.test.js b/src/organisms/github-user/highlights/mention.test.js new file mode 100644 index 0000000..6dfd6c4 --- /dev/null +++ b/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( + + ); + + 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"]'); + }); +});