Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions playwright/e2e/gene.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from "@playwright/test"
import { test, expect } from "@playwright/test"

test.describe("Gene", () => {
test("/gene/:id", async ({ page }) => {
Expand All @@ -7,8 +7,6 @@ test.describe("Gene", () => {
await expect(page.locator("h1").first()).toContainText(
"Contemporary Figurative Painting",
)
await expect(page).toHaveTitle(
"Contemporary Figurative Painting - Art & Prints for Sale | Artsy",
)
await expect(page).toHaveTitle("Contemporary Figurative Painting | Artsy")
})
})
21 changes: 3 additions & 18 deletions src/Apps/Gene/Components/GeneMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,19 @@ interface GeneMetaProps {
const GeneMeta: React.FC<React.PropsWithChildren<GeneMetaProps>> = ({
gene,
}) => {
const title = buildTitle(gene)
const description = buildDescription(gene)
const fallbackDescription = `Explore ${gene.name} art on Artsy. Browse works by size, price, and medium.`
const title = `${gene.displayName || gene.name} | Artsy`
Comment thread
iskounen marked this conversation as resolved.

return (
<MetaTags
title={title}
description={description}
description={gene.meta.description || fallbackDescription}
pathname={gene.href}
imageURL={gene.image?.cropped?.src}
/>
)
}

function buildTitle(gene: GeneMeta_gene$data): string {
return `${gene.displayName || gene.name} - Art & Prints for Sale | Artsy`
}

function buildDescription(gene: GeneMeta_gene$data): string {
const description = [
gene.meta.description,
`Browse ${gene.name} art on Artsy.`,
]
.filter(Boolean)
.join(" ")

return description
}

export const GeneMetaFragmentContainer = createFragmentContainer(GeneMeta, {
gene: graphql`
fragment GeneMeta_gene on Gene {
Expand Down
28 changes: 20 additions & 8 deletions src/Apps/Gene/Routes/__tests__/GeneShow.jest.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from "@testing-library/react"
import { GeneShowFragmentContainer } from "Apps/Gene/Routes/GeneShow"
import { MockBoot } from "DevTools/MockBoot"
import { setupTestWrapperTL } from "DevTools/setupTestWrapperTL"
import { screen } from "@testing-library/react"
import type { GeneShowTestQuery } from "__generated__/GeneShowTestQuery.graphql"
import { graphql } from "react-relay"

Expand Down Expand Up @@ -41,22 +41,34 @@ describe("GeneShow", () => {
expect(screen.getByText("Display Name")).toBeInTheDocument()
})

it("renders fallback title correctly", () => {
renderWithRelay({
Gene: () => ({
name: "Example Gene",
displayName: "",
}),
})

expect(screen.getByRole("heading", { level: 1 })).toBeInTheDocument()
expect(screen.getAllByText("Example Gene")).toHaveLength(2)
})

it("renders meta description and title from query", () => {
renderWithRelay({
Gene: () => ({
meta: { description: "Example Gene meta description." },
displayName: "Example Gene Display Name",
name: "Example Gene Name",
meta: { description: "Gene Meta Description" },
displayName: "Display Name",
name: "name",
}),
})

expect(document.querySelector('meta[name="description"]')).toHaveAttribute(
"content",
"Example Gene meta description. Browse Example Gene Name art on Artsy.",
"Gene Meta Description",
)
expect(document.querySelector('meta[name="title"]')).toHaveAttribute(
"content",
"Example Gene Display Name - Art & Prints for Sale | Artsy",
"Display Name | Artsy",
)
})

Expand All @@ -71,11 +83,11 @@ describe("GeneShow", () => {

expect(document.querySelector('meta[name="description"]')).toHaveAttribute(
"content",
"Browse Design art on Artsy.",
"Explore Design art on Artsy. Browse works by size, price, and medium.",
)
expect(document.querySelector('meta[name="title"]')).toHaveAttribute(
"content",
"Design - Art & Prints for Sale | Artsy",
"Design | Artsy",
)
})
})
Loading