VRFS-2795 filter tests
This commit is contained in:
parent
1cb887b696
commit
d3f0bad602
|
|
@ -4,7 +4,7 @@ context.JK ||= {};
|
|||
|
||||
context.JK.MusicianSearchFilter = class MusicianSearchFilter
|
||||
|
||||
constructor: (app) ->
|
||||
constructor: () ->
|
||||
@rest = context.JK.Rest()
|
||||
@logger = context.JK.logger
|
||||
@userId = null
|
||||
|
|
@ -61,8 +61,8 @@ context.JK.MusicianSearchFilter = class MusicianSearchFilter
|
|||
|
||||
_populateSelectIdentifier: (identifier) =>
|
||||
elem = $ '#musician-search-filter-builder select[name='+identifier+']'
|
||||
struct = gon.musician_search_filter[identifier]['map']
|
||||
keys = gon.musician_search_filter[identifier]['keys']
|
||||
struct = gon.musician_search_meta[identifier]['map']
|
||||
keys = gon.musician_search_meta[identifier]['keys']
|
||||
this._populateSelectWithKeys(struct, @searchFilter[identifier], keys, elem)
|
||||
|
||||
_populateSelectWithInt: (sourceStruct, selection, element) =>
|
||||
|
|
@ -91,8 +91,8 @@ context.JK.MusicianSearchFilter = class MusicianSearchFilter
|
|||
|
||||
populateAges: () =>
|
||||
$('#search-filter-ages').empty()
|
||||
ages_map = gon.musician_search_filter['ages']['map']
|
||||
$.each gon.musician_search_filter['ages']['keys'], (index, key) =>
|
||||
ages_map = gon.musician_search_meta['ages']['map']
|
||||
$.each gon.musician_search_meta['ages']['keys'], (index, key) =>
|
||||
ageTemplate = $('#template-search-filter-setup-ages').html()
|
||||
selected = ''
|
||||
ageLabel = ages_map[key]
|
||||
|
|
@ -109,6 +109,8 @@ context.JK.MusicianSearchFilter = class MusicianSearchFilter
|
|||
checked: selected)
|
||||
$('#search-filter-ages').append ageHtml
|
||||
|
||||
gotGenres: (genres) =>
|
||||
|
||||
populateGenres: () =>
|
||||
$('#search-filter-genres').empty()
|
||||
@rest.getGenres().done (genres) =>
|
||||
|
|
@ -118,15 +120,15 @@ context.JK.MusicianSearchFilter = class MusicianSearchFilter
|
|||
if 0 < @searchFilter.genres.length
|
||||
genreMatch = $.grep(@searchFilter.genres, (n, i) ->
|
||||
n == genre.id
|
||||
)
|
||||
if genreMatch.length > 0
|
||||
selected = 'checked'
|
||||
genreHtml = context.JK.fillTemplate(genreTemplate,
|
||||
id: genre.id
|
||||
description: genre.description
|
||||
checked: selected)
|
||||
$('#search-filter-genres').append genreHtml
|
||||
|
||||
)
|
||||
if genreMatch.length > 0
|
||||
selected = 'checked'
|
||||
genreHtml = context.JK.fillTemplate(genreTemplate,
|
||||
id: genre.id
|
||||
description: genre.description
|
||||
checked: selected)
|
||||
$('#search-filter-genres').append genreHtml
|
||||
|
||||
populateInstruments: () =>
|
||||
$('#search-filter-instruments').empty()
|
||||
@rest.getInstruments().done (instruments) =>
|
||||
|
|
@ -172,10 +174,10 @@ context.JK.MusicianSearchFilter = class MusicianSearchFilter
|
|||
vals
|
||||
|
||||
performSearch: () =>
|
||||
$.each gon.musician_search_filter.filter_keys.single, (index, key) =>
|
||||
$.each gon.musician_search_meta.filter_keys.single, (index, key) =>
|
||||
@searchFilter[key] = this._selectedValue(key)
|
||||
|
||||
$.each gon.musician_search_filter.filter_keys.multi, (index, key) =>
|
||||
$.each gon.musician_search_meta.filter_keys.multi, (index, key) =>
|
||||
@searchFilter[key] = this._selectedMultiValue(key)
|
||||
|
||||
@rest.postMusicianSearchFilter { filter: JSON.stringify(@searchFilter), page: 1 }
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class SpikesController < ApplicationController
|
|||
end
|
||||
|
||||
def musician_search_filter
|
||||
gon.musician_search_filter = MusicianSearch::SEARCH_FILTER_CONFIG
|
||||
gon.musician_search_meta = MusicianSearch::SEARCH_FILTER_CONFIG
|
||||
render :layout => 'web'
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,29 +2,36 @@ describe "MusicianSearchFilter", ->
|
|||
fixture.preload("musicianSearch.html")
|
||||
|
||||
beforeEach =>
|
||||
@server = sinon.fakeServer.create();
|
||||
@filterServer = sinon.fakeServer.create();
|
||||
window.jamClient = sinon.stub()
|
||||
@fixtures = fixture.load("musicianSearch.html", true)
|
||||
window.gon = {}
|
||||
window.gon.isNativeClient = true
|
||||
@defaultFilter = {"per_page":10,"filter_keys":{"keys":["sort_order","instruments","interests","genres","concert_gigs","studio_sessions","skill_level","ages"],"multi":["instruments","genres","ages"],"single":["sort_order","interests","concert_gigs","studio_sessions","skill_level"]},"sort_order":{"keys":["latency","distance"],"map":{"latency":"Latency to Me","distance":"Distance to Me"}},"interests":{"keys":["any","virtual_band","traditional_band","paid_sessions","free_sessions","cowriting"],"map":{"any":"Any","virtual_band":"Virtual Band","traditional_band":"Traditional Band","paid_sessions":"Paid Sessions","free_sessions":"Free Sessions","cowriting":"Co-Writing"}},"ages":{"keys":[-1,10,20,30,40,50],"map":{"-1":"Any","10":"Teens","20":"20's","30":"30's","40":"40's","50":"50+"}}}
|
||||
gon.musician_search_filter = @defaultFilter
|
||||
@searchMeta = {"per_page":10,"filter_keys":{"keys":["sort_order","instruments","interests","genres","concert_gigs","studio_sessions","skill_level","ages"],"multi":["instruments","genres","ages"],"single":["sort_order","interests","concert_gigs","studio_sessions","skill_level"]},"sort_order":{"keys":["latency","distance"],"map":{"latency":"Latency to Me","distance":"Distance to Me"}},"interests":{"keys":["any","virtual_band","traditional_band","paid_sessions","free_sessions","cowriting"],"map":{"any":"Any","virtual_band":"Virtual Band","traditional_band":"Traditional Band","paid_sessions":"Paid Sessions","free_sessions":"Free Sessions","cowriting":"Co-Writing"}},"ages":{"keys":[-1,10,20,30,40,50],"map":{"-1":"Any","10":"Teens","20":"20's","30":"30's","40":"40's","50":"50+"}}}
|
||||
window.gon.musician_search_meta = @searchMeta
|
||||
@defaultFilter = {sort_order: "latency", instruments: [], interests: "any", genres: [], concert_gigs: "-1", studio_sessions: "-1", skill_level: "-1", ages: [-1]}
|
||||
@genres = [{"description":"African","id":"african"},{"description":"Alternative Rock","id":"alternative rock"},{"description":"Ambient","id":"ambient"},{"description":"Americana","id":"americana"},{"description":"Asian","id":"asian"},{"description":"Avante-Garde","id":"avante-garde"},{"description":"Bluegrass","id":"bluegrass"},{"description":"Blues","id":"blues"},{"description":"Breakbeat","id":"breakbeat"},{"description":"Classical","id":"classical"},{"description":"Country","id":"country"},{"description":"Downtempo","id":"downtempo"},{"description":"Drum & Bass","id":"drum & bass"},{"description":"Electronic","id":"electronic"},{"description":"Folk","id":"folk"},{"description":"Hip Hop","id":"hip hop"},{"description":"House","id":"house"},{"description":"Industrial","id":"industrial"},{"description":"Jazz","id":"jazz"},{"description":"Latin","id":"latin"},{"description":"Metal","id":"metal"},{"description":"Other","id":"other"},{"description":"Pop","id":"pop"},{"description":"Psychedelic","id":"psychedelic"},{"description":"Punk","id":"punk"},{"description":"R&B","id":"r&b"},{"description":"Reggae","id":"reggae"},{"description":"Religious","id":"religious"},{"description":"Rock","id":"rock"},{"description":"Ska","id":"ska"},{"description":"Techno","id":"techno"},{"description":"Trance","id":"trance"}]
|
||||
@instruments = [{"id":"acoustic guitar","description":"Acoustic Guitar","popularity":3},{"id":"bass guitar","description":"Bass Guitar","popularity":3},{"id":"computer","description":"Computer","popularity":3},{"id":"drums","description":"Drums","popularity":3},{"id":"electric guitar","description":"Electric Guitar","popularity":3},{"id":"keyboard","description":"Keyboard","popularity":3},{"id":"voice","description":"Voice","popularity":3},{"id":"accordion","description":"Accordion","popularity":2},{"id":"banjo","description":"Banjo","popularity":2},{"id":"clarinet","description":"Clarinet","popularity":2},{"id":"flute","description":"Flute","popularity":2},{"id":"harmonica","description":"Harmonica","popularity":2},{"id":"piano","description":"Piano","popularity":2},{"id":"saxophone","description":"Saxophone","popularity":2},{"id":"trombone","description":"Trombone","popularity":2},{"id":"trumpet","description":"Trumpet","popularity":2},{"id":"upright bass","description":"Upright Bass","popularity":2},{"id":"violin","description":"Violin","popularity":2},{"id":"cello","description":"Cello","popularity":1},{"id":"euphonium","description":"Euphonium","popularity":1},{"id":"french horn","description":"French Horn","popularity":1},{"id":"mandolin","description":"Mandolin","popularity":1},{"id":"oboe","description":"Oboe","popularity":1},{"id":"other","description":"Other","popularity":1},{"id":"tuba","description":"Tuba","popularity":1},{"id":"ukulele","description":"Ukulele","popularity":1},{"id":"viola","description":"Viola","popularity":1}]
|
||||
|
||||
afterEach =>
|
||||
@server.restore()
|
||||
@filterServer.restore()
|
||||
|
||||
describe "displays empty search criteria", =>
|
||||
beforeEach =>
|
||||
@filterUI = new JK.MusicianSearchFilter()
|
||||
@filterUI.init()
|
||||
|
||||
it "displays validator widget", =>
|
||||
@server.respondWith("GET", "/api/search/musicians.json", [200, { "content-type": "application/json" }, JSON.stringify({sort_order: "latency", instruments: [], interests: "any", genres: [], concert_gigs: "-1", studio_sessions: "-1", skill_level: "-1", ages: [-1]})])
|
||||
sinon.spy()
|
||||
it "displays validator widget for default filter", =>
|
||||
@filterServer.respondWith("GET", "/api/search/musicians.json", [200, { "content-type": "application/json" }, JSON.stringify(@defaultFilter)])
|
||||
@filterServer.respondWith("GET", "/api/genres.json", [200, { "content-type": "application/json" }, JSON.stringify(@genres)])
|
||||
@filterServer.respondWith("GET", "/api/getInstruments.json", [200, { "content-type": "application/json" }, JSON.stringify(@instruments)])
|
||||
|
||||
@filterUI.afterShow();
|
||||
@server.respond()
|
||||
expect($('select[name="sort_order"]').val()).toEqual(@defaultFilter.sort_order.keys[0])
|
||||
expect($('select[name="interests"]').val()).toEqual(@defaultFilter.interests.keys[0])
|
||||
@filterServer.respond()
|
||||
expect($('#search-filter-genres input').length).toEqual(@genres.length)
|
||||
expect($('#search-filter-instruments input').length).toEqual(@instruments.length)
|
||||
expect($('select[name="sort_order"]').val()).toEqual(@searchMeta.sort_order.keys[0])
|
||||
expect($('select[name="interests"]').val()).toEqual(@searchMeta.interests.keys[0])
|
||||
expect($('select[name="skill_level"]').val()).toEqual("-1")
|
||||
expect($('select[name="studio_sessions"]').val()).toEqual("-1")
|
||||
expect($('select[name="concert_gigs"]').val()).toEqual("-1")
|
||||
|
|
@ -33,4 +40,18 @@ describe "MusicianSearchFilter", ->
|
|||
expect($('#search-filter-instruments input[selected]').length).toEqual(0)
|
||||
expect($('#search-filter-instruments select.proficiency_selector[value=2]').length).toEqual(0)
|
||||
|
||||
xit "displays validator widget for edited filter", =>
|
||||
@defaultFilter = {sort_order: @searchMeta.sort_order.keys[1], instruments: [], interests: @searchMeta.interests.keys[1], genres: ['ambient','asian'], concert_gigs: "1", studio_sessions: "1", skill_level: "1", ages: [-1]}
|
||||
@filterServer.respondWith("GET", "/api/search/musicians.json", [200, { "content-type": "application/json" }, JSON.stringify(@defaultFilter)])
|
||||
sinon.spy()
|
||||
@filterServer.respondWith("GET", "/api/genres.json", [200, { "content-type": "application/json" }, JSON.stringify(@genres)])
|
||||
sinon.spy()
|
||||
@filterUI.afterShow();
|
||||
@filterServer.respond()
|
||||
expect($('select[name="sort_order"]').val()).toEqual(@searchMeta.sort_order.keys[1])
|
||||
expect($('select[name="interests"]').val()).toEqual(@searchMeta.interests.keys[1])
|
||||
expect($('select[name="skill_level"]').val()).toEqual(@defaultFilter.skill_level)
|
||||
expect($('select[name="studio_sessions"]').val()).toEqual(@defaultFilter.studio_sessions)
|
||||
expect($('select[name="concert_gigs"]').val()).toEqual(@defaultFilter.concert_gigs)
|
||||
expect($('#search-filter-genres input[checked]').length).toEqual(@defaultFilter.genres.length)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue