Skip to content

Commit

Permalink
Merge pull request #2260 from sweir27/artist-page-optimizations
Browse files Browse the repository at this point in the history
@mzikherman => Only fetch cta_artists if the user is not logged in
  • Loading branch information
mzikherman authored Mar 13, 2018
2 parents 2e8df3d + 7e38daa commit f3b9e50
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/desktop/apps/artist/client/views/overview.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = class OverviewView extends Backbone.View
artists: @statuses.artists
articles: @statuses.articles
shows: @statuses.shows || @statuses.cv
loggedOut: !@user
.then ({ artist }) => @trigger 'artist:overview:sync', artist

setupBlurb: ->
Expand Down
4 changes: 2 additions & 2 deletions src/desktop/apps/artist/queries/overview.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports =
"""
query artist($artist_id: String!, $shows: Boolean!, $artists: Boolean!, $articles: Boolean!) {
query artist($artist_id: String!, $shows: Boolean!, $artists: Boolean!, $articles: Boolean!, $loggedOut: Boolean!) {
artist(id: $artist_id) {
counts {
shows: partner_shows
Expand All @@ -15,7 +15,7 @@ module.exports =
artists (size: 15) @include(if: $artists){
... artistCell
}
cta_artists: artists(size: 1) {
cta_artists: artists(size: 1) @include(if: $loggedOut){
image {
thumb: resized(width: 150, version: "square") {
url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- var count = 7
- var name = artist.get('name')
include ./row.jade
if artist.get('cta_artists')[0]
if artist.get('cta_artists') && artist.get('cta_artists')[0]
li
- var image = artist.get('cta_artists')[0].image.thumb.url
- var count = 3
Expand Down
53 changes: 53 additions & 0 deletions src/desktop/components/artist_page_cta/test/template.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
_ = require 'underscore'
$ = require 'cheerio'
benv = require 'benv'
jade = require 'jade'
{ fabricate } = require 'antigravity'
Artist = require '../../../models/artist'

templates =
overlay: jade.compileFile(require.resolve '../templates/overlay.jade')

describe 'templates', ->
before (done) ->
benv.setup =>
@artist = new Artist fabricate 'artist', name: 'Seth Clark', cta_image: thumb: url: 'http://thumb.jpg'
benv.expose
sd: AP: 'http://test.test'
done()

after ->
benv.teardown()

describe 'when there are null cta artists', ->
beforeEach ->
@artist.set cta_artists: null
@data = _.extend {}, { artist: @artist }

it 'renders correctly', ->
$template = $(templates.overlay @data)
$template.find('.artist-page-cta-overlay__feed__items__row').length.should.equal 1
text = $template.find('.artist-page-cta-overlay__headline').text()
text.should.equal 'Join Artsy to discover new works by Seth Clark and more artists you love'

describe 'when there are null cta artists', ->
beforeEach ->
@artist.set cta_artists: []
@data = _.extend {}, { artist: @artist }

it 'renders correctly', ->
$template = $(templates.overlay @data)
$template.find('.artist-page-cta-overlay__feed__items__row').length.should.equal 1
text = $template.find('.artist-page-cta-overlay__headline').text()
text.should.equal 'Join Artsy to discover new works by Seth Clark and more artists you love'

describe 'when there are some cta artists', ->
beforeEach ->
@artist.set cta_artists: [{ name: 'Drew Conrad', image: { thumb: { url: 'http://thumb1.jpg' } } }]
@data = _.extend {}, { artist: @artist }

it 'renders correctly', ->
$template = $(templates.overlay @data)
$template.find('.artist-page-cta-overlay__feed__items__row').length.should.equal 2
text = $($template.find('.artist-page-cta-overlay__feed__items__row__artist-info')[1]).text()
text.should.equal '3 New WorksTodayDrew Conrad'

0 comments on commit f3b9e50

Please sign in to comment.