Skip to content

Commit

Permalink
feat(DIA-863): add tracking to explore and discover home view sections (
Browse files Browse the repository at this point in the history
#6164)

* feat: add tracking to explore and discover home view sections

* feat: bump cohesion and add the right context module
  • Loading branch information
araujobarret authored Oct 24, 2024
1 parent b3d0ea3 commit 9895be1
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"author": "Art.sy Inc",
"license": "MIT",
"dependencies": {
"@artsy/cohesion": "^4.210.0",
"@artsy/cohesion": "^4.213.0",
"@artsy/img": "1.0.3",
"@artsy/morgan": "^1.0.2",
"@artsy/multienv": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/schema/v2/homeView/sections/DiscoverSomethingNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const marketingCollectionSlugs = [
export const DiscoverSomethingNew: HomeViewSection = {
id: "home-view-section-discover-something-new",
featureFlag: "diamond_home-view-marketing-collection-categories",
contextModule: "" as ContextModule, // TODO: fill in with real value
contextModule: ContextModule.discoverSomethingNewRail,
type: HomeViewSectionTypeNames.HomeViewSectionCards,
component: {
title: "Discover Something New",
Expand Down
2 changes: 1 addition & 1 deletion src/schema/v2/homeView/sections/ExploreByCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const marketingColletionCategories = {
export const ExploreByCategory: HomeViewSection = {
id: "home-view-section-explore-by-category",
featureFlag: "diamond_home-view-marketing-collection-categories",
contextModule: "" as ContextModule, // TODO: fill in with real value
contextModule: ContextModule.exploreBy,
type: HomeViewSectionTypeNames.HomeViewSectionCards,
component: {
title: "Explore by Category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,162 @@
import { isFeatureFlagEnabled } from "lib/featureFlags"
import gql from "lib/gql"
import { runQuery } from "schema/v2/test/utils"

jest.mock("lib/featureFlags", () => ({
isFeatureFlagEnabled: jest.fn(() => true),
}))

const mockIsFeatureFlagEnabled = isFeatureFlagEnabled as jest.Mock

describe("DiscoverSomethingNew", () => {
it.skip("needs specs", () => {})
describe("when the feature flag is enabled", () => {
beforeEach(() => {
mockIsFeatureFlagEnabled.mockImplementation((flag: string) => {
if (flag === "diamond_home-view-marketing-collection-categories")
return true
})
})

it("returns the section's metadata", async () => {
const query = gql`
{
homeView {
section(id: "home-view-section-discover-something-new") {
__typename
internalID
contextModule
ownerType
component {
title
behaviors {
viewAll {
buttonText
href
ownerType
}
}
}
}
}
}
`

const context = {}

const { homeView } = await runQuery(query, context)

expect(homeView.section).toMatchInlineSnapshot(`
Object {
"__typename": "HomeViewSectionCards",
"component": Object {
"behaviors": null,
"title": "Discover Something New",
},
"contextModule": "discoverSomethingNewRail",
"internalID": "home-view-section-discover-something-new",
"ownerType": null,
}
`)
})

it("returns the section's connection data", async () => {
const query = gql`
{
homeView {
section(id: "home-view-section-discover-something-new") {
... on HomeViewSectionCards {
cardsConnection(first: 6) {
edges {
node {
entityID
title
image {
url
}
}
}
}
}
}
}
}
`

const context = {
marketingCollectionsLoader: jest.fn().mockResolvedValue({
body: [
{
slug: "figurative-art",
id: "figurative-art",
title: "Figurative Art",
thumbnail: "figurative-art.jpg",
},
{
slug: "new-from-leading-galleries",
id: "new-from-leading-galleries",
title: "New from Leading Galleries",
thumbnail: "new-from-leading-galleries.jpg",
},
],
}),
}

const { homeView } = await runQuery(query, context)

expect(homeView.section).toMatchInlineSnapshot(`
Object {
"cardsConnection": Object {
"edges": Array [
Object {
"node": Object {
"entityID": "figurative-art",
"image": Object {
"url": "figurative-art.jpg",
},
"title": "Figurative Art",
},
},
Object {
"node": Object {
"entityID": "new-from-leading-galleries",
"image": Object {
"url": "new-from-leading-galleries.jpg",
},
"title": "New from Leading Galleries",
},
},
],
},
}
`)
})
})

describe("when the feature flag is disabled", () => {
beforeEach(() => {
mockIsFeatureFlagEnabled.mockImplementation((flag: string) => {
if (flag === "diamond_home-view-marketing-collection-categories")
return false
})
})

it("throws an error when accessed by id", async () => {
const query = gql`
{
homeView {
section(id: "home-view-section-discover-something-new") {
__typename
internalID
}
}
}
`

const context = {}

await expect(runQuery(query, context)).rejects.toThrow(
"Section is not displayable"
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("ExploreByCategory", () => {
"behaviors": null,
"title": "Explore by Category",
},
"contextModule": "",
"contextModule": "exploreBy",
"internalID": "home-view-section-explore-by-category",
"ownerType": null,
}
Expand Down
18 changes: 6 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@artsy/cohesion@^4.210.0":
version "4.210.0"
resolved "https://registry.yarnpkg.com/@artsy/cohesion/-/cohesion-4.210.0.tgz#668128d0ba058759a01c3e9bf8dfcdcda91891e9"
integrity sha512-xSKwXn/r7FDFIjy6D8E/7xKdbMsG7UF2LG9OjewrLgyLITBpgn3gFsxbhAYjl4HE5+MIgtYBhHWpjwtpGcEeRg==
"@artsy/cohesion@^4.213.0":
version "4.213.0"
resolved "https://registry.yarnpkg.com/@artsy/cohesion/-/cohesion-4.213.0.tgz#c935e8f51e852937ae08984df5abb2fd3d741480"
integrity sha512-Q+JOcGVUrprwukUdTYNlJ2Am/Dj4iiq8vy6R7GDUj9jUZbj4OFFiVzBGeBXR8+dT7dn4DIwd9NUW6drnGnnmJA==
dependencies:
core-js "3"

Expand Down Expand Up @@ -10061,7 +10061,8 @@ stringify-object@^3.2.2:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.1:
name strip-ansi-cjs
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -10103,13 +10104,6 @@ strip-ansi@^6.0.0:
dependencies:
ansi-regex "^5.0.0"

strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down

0 comments on commit 9895be1

Please sign in to comment.