Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add e2e test for image detail page (#473)

Krystle Salazar01808c299e1c
diff --git a/.github/workflows-disabled/end-to-end-tests.yml b/.github/workflows-disabled/end-to-end-tests.yml
deleted file mode 100644
index 8d1ac02c1..000000000
--- a/.github/workflows-disabled/end-to-end-tests.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-name: End-to-end tests
-on:
- push:
- branches:
- - master
- pull_request:
- branches:
- - master
-jobs:
- cypress-run:
- runs-on: ubuntu-16.04
- steps:
- - name: Checkout
- uses: actions/checkout@v1
- # Install NPM dependencies, cache them correctly
- # and run all Cypress tests
- - name: Cypress run
- uses: cypress-io/github-action@v2
- with:
- config: baseUrl=https://ccsearch-dev.creativecommons.org
diff --git a/src/components/ImageGrid/ImageCell.vue b/src/components/ImageGrid/ImageCell.vue
index 162785840..d717a2584 100644
--- a/src/components/ImageGrid/ImageCell.vue
+++ b/src/components/ImageGrid/ImageCell.vue
@@ -8,7 +8,7 @@
<figure class="search-grid_item">
<i :style="`padding-bottom:${iPadding}%`" />
<NuxtLink
- :to="localePath('/photos/' + image.id)"
+ :to="localePath('/image/' + image.id)"
class="search-grid_image-ctr"
:style="`width: ${imageWidth}%; top: ${imageTop}%; left:${imageLeft}%;`"
@click="onGotoDetailPage($event, image)"
diff --git a/src/components/SearchGridCell.vue b/src/components/SearchGridCell.vue
index b57e403bc..136ec97ab 100644
--- a/src/components/SearchGridCell.vue
+++ b/src/components/SearchGridCell.vue
@@ -8,7 +8,7 @@
<figure class="search-grid_item">
<i :style="`padding-bottom:${iPadding}%`" />
<NuxtLink
- :to="localePath('/photos/' + image.id)"
+ :to="localePath('/image/' + image.id)"
class="search-grid_image-ctr"
:style="`width: ${imageWidth}%; top: ${imageTop}%; left:${imageLeft}%;`"
@click="onGotoDetailPage($event, image)"
diff --git a/src/pages/photos/_id.vue b/src/pages/image/_id.vue
similarity index 100%
rename from src/pages/photos/_id.vue
rename to src/pages/image/_id.vue
diff --git a/test/e2e/homepage.spec.js b/test/e2e/homepage.spec.js
index 6889d4d68..ccc42ff81 100644
--- a/test/e2e/homepage.spec.js
+++ b/test/e2e/homepage.spec.js
@@ -2,7 +2,7 @@ const { test, expect } = require('@playwright/test')
test('can change type and search for audio/modification from homepage', async ({
page,
- context,
+ baseURL,
}) => {
// Go to http://localhost:8444/
await page.goto('/')
@@ -16,7 +16,6 @@ test('can change type and search for audio/modification from homepage', async ({
await page.fill('[placeholder="Search all content"]', 'cat')
// Click button:has-text("Search")
await page.click('button:has-text("Search")')
- const BASE_URL = context._options.baseURL
- const expectedUrl = BASE_URL + '/search/audio?q=cat&license_type=modification'
+ const expectedUrl = baseURL + '/search/audio?q=cat&license_type=modification'
await expect(page).toHaveURL(expectedUrl)
})
diff --git a/test/e2e/image-detail.spec.js b/test/e2e/image-detail.spec.js
new file mode 100644
index 000000000..b90a62c8d
--- /dev/null
+++ b/test/e2e/image-detail.spec.js
@@ -0,0 +1,28 @@
+const { test, expect } = require('@playwright/test')
+
+test.beforeEach(async ({ context, page }) => {
+ // Block any image request for each test in this file.
+ await context.route(/\.(png|jpeg|jpg|svg)$/, (route) => route.abort())
+
+ // Test in a custom image detail page, it should apply the same for any image.
+ // TODO: Make these tests independent of the live API.
+ await page.goto('image/e9d97a98-621b-4ec2-bf70-f47a74380452')
+})
+
+test('shows the author and title of the image', async ({ page }) => {
+ const author = page.locator('a[aria-label^="author"]')
+ await expect(author).toBeVisible()
+ const imgTitle = page.locator('h1')
+ await expect(imgTitle).toBeVisible()
+})
+
+test('shows the main image with its title as alt text', async ({ page }) => {
+ const imgTitle = await page.locator('h1').innerText()
+ const img = page.locator('img[class="photo_image"]')
+ await expect(img).toBeVisible()
+ await expect(img).toHaveAttribute('alt', imgTitle)
+})
+
+test('does not show back to search results breadcrumb', async ({ page }) => {
+ await expect(page.locator('text="Back to search results"')).not.toBeVisible()
+})
diff --git a/test/e2e/search.spec.js b/test/e2e/search.spec.js
index aec767e8a..3560b9fe5 100644
--- a/test/e2e/search.spec.js
+++ b/test/e2e/search.spec.js
@@ -55,3 +55,13 @@ test('shows search result metadata', async ({ page }) => {
// All search results have been shown, cannot load more
await expect(loadMoreButton).toHaveCount(0)
})
+
+test('navigates to the image detail page correctly', async ({ page }) => {
+ await page.goto('/search/image?q=honey')
+ const figure = page.locator('figure').first()
+ const imgTitle = await figure.locator('img').getAttribute('alt')
+ await figure.click()
+ await expect(page.locator('h1')).toHaveText(imgTitle)
+ // Renders the breadcrumb link
+ await expect(page.locator('text="Back to search results"')).toBeVisible()
+})
diff --git a/test/unit/specs/components/ImageDetails/photo-details.spec.js b/test/unit/specs/components/ImageDetails/photo-details.spec.js
index 1f4fc5ebc..b99971fe0 100644
--- a/test/unit/specs/components/ImageDetails/photo-details.spec.js
+++ b/test/unit/specs/components/ImageDetails/photo-details.spec.js
@@ -110,11 +110,6 @@ describe('PhotoDetails', () => {
expect(wrapper.html()).toContain(props.image.title)
})
- // it('renders creator name', () => {
- // const wrapper = render(PhotoDetails, options)
- // expect(wrapper.html()).toContain(props.image.creator)
- // })
-
it('redirects back when clicking on the back to results link', async () => {
const routerMock = {
push: jest.fn(),
diff --git a/test/unit/specs/components/search-grid-cell.spec.js b/test/unit/specs/components/search-grid-cell.spec.js
index 30595a816..cd5fe3cf6 100644
--- a/test/unit/specs/components/search-grid-cell.spec.js
+++ b/test/unit/specs/components/search-grid-cell.spec.js
@@ -5,6 +5,7 @@ describe('SearchGridCell', () => {
const props = {
image: {
id: 0,
+ license: 'by',
title: 'foo',
provider: 'flickr',
url: 'foo.bar',