docbrown/app/javascript/githubRepos/__tests__/singleRepo.test.jsx
Andy Zhao ebd4b50f3f Use Preact for asynchronous rendering for /settings/integrations (#986)
* Set default styles and move button style out of form

* Add MVP of Preact /settings/integrations

* Change background color on hover and focus

* Remove unused constructor

* Improve optimistic rendering

* Add display name

* Use loading indicator for optimistic rendering

* WIP test

* Add basic snapshot tests
2018-10-31 15:51:07 -04: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 selected', () => {
const subject = (
<SingleRepo
githubIdCode={123}
name="dev.to"
fork={false}
selected={false}
/>
);
it('should render and match the snapshot', () => {
const tree = render(subject);
expect(tree).toMatchSnapshot();
});
it('should have a state of { selected: false }', () => {
const context = shallow(subject);
expect(context.state()).toEqual({ selected: false });
});
});
describe('when it is selected', () => {
const subject = (
<SingleRepo githubIdCode={123} name="dev.to" fork={false} selected />
);
it('should render and match the snapshot', () => {
const tree = render(subject);
expect(tree).toMatchSnapshot();
});
it('should have a state of { selected: true }', () => {
const context = shallow(subject);
expect(context.state()).toEqual({ selected: true });
});
});
describe('when it is a fork', () => {
const subject = (
<SingleRepo githubIdCode={123} name="dev.to" fork selected={false} />
);
it('should render and match the snapshot', () => {
const tree = render(subject);
expect(tree).toMatchSnapshot();
});
});
});