Skip to content

Commit

Permalink
unit tests to support sorting fields option
Browse files Browse the repository at this point in the history
  • Loading branch information
joemcelroy committed Apr 1, 2016
1 parent 10826fd commit c975192
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/__test__/core/accessors/SortingAccessorSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ describe("SortingAccessor", ()=> {
label:"Lowest Price",
field:'price',
key:"cheap"
},
{
label: "Highly rated",
key:"rated",
fields: [
{field:"rating", options:{order:"asc"}},
{field:"price", options:{order:"desc", customKey:"custom"}}
]
},
{
label: "Cheapest",
key:"cheapest",
fields: [
{field:"price", options:{order:'desc'}},
{field:"rated"}
]
}
]
}
Expand All @@ -33,7 +49,23 @@ describe("SortingAccessor", ()=> {
expect(this.options.options).toEqual([
{label: 'None', key: 'none'},
{label: 'Highest Price', field: 'price', order: 'desc', key: 'price_desc'},
{label: 'Lowest Price', field: 'price', key: 'cheap'}
{label: 'Lowest Price', field: 'price', key: 'cheap'},
{
label: "Highly rated",
key:"rated",
fields: [
{field:"rating", options:{order:"asc"}},
{field:"price", options:{order:"desc", customKey:"custom"}}
]
},
{
label: "Cheapest",
key:"cheapest",
fields: [
{field:"price", options:{order:'desc'}},
{field:"rated"}
]
}
])
})

Expand All @@ -50,6 +82,16 @@ describe("SortingAccessor", ()=> {
query = this.accessor.buildOwnQuery(query)
expect(query.query.sort).toEqual([{'price':'desc'}])

// handle complex sort
this.accessor.state = new ValueState("rated")
query = this.accessor.buildOwnQuery(query)
expect(query.query.sort).toEqual([{'rating':{order:'asc'}}, {'price':{order:'desc', customKey:'custom'}}])

// empty options
this.accessor.state = new ValueState("cheapest")
query = this.accessor.buildOwnQuery(query)
expect(query.query.sort).toEqual([{'price':{order:'desc'}}, {'rated':{}}])

// handle no options
this.accessor.options.options = []
query = this.accessor.buildOwnQuery(new ImmutableQuery())
Expand Down

0 comments on commit c975192

Please sign in to comment.