Skip to content

Commit

Permalink
Add e2e test for <amp-lightbox-gallery> (#22964)
Browse files Browse the repository at this point in the history
This simply opens/closes the gallery to make sure nothing major is
broken.
  • Loading branch information
Sepand Parhami committed Jun 24, 2019
1 parent 275968a commit 04fd845
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 15 deletions.
72 changes: 72 additions & 0 deletions extensions/amp-lightbox-gallery/0.1/test-e2e/test-open-close.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright 2019 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const pageWidth = 800;
const pageHeight = 600;

describes.endtoend(
'AMP Lightbox Gallery Open/Close',
{
testUrl:
'http://localhost:8000/test/manual/amp-lightbox-gallery-launch.amp.html',
initialRect: {width: pageWidth, height: pageHeight},
// TODO(sparhami) Get this working in other environments.
environments: ['single'],
},
async env => {
let controller;

function css(handle, name) {
return controller.getElementCssValue(handle, name);
}

function prop(el, name) {
return controller.getElementProperty(el, name);
}

beforeEach(async () => {
controller = env.controller;
});

// TODO(sparhami) Cover swipe to dismiss if possible.
// TODO(sparhami) Test basic transition to gallery and back.
it('should open/close lightbox', async () => {
// First open the gallery.
const firstAmpImg = await controller.findElement('amp-img');
await controller.click(firstAmpImg);

// Verify it opened.
const overlay = await controller.findElement('.i-amphtml-lbg-overlay');
const galleryButton = await controller.findElement(
'[data-action="gallery"]'
);
const closeButton = await controller.findElement('[data-action="close"]');
await expect(css(overlay, 'opacity')).to.equal('1');
await expect(css(galleryButton, 'opacity')).to.equal('1');
await expect(css(closeButton, 'opacity')).to.equal('1');

// Wait for the first slide's image to load
const firstSlideImg = await controller.findElement(
'amp-lightbox-gallery img'
);
await expect(prop(firstSlideImg, 'naturalWidth')).to.be.gt(0);

// Now close the gallery via button click and wait for it to close.
await controller.click(closeButton);
await controller.findElement('amp-lightbox-gallery[hidden]');
});
}
);
6 changes: 3 additions & 3 deletions test/manual/amp-lightbox-gallery-launch-captions.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h2>Open with expanded caption</h2>
<amp-img
on="tap:lg.open(expandDescription = true)"
lightbox="caption"
src="https://picsum.photos/300/200"
src="./img/bluegradient.png"
width="300"
height="200"
layout="responsive"></amp-img>
Expand All @@ -69,7 +69,7 @@ <h2>Open with expanded caption</h2>
<amp-img
on="tap:lg.open(expandDescription = true)"
lightbox="caption"
src="https://picsum.photos/400/300"
src="./img/orangegradient.png"
width="400"
height="300"
layout="responsive"></amp-img>
Expand All @@ -87,7 +87,7 @@ <h2>Open with expanded caption</h2>
<amp-img
on="tap:lg.open(expandDescription = true)"
lightbox="caption"
src="https://picsum.photos/400/300"
src="./img/lilacgradient.png"
width="400"
height="300"
layout="responsive"></amp-img>
Expand Down
24 changes: 12 additions & 12 deletions test/manual/amp-lightbox-gallery-launch.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
This is a basic example that demonstrates lightboxed `<amp-img>`s. You have one or more `<amp-img>` elements on the page. Just add the "lightbox" attribute to each image that you wish to view in a lightbox.
-->
<div class="container">
<amp-img lightbox src="https://picsum.photos/300/200" width="300" height="200" layout="responsive"></amp-img>
<amp-img lightbox src="./img/bluegradient.png" width="300" height="200" layout="responsive"></amp-img>
<p class="paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<amp-img lightbox src="https://picsum.photos/300/200" width="300" height="200" layout="responsive"></amp-img>
<amp-img lightbox src="./img/redgradient.png" width="300" height="200" layout="responsive"></amp-img>
<p class="paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<amp-img lightbox src="https://picsum.photos/300/200" width="300" height="200" layout="responsive"></amp-img>
<amp-img lightbox src="./img/lemonyellowgradient.png" width="300" height="200" layout="responsive"></amp-img>
<p class="paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>

Expand All @@ -78,9 +78,9 @@
-->
<div>
<amp-carousel lightbox width="400" height="300" layout="responsive" type="slides">
<amp-img src="https://picsum.photos/400/300" width="400" height="300" layout="responsive"></amp-img>
<amp-img src="https://picsum.photos/400/300" width="400" height="300" layout="responsive"></amp-img>
<amp-img src="https://picsum.photos/400/300" width="400" height="300" layout="responsive"></amp-img>
<amp-img src="./img/lilacgradient.png" width="400" height="300" layout="responsive"></amp-img>
<amp-img src="./img/tealgradient.png" width="400" height="300" layout="responsive"></amp-img>
<amp-img src="./img/orangegradient.png" width="400" height="300" layout="responsive"></amp-img>
</amp-carousel>
</div>

Expand All @@ -89,20 +89,20 @@

<div>
<amp-img lightbox="hero"
src="https://picsum.photos/400/300"
src="./img/lilacgradient.png"
width="400"
height="300"
layout="responsive">
<span class="overlay-text">See photo gallery</span>
</amp-img>
<div hidden>
<amp-img lightbox="hero"
src="https://picsum.photos/400/300"
src="./img/orangegradient.png"
layout="responsive"
width="400"
height="300"></amp-img>
<amp-img lightbox="hero"
src="https://picsum.photos/400/300"
src="./img/tealgradient.png"
width="400"
height="300"
layout="responsive" ></amp-img>
Expand All @@ -120,7 +120,7 @@

<amp-img
lightbox="caption"
src="https://picsum.photos/300/200"
src="./img/lemonyellowgradient.png"
width="300"
height="200"
layout="responsive"></amp-img>
Expand All @@ -129,7 +129,7 @@
<figure>
<amp-img
lightbox="caption"
src="https://picsum.photos/300/200"
src="./img/redgradient.png"
width="300"
height="200"
layout="responsive"></amp-img>
Expand All @@ -141,7 +141,7 @@

<amp-img
lightbox="caption"
src="https://picsum.photos/300/200"
src="./img/greengradient.png"
layout="responsive"
width="300"
height="200"
Expand Down
Binary file added test/manual/img/bluegradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/manual/img/greengradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/manual/img/lemonyellowgradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/manual/img/lilacgradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/manual/img/orangegradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/manual/img/redgradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/manual/img/tealgradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 04fd845

Please sign in to comment.