-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
588580c
commit a191c7d
Showing
3 changed files
with
492 additions
and
482 deletions.
There are no files selected for viewing
225 changes: 83 additions & 142 deletions
225
test/mocha/js/widgets/citation_graph_facet_widget.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,89 @@ | ||
define(["js/widgets/facet/factory", | ||
'js/components/api_response', | ||
'js/wraps/graph_tabs' | ||
], | ||
function(FacetFactory, ApiResponse, GraphTabs) { | ||
|
||
var testJSON = { | ||
"responseHeader": { | ||
"status": 0, | ||
"QTime": 7, | ||
"params": { | ||
"facet": "true", | ||
"fl": "id", | ||
"indent": "true", | ||
"q": "author:^accomazzi,a", | ||
"wt": "json", | ||
"facet.pivot": "property,citation_count" | ||
} | ||
define([ | ||
'js/widgets/facet/factory', | ||
'js/components/api_response', | ||
'js/wraps/graph_tabs', | ||
], function(FacetFactory, ApiResponse, GraphTabs) { | ||
const testJSON = { | ||
responseHeader: { | ||
status: 0, | ||
QTime: 2, | ||
params: { | ||
'json.facet': | ||
'{"citation_count":{"type":"terms","field":"citation_count","sort":{"index":"desc"},"limit":2000}}', | ||
q: 'author:"^accomazzi, a"', | ||
stats: 'true', | ||
fl: 'id', | ||
start: '0', | ||
sort: 'date desc,bibcode desc', | ||
rows: '10', | ||
wt: 'json', | ||
p_: '0', | ||
'stats.field': 'citation_count', | ||
}, | ||
"response": { | ||
"numFound": 34, | ||
"start": 0, | ||
"docs": [ | ||
{ | ||
"id": "4582438" | ||
}, | ||
{ | ||
"id": "4545442" | ||
}, | ||
{ | ||
"id": "4545606" | ||
}, | ||
{ | ||
"id": "9067423" | ||
}, | ||
{ | ||
"id": "8285512" | ||
}, | ||
{ | ||
"id": "8700936" | ||
}, | ||
{ | ||
"id": "3843891" | ||
}, | ||
{ | ||
"id": "3404318" | ||
}, | ||
{ | ||
"id": "3340879" | ||
}, | ||
{ | ||
"id": "3513629" | ||
} | ||
] | ||
}, | ||
response: { | ||
numFound: 48, | ||
start: 0, | ||
docs: [ | ||
{ id: '20302549' }, | ||
{ id: '18677923' }, | ||
{ id: '17584600' }, | ||
{ id: '15583916' }, | ||
{ id: '17796736' }, | ||
{ id: '15198148' }, | ||
{ id: '14998905' }, | ||
{ id: '13986258' }, | ||
{ id: '13985717' }, | ||
{ id: '15278338' }, | ||
], | ||
}, | ||
facets: { | ||
count: 48, | ||
citation_count: { | ||
buckets: [ | ||
{ val: 23, count: 1 }, | ||
{ val: 8, count: 1 }, | ||
{ val: 6, count: 4 }, | ||
{ val: 5, count: 1 }, | ||
{ val: 4, count: 3 }, | ||
{ val: 3, count: 4 }, | ||
{ val: 2, count: 3 }, | ||
{ val: 1, count: 4 }, | ||
{ val: 0, count: 27 }, | ||
], | ||
}, | ||
"facet_counts": { | ||
"facet_queries": {}, | ||
"facet_fields": {}, | ||
"facet_dates": {}, | ||
"facet_ranges": {}, | ||
"facet_pivot": { | ||
"property,citation_count": [ | ||
{ | ||
"field": "property", | ||
"value": "notrefereed", | ||
"count": 29, | ||
"pivot": [ | ||
{ | ||
"field": "citation_count", | ||
"value": 0, | ||
"count": 7 | ||
}, | ||
{ | ||
"field": "citation_count", | ||
"value": 1, | ||
"count": 3 | ||
}, | ||
{ | ||
"field": "citation_count", | ||
"value": 2, | ||
"count": 3 | ||
}, | ||
{ | ||
"field": "citation_count", | ||
"value": 3, | ||
"count": 3 | ||
}, | ||
{ | ||
"field": "citation_count", | ||
"value": 6, | ||
"count": 3 | ||
}, | ||
{ | ||
"field": "citation_count", | ||
"value": 4, | ||
"count": 1 | ||
} | ||
] | ||
}, | ||
|
||
{ | ||
"field": "property", | ||
"value": "refereed", | ||
"count": 5, | ||
"pivot": [ | ||
{ | ||
"field": "citation_count", | ||
"value": 0, | ||
"count": 3 | ||
}, | ||
{ | ||
"field": "citation_count", | ||
"value": 1, | ||
"count": 1 | ||
}, | ||
{ | ||
"field": "citation_count", | ||
"value": 20, | ||
"count": 1 | ||
} | ||
] | ||
} | ||
|
||
] | ||
} | ||
} | ||
}; | ||
|
||
describe("Graph for Citation Distribution in a List of Results", function() { | ||
|
||
var widget; | ||
|
||
beforeEach(function() { | ||
|
||
widget = GraphTabs().citationGraphWidget; | ||
widget.processResponse(new ApiResponse(testJSON)); | ||
}, | ||
stats: { | ||
stats_fields: { | ||
citation_count: { | ||
min: 0, | ||
max: 23, | ||
count: 48, | ||
missing: 0, | ||
sum: 94, | ||
sumOfSquares: 862, | ||
mean: 1.9583333333333333, | ||
stddev: 3.7978624073613076, | ||
}, | ||
}, | ||
}, | ||
}; | ||
describe('Graph for Citation Distribution in a List of Results', function() { | ||
var widget; | ||
|
||
}); | ||
beforeEach(function() { | ||
widget = GraphTabs().citationGraphWidget; | ||
widget.processResponse(new ApiResponse(testJSON)); | ||
}); | ||
|
||
it("should have a processResponse function that unspools a facet pivot query into a single, ordered array usable by d3", function(done) { | ||
var graphData = _.map(widget.model.attributes.graphData, _.values).join(','); | ||
//where y is # citations | ||
var expectedResults = 'true,1,20,false,2,6,false,3,6,false,4,6,false,5,4,false,6,3,false,7,3,false,8,3,false,9,2,false,10,2,false,11,2,true,12,1,false,13,1,false,14,1,false,15,1,true,16,0,true,17,0,true,18,0,false,19,0,false,20,0,false,21,0,false,22,0,false,23,0,false,24,0,false,25,0'; | ||
expect(graphData).to.eql(expectedResults); | ||
done(); | ||
}); | ||
it('should have a processResponse function that unspools a facet pivot query into a single, ordered array usable by d3', function(done) { | ||
var graphData = _.map(widget.model.attributes.graphData, _.values).join( | ||
',' | ||
); | ||
// where y is # citations | ||
var expectedResults = '0,23,1,8,2,6,3,5,4,4,5,3,6,2,7,1,8,0'; | ||
expect(graphData).to.eql(expectedResults); | ||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.