-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
b3d0ea3
commit 9895be1
Showing
6 changed files
with
170 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 160 additions & 1 deletion
161
src/schema/v2/homeView/sections/__tests__/DiscoverSomethingNew.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters