docbrown/app/javascript/githubRepos/__tests__/singleRepo.test.jsx
rhymes 81fff248dd
Refactoring GitHub Repos functionality - step 1 (#7764)
* Rename find_or_create to upsert and improve validation and testing

* Add User.authenticated_through?

* Refactor settings/integrations

* Refactor profile github repositories rendering

* Refactor repos fetching

* Only fetch a single repo and improve error messages

* Remove unused code

* Cleanups

* Fix specs

* Remove trailing whitespace

* Fix spec

* Trigger Travis
2020-05-12 13:48:19 +02:00

56 lines
1.5 KiB
JavaScript

import { h } from 'preact';
import { shallow } from 'preact-render-spy';
import render from 'preact-render-to-json';
import fetch from 'jest-fetch-mock';
import { SingleRepo } from '../singleRepo';
global.fetch = fetch;
describe('<SingleRepo />', () => {
describe('when it is not already featured', () => {
const subject = (
<SingleRepo
githubIdCode={123}
name="dev.to"
fork={false}
featured={false}
/>
);
it('should render and match the snapshot', () => {
const tree = render(subject);
expect(tree).toMatchSnapshot();
});
it('should have a state of { featured: false }', () => {
const context = shallow(subject);
expect(context.state()).toEqual({ featured: false });
});
});
describe('when it is featured', () => {
const subject = (
<SingleRepo githubIdCode={123} name="dev.to" fork={false} featured />
);
it('should render and match the snapshot', () => {
const tree = render(subject);
expect(tree).toMatchSnapshot();
});
it('should have a state of { featured: true }', () => {
const context = shallow(subject);
expect(context.state()).toEqual({ featured: true });
});
});
describe('when it is a fork', () => {
const subject = (
<SingleRepo githubIdCode={123} name="dev.to" fork featured={false} />
);
it('should render and match the snapshot', () => {
const tree = render(subject);
expect(tree).toMatchSnapshot();
});
});
});