@@ -4,6 +4,8 @@ import { browser } from 'protractor';
44describe ( 'ImageLoader Lib E2E Tests' , function ( ) {
55 let page : AppPage ;
66
7+ const browserWaitTimeout = 10000 ;
8+
79 beforeEach ( ( ) => page = new AppPage ( ) ) ;
810
911 beforeEach ( ( ) => page . navigateTo ( ) ) ;
@@ -16,6 +18,18 @@ describe('ImageLoader Lib E2E Tests', function () {
1618 } ) ;
1719 } ) ;
1820
21+ describe ( 'placeholder image' , ( ) => {
22+ beforeEach ( ( ) => page . setWindowSize ( 300 , 580 ) ) ;
23+
24+ it ( 'should load placeholder image' , ( ) => {
25+ expect ( page . getImageElement ( ) . getAttribute ( 'src' ) ) . toEqual ( 'http://via.placeholder.com/35x15?text=placeholder' ) ;
26+ } ) ;
27+
28+ it ( 'should update placeholder loaded boolean on init' , ( ) => {
29+ expect ( page . getplaceholderBooleanElement ( ) . getText ( ) ) . toEqual ( 'true' ) ;
30+ } ) ;
31+ } ) ;
32+
1933 describe ( 'lazy load image' , ( ) => {
2034 beforeEach ( ( ) => page . setWindowSize ( 300 , 580 ) ) ;
2135
@@ -25,34 +39,94 @@ describe('ImageLoader Lib E2E Tests', function () {
2539 expect ( imageLoaderCompClass ) . toContain ( 'sn-image-not-loaded' ) ;
2640 expect ( imgSrc ) . toEqual ( 'http://via.placeholder.com/35x15?text=placeholder' ) ;
2741
28- page . scrollTo ( 0 , 580 * 1.5 ) ;
42+ page . scrollTo ( 0 , 580 * 1.5 )
43+ . then ( ( ) => {
44+ browser . wait ( ( ) => page . getLoadedImageElement ( ) ) ;
45+ } ) ;
46+
2947 imageLoaderCompClass = page . getImageLoaderComp ( ) . getAttribute ( 'class' ) ;
3048 imgSrc = page . getImageElement ( ) . getAttribute ( 'srcset' ) ;
3149 expect ( imageLoaderCompClass ) . toContain ( 'sn-image-loaded' ) ;
3250 expect ( imgSrc ) . toEqual ( 'http://via.placeholder.com/150x350?text=xs+1x 1x, http://via.placeholder.com/300x700?text=xs+2x 2x' ) ;
51+
52+ } ) ;
53+
54+ it ( 'should update full res image event count on when in viewport' , ( ) => {
55+ expect ( page . getFullResCountElement ( ) . getText ( ) ) . toEqual ( '0' ) ;
56+
57+ page . scrollTo ( 0 , 580 * 1.5 )
58+ . then ( ( ) => {
59+ browser . wait ( ( ) => page . getLoadedImageElement ( ) ) ;
60+ } ) ;
61+
62+ expect ( page . getFullResCountElement ( ) . getText ( ) ) . toEqual ( '1' ) ;
3363 } ) ;
64+
3465 } ) ;
3566
3667 describe ( 'responsive image' , ( ) => {
3768 beforeEach ( ( ) => page . setWindowSize ( 300 , 580 ) ) ;
3869
3970 it ( 'should load correct image for device size' , ( ) => {
40- page . scrollTo ( 0 , 580 * 1.5 ) ;
71+ page . scrollTo ( 0 , 580 * 1.5 )
72+ . then ( ( ) => {
73+ browser . wait ( ( ) => page . getLoadedImageElement ( ) ) ;
74+ } ) ;
4175
4276 const imageLoaderCompClass = page . getImageLoaderComp ( ) . getAttribute ( 'class' ) ;
4377 let imgSrc = page . getImageElement ( ) . getAttribute ( 'srcset' ) ;
44-
4578 expect ( imageLoaderCompClass ) . toContain ( 'sn-image-loaded' ) ;
4679 expect ( imgSrc ) . toEqual ( 'http://via.placeholder.com/150x350?text=xs+1x 1x, http://via.placeholder.com/300x700?text=xs+2x 2x' ) ;
4780
48- page . setWindowSize ( 768 , 580 ) ;
81+ page . setWindowSize ( 768 , 580 )
82+ . then ( ( ) => {
83+ browser . wait ( ( ) => page . getLoadedImageElementBySrcSet (
84+ 'http://via.placeholder.com/350x250?text=md+1x 1x, http://via.placeholder.com/700x500?text=md+2x 2x'
85+ ) , browserWaitTimeout ) ;
86+ } ) ;
87+
4988 imgSrc = page . getImageElement ( ) . getAttribute ( 'srcset' ) ;
5089 expect ( imgSrc ) . toEqual ( 'http://via.placeholder.com/350x250?text=md+1x 1x, http://via.placeholder.com/700x500?text=md+2x 2x' ) ;
5190
52- page . setWindowSize ( 1024 , 580 ) ;
91+ page . setWindowSize ( 1024 , 580 )
92+ . then ( ( ) => {
93+ browser . wait ( ( ) => page . getLoadedImageElementBySrcSet (
94+ 'http://via.placeholder.com/700x400?text=lg+1x 1x, http://via.placeholder.com/1400x800?text=lg+2x 2x'
95+ ) , browserWaitTimeout ) ;
96+ } ) ;
97+
5398 imgSrc = page . getImageElement ( ) . getAttribute ( 'srcset' ) ;
5499 expect ( imgSrc ) . toEqual ( 'http://via.placeholder.com/700x400?text=lg+1x 1x, http://via.placeholder.com/1400x800?text=lg+2x 2x' ) ;
55100 } ) ;
101+
102+ it ( 'should update image loaded event count on window resize when image in viewport' , ( ) => {
103+ expect ( page . getFullResCountElement ( ) . getText ( ) ) . toEqual ( '0' ) ;
104+
105+ page . scrollTo ( 0 , 580 * 1.5 )
106+ . then ( ( ) => {
107+ browser . wait ( ( ) => page . getLoadedImageElement ( ) ) ;
108+ } ) ;
109+
110+ expect ( page . getFullResCountElement ( ) . getText ( ) ) . toEqual ( '1' ) ;
111+
112+ page . setWindowSize ( 768 , 580 )
113+ . then ( ( ) => {
114+ browser . wait ( ( ) => page . getLoadedImageElementBySrcSet (
115+ 'http://via.placeholder.com/350x250?text=md+1x 1x, http://via.placeholder.com/700x500?text=md+2x 2x'
116+ ) , browserWaitTimeout ) ;
117+ } ) ;
118+ expect ( page . getFullResCountElement ( ) . getText ( ) ) . toEqual ( '2' ) ;
119+
120+ page . setWindowSize ( 1024 , 580 )
121+ . then ( ( ) => {
122+ browser . wait ( ( ) => page . getLoadedImageElementBySrcSet (
123+ 'http://via.placeholder.com/700x400?text=lg+1x 1x, http://via.placeholder.com/1400x800?text=lg+2x 2x'
124+ ) , browserWaitTimeout ) ;
125+ } ) ;
126+ expect ( page . getFullResCountElement ( ) . getText ( ) ) . toEqual ( '3' ) ;
127+ } ) ;
128+
56129 } ) ;
130+
57131} ) ;
58132
0 commit comments