@@ -3,51 +3,75 @@ import Article from "../Article"
33import Undernet from "undernet"
44import Prism from "prismjs"
55
6+ jest . mock ( "app/components/ScrollUpOnMount" , ( ) => global . simpleMock ( "ScrollUpOnMount" ) )
7+
68global . scrollTo = jest . fn ( )
79
8- jest . mock ( "undernet" , ( ) => ( {
9- start : jest . fn ( ) ,
10- stop : jest . fn ( ) ,
11- } ) )
10+ const components = [ "Tooltips" , "Accordions" , "Modals" , "Dropdowns" ]
11+
12+ components . forEach ( component => {
13+ Undernet [ component ] . start = jest . fn ( )
14+ Undernet [ component ] . stop = jest . fn ( )
15+ } )
1216
1317jest . mock ( "prismjs" , ( ) => ( {
1418 highlightAll : jest . fn ( ) ,
1519} ) )
1620
17- describe ( "<Article />" , ( ) => {
18- let wrapper
19- beforeEach ( ( ) => {
20- const md = "# Test header \n So neat"
21- wrapper = mount ( < Article > { md } </ Article > )
22- } )
23-
24- it ( "renders" , ( ) => {
25- expect ( wrapper ) . toMatchSnapshot ( )
26- } )
21+ const mountComponent = ( ) => {
22+ const md = "# Test header \n So neat"
23+ return mount ( < Article > { md } </ Article > )
24+ }
2725
28- it ( "calls window.scrollTo on mount" , ( ) => {
29- expect ( window . scrollTo ) . toHaveBeenCalledWith ( 0 , 0 )
30- } )
26+ describe ( "<Article />" , ( ) => {
27+ describe ( "#render" , ( ) => {
28+ it ( "renders" , ( ) => {
29+ // Given
30+ const wrapper = mountComponent ( )
31+ // Then
32+ expect ( wrapper ) . toMatchSnapshot ( )
33+ } )
3134
32- it ( "calls Prism.highlightAll on mount" , ( ) => {
33- expect ( Prism . highlightAll ) . toHaveBeenCalled ( )
35+ it ( "sets fadeIn class on wrapper on mount" , ( ) => {
36+ // Given
37+ const wrapper = mountComponent ( )
38+ // Then
39+ const fadeInClassIsPresent = wrapper
40+ . find ( "article" )
41+ . prop ( "className" )
42+ . includes ( "fadeIn" )
43+ expect ( fadeInClassIsPresent ) . toBe ( true )
44+ } )
3445 } )
3546
36- it ( "starts Undernet on mount" , ( ) => {
37- expect ( Undernet . start ) . toHaveBeenCalled ( )
38- } )
47+ describe ( "#componentDidMount" , ( ) => {
48+ it ( "calls Prism.highlightAll on mount" , ( ) => {
49+ // Given
50+ mountComponent ( )
51+ // Then
52+ expect ( Prism . highlightAll ) . toHaveBeenCalled ( )
53+ } )
3954
40- it ( "stops Undernet on unmount" , ( ) => {
41- wrapper . unmount ( )
42- expect ( Undernet . stop ) . toHaveBeenCalled ( )
55+ components . forEach ( component => {
56+ it ( `calls Undernet.${ component } .start` , ( ) => {
57+ // Given
58+ mountComponent ( )
59+ // Then
60+ expect ( Undernet [ component ] . start ) . toHaveBeenCalled ( )
61+ } )
62+ } )
4363 } )
4464
45- it ( "sets fadeIn class on wrapper on mount" , ( ) => {
46- expect (
47- wrapper
48- . find ( "article" )
49- . prop ( "className" )
50- . includes ( "fadeIn" )
51- ) . toBe ( true )
65+ describe ( "#componentWillUnmount" , ( ) => {
66+ components . forEach ( component => {
67+ it ( `calls Undernet.${ component } .stop` , ( ) => {
68+ // Given
69+ const wrapper = mountComponent ( )
70+ // When
71+ wrapper . unmount ( )
72+ // Then
73+ expect ( Undernet [ component ] . stop ) . toHaveBeenCalled ( )
74+ } )
75+ } )
5276 } )
5377} )
0 commit comments