Skip to content

Commit 9895be1

Browse files
authored
feat(DIA-863): add tracking to explore and discover home view sections (#6164)
* feat: add tracking to explore and discover home view sections * feat: bump cohesion and add the right context module
1 parent b3d0ea3 commit 9895be1

File tree

6 files changed

+170
-17
lines changed

6 files changed

+170
-17
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"author": "Art.sy Inc",
3939
"license": "MIT",
4040
"dependencies": {
41-
"@artsy/cohesion": "^4.210.0",
41+
"@artsy/cohesion": "^4.213.0",
4242
"@artsy/img": "1.0.3",
4343
"@artsy/morgan": "^1.0.2",
4444
"@artsy/multienv": "^1.2.0",

Diff for: src/schema/v2/homeView/sections/DiscoverSomethingNew.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const marketingCollectionSlugs = [
2121
export const DiscoverSomethingNew: HomeViewSection = {
2222
id: "home-view-section-discover-something-new",
2323
featureFlag: "diamond_home-view-marketing-collection-categories",
24-
contextModule: "" as ContextModule, // TODO: fill in with real value
24+
contextModule: ContextModule.discoverSomethingNewRail,
2525
type: HomeViewSectionTypeNames.HomeViewSectionCards,
2626
component: {
2727
title: "Discover Something New",

Diff for: src/schema/v2/homeView/sections/ExploreByCategory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const marketingColletionCategories = {
4242
export const ExploreByCategory: HomeViewSection = {
4343
id: "home-view-section-explore-by-category",
4444
featureFlag: "diamond_home-view-marketing-collection-categories",
45-
contextModule: "" as ContextModule, // TODO: fill in with real value
45+
contextModule: ContextModule.exploreBy,
4646
type: HomeViewSectionTypeNames.HomeViewSectionCards,
4747
component: {
4848
title: "Explore by Category",
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,162 @@
1+
import { isFeatureFlagEnabled } from "lib/featureFlags"
2+
import gql from "lib/gql"
3+
import { runQuery } from "schema/v2/test/utils"
4+
5+
jest.mock("lib/featureFlags", () => ({
6+
isFeatureFlagEnabled: jest.fn(() => true),
7+
}))
8+
9+
const mockIsFeatureFlagEnabled = isFeatureFlagEnabled as jest.Mock
10+
111
describe("DiscoverSomethingNew", () => {
2-
it.skip("needs specs", () => {})
12+
describe("when the feature flag is enabled", () => {
13+
beforeEach(() => {
14+
mockIsFeatureFlagEnabled.mockImplementation((flag: string) => {
15+
if (flag === "diamond_home-view-marketing-collection-categories")
16+
return true
17+
})
18+
})
19+
20+
it("returns the section's metadata", async () => {
21+
const query = gql`
22+
{
23+
homeView {
24+
section(id: "home-view-section-discover-something-new") {
25+
__typename
26+
internalID
27+
contextModule
28+
ownerType
29+
component {
30+
title
31+
behaviors {
32+
viewAll {
33+
buttonText
34+
href
35+
ownerType
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
42+
`
43+
44+
const context = {}
45+
46+
const { homeView } = await runQuery(query, context)
47+
48+
expect(homeView.section).toMatchInlineSnapshot(`
49+
Object {
50+
"__typename": "HomeViewSectionCards",
51+
"component": Object {
52+
"behaviors": null,
53+
"title": "Discover Something New",
54+
},
55+
"contextModule": "discoverSomethingNewRail",
56+
"internalID": "home-view-section-discover-something-new",
57+
"ownerType": null,
58+
}
59+
`)
60+
})
61+
62+
it("returns the section's connection data", async () => {
63+
const query = gql`
64+
{
65+
homeView {
66+
section(id: "home-view-section-discover-something-new") {
67+
... on HomeViewSectionCards {
68+
cardsConnection(first: 6) {
69+
edges {
70+
node {
71+
entityID
72+
title
73+
image {
74+
url
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}
82+
}
83+
`
84+
85+
const context = {
86+
marketingCollectionsLoader: jest.fn().mockResolvedValue({
87+
body: [
88+
{
89+
slug: "figurative-art",
90+
id: "figurative-art",
91+
title: "Figurative Art",
92+
thumbnail: "figurative-art.jpg",
93+
},
94+
{
95+
slug: "new-from-leading-galleries",
96+
id: "new-from-leading-galleries",
97+
title: "New from Leading Galleries",
98+
thumbnail: "new-from-leading-galleries.jpg",
99+
},
100+
],
101+
}),
102+
}
103+
104+
const { homeView } = await runQuery(query, context)
105+
106+
expect(homeView.section).toMatchInlineSnapshot(`
107+
Object {
108+
"cardsConnection": Object {
109+
"edges": Array [
110+
Object {
111+
"node": Object {
112+
"entityID": "figurative-art",
113+
"image": Object {
114+
"url": "figurative-art.jpg",
115+
},
116+
"title": "Figurative Art",
117+
},
118+
},
119+
Object {
120+
"node": Object {
121+
"entityID": "new-from-leading-galleries",
122+
"image": Object {
123+
"url": "new-from-leading-galleries.jpg",
124+
},
125+
"title": "New from Leading Galleries",
126+
},
127+
},
128+
],
129+
},
130+
}
131+
`)
132+
})
133+
})
134+
135+
describe("when the feature flag is disabled", () => {
136+
beforeEach(() => {
137+
mockIsFeatureFlagEnabled.mockImplementation((flag: string) => {
138+
if (flag === "diamond_home-view-marketing-collection-categories")
139+
return false
140+
})
141+
})
142+
143+
it("throws an error when accessed by id", async () => {
144+
const query = gql`
145+
{
146+
homeView {
147+
section(id: "home-view-section-discover-something-new") {
148+
__typename
149+
internalID
150+
}
151+
}
152+
}
153+
`
154+
155+
const context = {}
156+
157+
await expect(runQuery(query, context)).rejects.toThrow(
158+
"Section is not displayable"
159+
)
160+
})
161+
})
3162
})

Diff for: src/schema/v2/homeView/sections/__tests__/ExploreByCategory.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("ExploreByCategory", () => {
5252
"behaviors": null,
5353
"title": "Explore by Category",
5454
},
55-
"contextModule": "",
55+
"contextModule": "exploreBy",
5656
"internalID": "home-view-section-explore-by-category",
5757
"ownerType": null,
5858
}

Diff for: yarn.lock

+6-12
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# yarn lockfile v1
33

44

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

@@ -10061,7 +10061,8 @@ stringify-object@^3.2.2:
1006110061
is-obj "^1.0.1"
1006210062
is-regexp "^1.0.0"
1006310063

10064-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
10064+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.1:
10065+
name strip-ansi-cjs
1006510066
version "6.0.1"
1006610067
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1006710068
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -10103,13 +10104,6 @@ strip-ansi@^6.0.0:
1010310104
dependencies:
1010410105
ansi-regex "^5.0.0"
1010510106

10106-
strip-ansi@^6.0.1:
10107-
version "6.0.1"
10108-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
10109-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
10110-
dependencies:
10111-
ansi-regex "^5.0.1"
10112-
1011310107
strip-ansi@^7.0.1:
1011410108
version "7.1.0"
1011510109
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"

0 commit comments

Comments
 (0)