@@ -5,8 +5,6 @@ import { image } from '../src/app/app-data';
55describe ( 'ImageLoader Lib E2E Tests' , function ( ) {
66 let page : AppPage ;
77
8- const browserWaitTimeout = 10000 ;
9-
108 beforeEach ( ( ) => {
119 page = new AppPage ( ) ;
1210 page . navigateTo ( ) ;
@@ -26,27 +24,30 @@ describe('ImageLoader Lib E2E Tests', function () {
2624 describe ( 'placeholder image' , ( ) => {
2725 beforeEach ( ( ) => page . setWindowSize ( 400 , 580 ) ) ;
2826
29- it ( 'should load placeholder image' , ( ) => {
30- expect ( page . getImageBottomElement ( ) . getAttribute ( 'src' ) ) . toEqual ( 'http://via.placeholder.com/40x40?text=placeholder' ) ;
27+ it ( 'should set src to placeholder image' , ( ) => {
28+ const result = page . getImageBottomElementSrc ( ) ;
29+ const expected = image . placeholder ;
30+ expect ( result ) . toEqual ( expected ) ;
3131 } ) ;
3232
33- it ( 'should update placeholder loaded boolean on init' , ( ) => {
34- expect ( page . getBottomPlaceholderBooleanElement ( ) . getText ( ) ) . toEqual ( 'true' ) ;
33+ it ( 'should set placeholder loaded text to true on init' , ( ) => {
34+ const result = page . getImageBottomPlaceholderLoadedElementText ( ) ;
35+ const expected = 'true' ;
36+ expect ( result ) . toEqual ( expected ) ;
3537 } ) ;
3638 } ) ;
3739
38- describe ( 'inviewport image on load' , ( ) => {
40+ describe ( 'image in viewport on page load' , ( ) => {
3941 beforeEach ( ( ) => page . setWindowSize ( 400 , 580 ) ) ;
4042
41- it ( 'should load full res image if image is in viewport on page load' , ( ) => {
42- browser . wait ( ( ) => page . getLoadedImageTopElement ( ) ) ;
43-
44- const imageLoaderCompClass = page . getImageTopLoaderComp ( ) . getAttribute ( 'class' ) ;
45- const imgSrc = page . getImageTopElement ( ) . getAttribute ( 'srcset' ) ;
46- expect ( imageLoaderCompClass ) . toContain ( 'sn-image-loaded' ) ;
47- expect ( imgSrc ) . toEqual ( 'http://via.placeholder.com/400x400?text=xs+1x 1x, http://via.placeholder.com/800x800?text=xs+2x 2x' ) ;
48-
43+ it ( 'should load image when in viewport on page load' , ( ) => {
44+ page . waitForImageTopElementLoaded ( ) ;
4945
46+ const resultLoaded = page . isImageTopLoaded ( ) ;
47+ const resultSrcset = page . getImageTopElementSrcSet ( ) ;
48+ const expectedSrcset = `${ image . images [ 0 ] . x1 } 1x, ${ image . images [ 0 ] . x2 } 2x` ;
49+ expect ( resultLoaded ) . toBeTruthy ( ) ;
50+ expect ( resultSrcset ) . toEqual ( expectedSrcset ) ;
5051 } ) ;
5152
5253 } ) ;
@@ -55,27 +56,28 @@ describe('ImageLoader Lib E2E Tests', function () {
5556 beforeEach ( ( ) => page . setWindowSize ( 400 , 580 ) ) ;
5657
5758 it ( 'should load image when scrolled into viewport' , ( ) => {
58- let imageLoaderCompClass = page . getImageBottomLoaderComp ( ) . getAttribute ( 'class' ) ;
59- let imgSrc = page . getImageBottomElement ( ) . getAttribute ( 'src' ) ;
60- expect ( imageLoaderCompClass ) . toContain ( 'sn-image-not-loaded' ) ;
61- expect ( imgSrc ) . toEqual ( 'http://via.placeholder.com/40x40?text=placeholder' ) ;
62-
63- page . scrollTo ( 0 , 580 * 2 ) ;
64- browser . wait ( ( ) => page . getLoadedImageBottomElement ( ) ) ;
65-
66- imageLoaderCompClass = page . getImageBottomLoaderComp ( ) . getAttribute ( 'class' ) ;
67- imgSrc = page . getImageBottomElement ( ) . getAttribute ( 'srcset' ) ;
68- expect ( imageLoaderCompClass ) . toContain ( 'sn-image-loaded' ) ;
69- expect ( imgSrc ) . toEqual ( 'http://via.placeholder.com/400x400?text=xs+1x 1x, http://via.placeholder.com/800x800?text=xs+2x 2x' ) ;
59+ let resultLoaded = page . isImageBottomLoaded ( ) ;
60+ let expectedLoaded = false ;
61+ let resultSrc = page . getImageBottomElementSrc ( ) ;
62+ let expectedSrc = image . placeholder ;
63+ expect ( resultLoaded ) . toEqual ( expectedLoaded ) ;
64+ expect ( resultSrc ) . toEqual ( expectedSrc ) ;
65+
66+ page . scrollToImageBottomElement ( ) ;
67+
68+ resultLoaded = page . isImageBottomLoaded ( ) ;
69+ expectedLoaded = true ;
70+ resultSrc = page . getImageBottomElementSrc ( ) ;
71+ expectedSrc = image . images [ 0 ] . x1 ;
72+ expect ( resultLoaded ) . toEqual ( expectedLoaded ) ;
73+ expect ( resultSrc ) . toEqual ( expectedSrc ) ;
7074
7175 } ) ;
7276
73- it ( 'should update full res image event count scroll into viewport' , ( ) => {
74- expect ( page . getBottomFullResCountElement ( ) . getText ( ) ) . toEqual ( '0' ) ;
75-
76- page . scrollTo ( 0 , 580 * 2 ) ;
77- browser . wait ( ( ) => page . getLoadedImageBottomElement ( ) ) ;
78- expect ( page . getBottomFullResCountElement ( ) . getText ( ) ) . toEqual ( '1' ) ;
77+ it ( 'should update image loaded count element when image scrolled into viewport' , ( ) => {
78+ expect ( page . getImageBottomLoadedCountElementText ( ) ) . toEqual ( '0' ) ;
79+ page . scrollToImageBottomElement ( ) ;
80+ expect ( page . getImageBottomLoadedCountElementText ( ) ) . toEqual ( '1' ) ;
7981 } ) ;
8082
8183 } ) ;
@@ -84,48 +86,65 @@ describe('ImageLoader Lib E2E Tests', function () {
8486
8587 it ( 'should load correct image for "xs" device size' , ( ) => {
8688 page . setWindowSize ( 400 , 580 ) ;
87- page . scrollTo ( 0 , 580 * 2 ) ;
88- page . waitForImageBottomElementLoaded ( ) ;
89+ page . scrollToImageBottomElement ( ) ;
90+
91+ const resultLoaded = page . isImageBottomLoaded ( ) ;
92+ const expectedLoaded = true ;
93+ const resultSrcset = page . getImageBottomElementSrcSet ( ) ;
94+ const expectedSrcset = `${ image . images [ 0 ] . x1 } 1x, ${ image . images [ 0 ] . x2 } 2x` ;
8995
90- expect ( page . getLoadedImageBottomElement ( ) ) . toBeTruthy ( ) ;
91- expect ( page . getImageBottomElementSrcSet ( ) ) . toEqual ( ` ${ image . images [ 0 ] . x1 } 1x, ${ image . images [ 0 ] . x2 } 2x` ) ;
96+ expect ( resultLoaded ) . toEqual ( expectedLoaded ) ;
97+ expect ( resultSrcset ) . toEqual ( expectedSrcset ) ;
9298 } ) ;
9399
94100 it ( 'should load correct image for "md" device size' , ( ) => {
95101 page . setWindowSize ( 768 , 580 ) ;
96- page . scrollTo ( 0 , 580 * 2.5 ) ;
97- page . waitForImageBottomElementLoaded ( ) ;
102+ page . scrollToImageBottomElement ( ) ;
98103
99- expect ( page . getLoadedImageBottomElement ( ) ) . toBeTruthy ( ) ;
100- expect ( page . getImageBottomElementSrcSet ( ) ) . toEqual ( `${ image . images [ 1 ] . x1 } 1x, ${ image . images [ 1 ] . x2 } 2x` ) ;
104+ const resultLoaded = page . isImageBottomLoaded ( ) ;
105+ const expectedLoaded = true ;
106+ const resultSrcset = page . getImageBottomElementSrcSet ( ) ;
107+ const expectedSrcset = `${ image . images [ 1 ] . x1 } 1x, ${ image . images [ 1 ] . x2 } 2x` ;
108+
109+ expect ( resultLoaded ) . toEqual ( expectedLoaded ) ;
110+ expect ( resultSrcset ) . toEqual ( expectedSrcset ) ;
101111 } ) ;
102112
103113 it ( 'should load correct image for "lg" device size' , ( ) => {
104114 page . setWindowSize ( 1024 , 580 ) ;
105- page . scrollTo ( 0 , 580 * 2.5 ) ;
106- page . waitForImageBottomElementLoaded ( ) ;
115+ page . scrollToImageBottomElement ( ) ;
116+
117+ const resultLoaded = page . isImageBottomLoaded ( ) ;
118+ const expectedLoaded = true ;
119+ const resultSrcset = page . getImageBottomElementSrcSet ( ) ;
120+ const expectedSrcset = `${ image . images [ 2 ] . x1 } 1x, ${ image . images [ 2 ] . x2 } 2x` ;
107121
108- expect ( page . getLoadedImageBottomElement ( ) ) . toBeTruthy ( ) ;
109- expect ( page . getImageBottomElementSrcSet ( ) ) . toEqual ( ` ${ image . images [ 2 ] . x1 } 1x, ${ image . images [ 2 ] . x2 } 2x` ) ;
122+ expect ( resultLoaded ) . toEqual ( expectedLoaded ) ;
123+ expect ( resultSrcset ) . toEqual ( expectedSrcset ) ;
110124 } ) ;
111125
112126 it ( 'should update image loaded event count on window resize when image in viewport' , ( ) => {
113- expect ( page . getBottomFullResCountElement ( ) . getText ( ) ) . toEqual ( '0' ) ;
127+ let result = page . getImageBottomLoadedCountElementText ( ) ;
128+ let expected = '0' ;
129+ expect ( result ) . toEqual ( expected ) ;
114130
115131 page . setWindowSize ( 400 , 580 ) ;
116- page . scrollTo ( 0 , 580 * 2.5 ) ;
117- page . waitForImageBottomElementLoaded ( ) ;
118- expect ( page . getBottomFullResCountElement ( ) . getText ( ) ) . toEqual ( '1' ) ;
132+ page . scrollToImageBottomElement ( ) ;
133+ result = page . getImageBottomLoadedCountElementText ( ) ;
134+ expected = '1' ;
135+ expect ( result ) . toEqual ( expected ) ;
119136
120137 page . setWindowSize ( 768 , 580 ) ;
121- page . scrollTo ( 0 , 580 * 3 ) ;
122- page . waitForImageBottomElementLoaded ( ) ;
123- expect ( page . getBottomFullResCountElement ( ) . getText ( ) ) . toEqual ( '2' ) ;
138+ page . scrollToImageBottomElement ( ) ;
139+ result = page . getImageBottomLoadedCountElementText ( ) ;
140+ expected = '2' ;
141+ expect ( result ) . toEqual ( expected ) ;
124142
125143 page . setWindowSize ( 1024 , 580 ) ;
126- page . scrollTo ( 0 , 580 * 3 ) ;
127- page . waitForImageBottomElementLoaded ( ) ;
128- expect ( page . getBottomFullResCountElement ( ) . getText ( ) ) . toEqual ( '3' ) ;
144+ page . scrollToImageBottomElement ( ) ;
145+ result = page . getImageBottomLoadedCountElementText ( ) ;
146+ expected = '3' ;
147+ expect ( result ) . toEqual ( expected ) ;
129148 } ) ;
130149
131150 } ) ;
0 commit comments