1+ /*
2+ * Copyright 2019, GeoSolutions Sas.
3+ * All rights reserved.
4+ *
5+ * This source code is licensed under the BSD-style license found in the
6+ * LICENSE file in the root directory of this source tree.
7+ */
8+
19import React from 'react' ;
2- const ReactDOM = require ( 'react-dom' ) ;
3- const expect = require ( 'expect' ) ;
10+ import ReactDOM from 'react-dom' ;
11+ import expect from 'expect' ;
412import Content from '../Content' ;
513import STORY from 'json-loader!../../../../test-resources/geostory/sampleStory_1.json' ;
6-
14+ const SCROLLABLE_CONTAINER_ID = "TEST_SCROLLABLE_CONTAINER" ;
15+ const TestScrollableContainer = ( { children, height } ) => < div id = { SCROLLABLE_CONTAINER_ID } style = { { height, overflowY : "auto" } } > { children } </ div > ;
716describe ( 'Content component' , ( ) => {
817 beforeEach ( ( done ) => {
918 document . body . innerHTML = '<div id="container"></div>' ;
@@ -17,12 +26,28 @@ describe('Content component', () => {
1726 it ( 'Content rendering with defaults' , ( ) => {
1827 ReactDOM . render ( < Content /> , document . getElementById ( "container" ) ) ;
1928 const container = document . getElementById ( 'container' ) ;
20- expect ( container . querySelector ( '.ms-geostory- content-unknown' ) ) . toExist ( ) ;
29+ expect ( container . querySelector ( '.ms-content-unknown' ) ) . toExist ( ) ;
2130 } ) ;
2231 it ( 'Content rendering known type (text)' , ( ) => {
2332 ReactDOM . render ( < Content { ...STORY . sections [ 0 ] . contents [ 0 ] } /> , document . getElementById ( "container" ) ) ;
2433 const container = document . getElementById ( 'container' ) ;
25- const el = container . querySelector ( '.ms-geostory- content-text' ) ;
34+ const el = container . querySelector ( '.ms-content-text' ) ;
2635 expect ( el ) . toExist ( ) ;
2736 } ) ;
37+ it ( 'content has intersection observer' , ( done ) => {
38+ const ID_1 = "ID_1" ;
39+ const ID_2 = "ID_2" ;
40+ ReactDOM . render ( ( < TestScrollableContainer height = "100" >
41+ < Content id = { ID_1 } type = "text" height = { 100 } />
42+ < Content id = { ID_2 } onVisibilityChange = { ( { id, visible } ) => {
43+ expect ( id ) . toBe ( ID_2 ) ;
44+ expect ( visible ) . toBe ( true ) ;
45+ done ( ) ;
46+ } } type = "text" height = { 100 } />
47+ </ TestScrollableContainer > ) , document . getElementById ( "container" ) ) ;
48+ const container = document . getElementById ( 'container' ) ;
49+ const scrollable = container . querySelector ( `#${ SCROLLABLE_CONTAINER_ID } ` ) ;
50+ expect ( scrollable ) . toExist ( ) ;
51+ scrollable . scrollBy ( 0 , 120 ) ;
52+ } ) ;
2853} ) ;
0 commit comments