Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@dblandin => [SearchResults] Add basic contents for a tab #2148

Merged
merged 2 commits into from
Mar 12, 2019
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
45 changes: 45 additions & 0 deletions src/Apps/Search/Routes/Artists/SearchResultsArtists.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Box, Spacer } from "@artsy/palette"
import { SearchResultsArtistsRoute_viewer } from "__generated__/SearchResultsArtistsRoute_viewer.graphql"
import React, { SFC } from "react"
import { createFragmentContainer, graphql } from "react-relay"
import { get } from "Utils/get"

export interface Props {
viewer: SearchResultsArtistsRoute_viewer
}

export const SearchResultsArtistsRoute: SFC<Props> = props => {
const { viewer } = props

const artists = get(viewer, v => v.search.edges, []).map(e => e.node)
return (
<>
{artists.map((artist, index) => {
return (
<Box key={index}>
{artist.name}
<Spacer mb={3} />
</Box>
)
})}
</>
)
}

export const SearchResultsArtistsRouteFragmentContainer = createFragmentContainer(
SearchResultsArtistsRoute,
graphql`
fragment SearchResultsArtistsRoute_viewer on Viewer
@argumentDefinitions(term: { type: "String!", defaultValue: "" }) {
search(query: $term, first: 10, entities: [ARTIST]) {
edges {
node {
... on Artist {
name
}
}
}
}
}
`
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ContextProvider } from "Artsy"
import { MockBoot } from "DevTools"
import { mount } from "enzyme"
import React from "react"
import { SearchResultsArtistsRoute as SearchResultsArtists } from "../SearchResultsArtists"

describe("SearchResultsArtworks", () => {
const getWrapper = (searchProps: any) => {
return mount(
<MockBoot>
<ContextProvider>
<SearchResultsArtists {...searchProps} />
</ContextProvider>
</MockBoot>
)
}

const props = {
term: "andy",
viewer: {
search: {
edges: [
{
node: {
name: "Catty Artist",
},
},
],
},
},
}

it("renders artworks contents", () => {
const wrapper = getWrapper(props) as any
const html = wrapper.html()
expect(html).toContain("Catty Artist")
})
})
47 changes: 47 additions & 0 deletions src/Apps/Search/Routes/Artworks/SearchResultsArtworks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Box, Spacer } from "@artsy/palette"
import { SearchResultsArtworksRoute_viewer } from "__generated__/SearchResultsArtworksRoute_viewer.graphql"
import React, { SFC } from "react"
import { createFragmentContainer, graphql } from "react-relay"
import { get } from "Utils/get"

export interface Props {
viewer: SearchResultsArtworksRoute_viewer
}

export const SearchResultsArtworksRoute: SFC<Props> = props => {
const { viewer } = props

const artworks = get(viewer, v => v.search.edges, []).map(e => e.node)
return (
<>
{artworks.map((artwork, index) => {
return (
<Box key={index}>
{artwork.title}, {artwork.date} by {artwork.artist_names}
<Spacer mb={3} />
</Box>
)
})}
</>
)
}

export const SearchResultsArtworksRouteFragmentContainer = createFragmentContainer(
SearchResultsArtworksRoute,
graphql`
fragment SearchResultsArtworksRoute_viewer on Viewer
@argumentDefinitions(term: { type: "String!", defaultValue: "" }) {
search(query: $term, first: 10, entities: [ARTWORK]) {
edges {
node {
... on Artwork {
title
artist_names
date
}
}
}
}
}
`
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ContextProvider } from "Artsy"
import { MockBoot } from "DevTools"
import { mount } from "enzyme"
import React from "react"
import { SearchResultsArtworksRoute as SearchResultsArtworks } from "../SearchResultsArtworks"

describe("SearchResultsArtworks", () => {
const getWrapper = (searchProps: any) => {
return mount(
<MockBoot>
<ContextProvider>
<SearchResultsArtworks {...searchProps} />
</ContextProvider>
</MockBoot>
)
}

const props = {
term: "andy",
viewer: {
search: {
edges: [
{
node: {
title: "Catty Artwork",
artist_names: "Percy Z",
date: "2019",
},
},
],
},
},
}

it("renders artworks contents", () => {
const wrapper = getWrapper(props) as any
const html = wrapper.html()
expect(html).toContain("Catty Artwork, 2019 by Percy Z")
})
})
22 changes: 19 additions & 3 deletions src/Apps/Search/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SearchResultsArtistsRouteFragmentContainer as SearchResultsArtistsRoute } from "Apps/Search/Routes/Artists/SearchResultsArtists"
import { SearchResultsArtworksRouteFragmentContainer as SearchResultsArtworksRoute } from "Apps/Search/Routes/Artworks/SearchResultsArtworks"
import { RouteConfig } from "found"
import React from "react"
import { graphql } from "react-relay"
import { SearchAppFragmentContainer as SearchApp } from "./SearchApp"

Expand Down Expand Up @@ -34,11 +35,26 @@ export const routes: RouteConfig[] = [
children: [
{
path: "/",
Component: () => <div>Artwork search results</div>,
Component: SearchResultsArtworksRoute,
query: graphql`
query routes_SearchResultsArtworksQuery($term: String!) {
viewer {
...SearchResultsArtworksRoute_viewer @arguments(term: $term)
}
}
`,
prepareVariables,
},
{
path: "artists",
Component: () => <div>Artist search results</div>,
Component: SearchResultsArtistsRoute,
query: graphql`
query routes_SearchResultsArtistsQuery($term: String!) {
viewer {
...SearchResultsArtistsRoute_viewer @arguments(term: $term)
}
}
`,
prepareVariables,
},
],
Expand Down
110 changes: 110 additions & 0 deletions src/__generated__/SearchResultsArtistsRoute_viewer.graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading