1
+ jest . autoMockOff ( ) ;
2
+
3
+ import React from 'react' ;
4
+ import ReactDOM from 'react-dom' ;
5
+ import TestUtils from 'react-addons-test-utils' ;
6
+
7
+ const Detail = require ( '../src/components/Detail/Detail' ) . default ;
8
+
9
+ describe ( 'Detail' , ( ) => {
10
+ // tests go here
11
+ it ( 'starts with zero commits' , ( ) => {
12
+ const rendered = TestUtils . renderIntoDocument (
13
+ < Detail params = { { repo : '' } } />
14
+ ) ;
15
+
16
+ expect ( rendered . state . commits . length ) . toEqual ( 0 ) ;
17
+ } ) ;
18
+
19
+ it ( 'shows commits by default' , ( ) => {
20
+ const rendered = TestUtils . renderIntoDocument (
21
+ < Detail params = { { repo : '' } } />
22
+ ) ;
23
+
24
+ expect ( rendered . state . mode ) . toEqual ( 'commits' ) ;
25
+ } ) ;
26
+
27
+ it ( 'shows forks when the button is tapped' , ( ) => {
28
+ const rendered = TestUtils . renderIntoDocument (
29
+ < Detail params = { { repo : '' } } />
30
+ ) ;
31
+
32
+ const btns = TestUtils . scryRenderedDOMComponentsWithTag ( rendered , 'button' ) ;
33
+ const forksButton = btns [ 1 ] ;
34
+ TestUtils . Simulate . click ( forksButton ) ;
35
+ expect ( rendered . state . mode ) . toEqual ( 'forks' ) ;
36
+ } ) ;
37
+
38
+ it ( 'fetches forks from Github' , ( ) => {
39
+ const rendered = TestUtils . renderIntoDocument (
40
+ < Detail params = { { repo : 'react' } } />
41
+ ) ;
42
+
43
+ beforeEach ( ( ) => {
44
+ if ( rendered . state . forks . length > 0 ) {
45
+ console . log ( 'Waiting for forks: ' + rendered . state . forks . length ) ;
46
+ done ( ) ;
47
+ }
48
+ } , "commits to be set" , 2000 ) ;
49
+
50
+ afterEach ( ( ) => {
51
+ expect ( rendered . state . forks . length ) . toEqual ( 30 ) ;
52
+ } ) ;
53
+ } ) ;
54
+
55
+ } ) ;
0 commit comments