Skip to content

Commit

Permalink
feat: add a News home view section (#5946)
Browse files Browse the repository at this point in the history
* chore: clean up, alphabetize etc

* feat: add a news section

* fix: improper nesting in test
  • Loading branch information
anandaroop authored Aug 27, 2024
1 parent fe5bf4c commit 9d938af
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 31 deletions.
10 changes: 9 additions & 1 deletion src/schema/v2/homeView/__tests__/HomeView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ describe("homeView", () => {
}),
}

it("returns requested data for each section", async () => {
it("returns every section", async () => {
const { homeView } = await runQuery(query, context)

expect(homeView.sectionsConnection).toMatchInlineSnapshot(`
Object {
"edges": Array [
Object {
"node": Object {
"__typename": "ArticlesRailHomeViewSection",
"component": Object {
"title": "News",
},
},
},
Object {
"node": Object {
"__typename": "ActivityRailHomeViewSection",
Expand Down
135 changes: 108 additions & 27 deletions src/schema/v2/homeView/__tests__/HomeViewSection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,42 +477,42 @@ describe("HomeViewSection", () => {
}
`)
})
})

describe("ViewingRoomsRailHomeViewSection", () => {
it("returns correct data", async () => {
const query = gql`
{
homeView {
section(id: "home-view-section-viewing-rooms") {
__typename
describe("ViewingRoomsRailHomeViewSection", () => {
it("returns correct data", async () => {
const query = gql`
{
homeView {
section(id: "home-view-section-viewing-rooms") {
__typename
... on ViewingRoomsRailHomeViewSection {
component {
title
}
... on ViewingRoomsRailHomeViewSection {
component {
title
}
}
}
}
`

const context = {
authenticatedLoaders: {
meLoader: jest.fn().mockReturnValue({ type: "User" }),
},
}
`

const data = await runQuery(query, context)
const context = {
authenticatedLoaders: {
meLoader: jest.fn().mockReturnValue({ type: "User" }),
},
}

expect(data.homeView.section).toMatchInlineSnapshot(`
Object {
"__typename": "ViewingRoomsRailHomeViewSection",
"component": Object {
"title": "Viewing Rooms",
},
}
`)
})
const data = await runQuery(query, context)

expect(data.homeView.section).toMatchInlineSnapshot(`
Object {
"__typename": "ViewingRoomsRailHomeViewSection",
"component": Object {
"title": "Viewing Rooms",
},
}
`)
})
})

Expand Down Expand Up @@ -732,4 +732,85 @@ describe("HomeViewSection", () => {
`)
})
})

describe("News", () => {
it("returns correct data", async () => {
const query = gql`
{
homeView {
section(id: "home-view-section-news") {
__typename
... on ArticlesRailHomeViewSection {
component {
title
href
type
}
articlesConnection(first: 3) {
edges {
node {
title
href
}
}
}
}
}
}
}
`

const articles = [
{
title: "Bored apes stolen",
slug: "stolen-apes",
},
{
title: "More apes stolen",
slug: "more-apes",
},
]

const context = {
articlesLoader: jest.fn().mockReturnValue({
count: articles.length,
results: articles,
}),
authenticatedLoaders: {
meLoader: jest.fn().mockReturnValue({ type: "User" }),
},
}

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

expect(homeView.section).toMatchInlineSnapshot(`
Object {
"__typename": "ArticlesRailHomeViewSection",
"articlesConnection": Object {
"edges": Array [
Object {
"node": Object {
"href": "/article/stolen-apes",
"title": "Bored apes stolen",
},
},
Object {
"node": Object {
"href": "/article/more-apes",
"title": "More apes stolen",
},
},
],
},
"component": Object {
"href": "/news",
"title": "News",
"type": "ArticlesCard",
},
}
`)
})
})
})
27 changes: 27 additions & 0 deletions src/schema/v2/homeView/articlesResolvers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { GraphQLFieldResolver } from "graphql"
import type { ResolverContext } from "types/graphql"
import ArticlesConnection from "../articlesConnection"
import ArticleSorts from "../sorts/article_sorts"
import { ArticleLayoutEnum } from "../article/models"

/*
* Resolvers for home view articels sections
Expand All @@ -10,3 +12,28 @@ export const LatestArticlesResolvers: GraphQLFieldResolver<
any,
ResolverContext
> = ArticlesConnection.resolve!

export const NewsResolver: GraphQLFieldResolver<any, ResolverContext> = async (
parent,
args,
context,
info
) => {
const finalArgs = {
// formerly specified client-side
published: true,
sort: ArticleSorts.type.getValue("PUBLISHED_AT_DESC")?.value,
layout: ArticleLayoutEnum.getValue("NEWS")?.value,

...args,
}

const result = await ArticlesConnection.resolve!(
parent,
finalArgs,
context,
info
)

return result
}
3 changes: 3 additions & 0 deletions src/schema/v2/homeView/getSectionsForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
TrendingArtists,
ViewingRooms,
LatestAuctionResults,
News,
} from "./sections"

export async function getSectionsForUser(
Expand Down Expand Up @@ -51,9 +52,11 @@ export async function getSectionsForUser(
NewWorksFromGalleriesYouFollow,
RecommendedArtists,
ViewingRooms,
News,
]
} else {
sections = [
News,
LatestActivity,
CuratorsPicksEmerging,
SimilarToRecentlyViewedArtworks,
Expand Down
17 changes: 14 additions & 3 deletions src/schema/v2/homeView/sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FeaturedFairsResolver } from "./featuredFairsResolver"
type MaybeResolved<T> =
| T
| ((context: ResolverContext, args: any) => Promise<T>)
import { LatestArticlesResolvers } from "./articlesResolvers"
import { LatestArticlesResolvers, NewsResolver } from "./articlesResolvers"
import { MarketingCollectionsResolver } from "./marketingCollectionsResolver"
import { LatestActivityResolver } from "./activityResolvers"
import { LatestAuctionResultsResolver } from "./auctionResultsResolvers"
Expand Down Expand Up @@ -117,8 +117,6 @@ export const NewWorksFromGalleriesYouFollow: HomeViewSection = {
resolver: NewWorksFromGalleriesYouFollowResolver,
}

// Artists Rails

export const TrendingArtists: HomeViewSection = {
id: "home-view-section-trending-artists",
type: "ArtistsRailHomeViewSection",
Expand Down Expand Up @@ -212,6 +210,17 @@ export const LatestAuctionResults: HomeViewSection = {
resolver: LatestAuctionResultsResolver,
}

export const News: HomeViewSection = {
id: "home-view-section-news",
type: "ArticlesRailHomeViewSection",
component: {
title: "News",
href: "/news",
type: "ArticlesCard",
},
resolver: NewsResolver,
}

const sections: HomeViewSection[] = [
AuctionLotsForYou,
CuratorsPicksEmerging,
Expand All @@ -222,8 +231,10 @@ const sections: HomeViewSection[] = [
LatestAuctionResults,
MarketingCollections,
MarketingCollections,
MarketingCollections,
NewWorksForYou,
NewWorksFromGalleriesYouFollow,
News,
RecentlyViewedArtworks,
RecommendedArtists,
ShowsForYou,
Expand Down

0 comments on commit 9d938af

Please sign in to comment.