-
Notifications
You must be signed in to change notification settings - Fork 35
/
set_spec.js
136 lines (94 loc) · 4.85 KB
/
set_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
describe("Set", function() {
var graph, ajaxSpy;
beforeAll(function() {
var fixture = loadFixtures('graph.html');
var setJSON = getJSONFixture('set-1.json');
jasmine.Ajax.install();
ajaxSpy = spyOn($, "ajax").and.callFake(function(object) {
var response,
url = object.url.split('?')[0]; // remove cache-clearing additions
if (url == '/spectrums/9.json') response = object.success(TestResponses.spectrum.success.responseText);
else if (url == '/sets/calibrated/1.json') response = object.success(setJSON); // faking with JSON fixture
else if (url == '/spectrums/9/tags') response = object.success(TestResponses.tags.success.responseText);
else if (url == '/spectrums/clone_calibration/9.json') response = object.success('success');
else if (url == '/match/search/9.json') response = object.success([TestResponses.spectrum.success.responseText]); // return an array containing same spectrum
else response = 'none';
// check this if you have trouble faking a server response:
if (response != 'none') console.log('Faked response to:', object.url)
else console.log('Failed to fake response to:', object.url)
});
graph = new SpectralWorkbench.Graph({
set_id: 1,
calibrated: true,
onComplete: function(graph) { // fires when graph.image is loaded, so that later tests can run
expect(graph).toBeDefined();
expect(graph.datum).toBeDefined();
expect(graph.dataType).toBe('set');
// done(); // for some reason, this doesn't need to be aynchronous with a Set. Not sure why? It does for a spectrum...
}
});
});
afterAll(function() {
jasmine.Ajax.uninstall();
});
it("should initialize line styling and table rows properly", function() {
expect(graph).toBeDefined();
expect(graph.datum).toBeDefined();
// you can't do jquery hasClass() to SVGs, but d3 can do classed();
expect(d3.selectAll('g#spectrum-line-1')[0].length).toBe(2); // in main graph and in zoom graph
expect(d3.selectAll('g#spectrum-line-2')[0].length).toBe(2); // in main graph and in zoom graph
expect(d3.selectAll('g#spectrum-line-4')[0].length).toBe(2); // in main graph and in zoom graph
expect(d3.selectAll('g#spectrum-line-6')[0].length).toBe(2); // in main graph and in zoom graph
expect(d3.select('g#spectrum-line-1').classed('dimmed')).toBe(false);
expect(d3.select('g#spectrum-line-2').classed('dimmed')).toBe(false);
expect(d3.select('g#spectrum-line-4').classed('dimmed')).toBe(false);
expect(d3.select('g#spectrum-line-6').classed('dimmed')).toBe(false);
// these are currently manually added in the graph.html static fixture,
// since they're normally generated by Ruby
expect($('tr.spectrum-1').length).toBe(1);
expect($('tr.spectrum-2').length).toBe(1);
expect($('tr.spectrum-4').length).toBe(1);
expect($('tr.spectrum-6').length).toBe(1);
// Can't seem to handle graph persistence... bah.
// If we separate specs, the selectors don't find anything anymore
/*
});
it("should highlight graph line and dim others when hovering over table row", function() {
*/
$('tr.spectrum-1').mouseover();
expect(d3.select('g#spectrum-line-1').classed('dimmed')).toBe(false);
expect(d3.select('g#spectrum-line-2').classed('dimmed')).toBe(true);
expect(d3.select('g#spectrum-line-4').classed('dimmed')).toBe(true);
expect(d3.select('g#spectrum-line-6').classed('dimmed')).toBe(true);
expect(d3.select('g#spectrum-line-1').classed('highlight')).toBe(true);
/*
});
it("should highlight table row when hovering over graph line ", function() {
*/
// Manual event triggering uses selection.dispatch in d3 4.0:
// https://github.com/d3/d3-selection#selection_dispatch
// in the meantime, we create a one-off trigger():
// https://github.com/d3/d3/issues/100
d3.selection.prototype.trigger = function( event ) {
var e = document.createEvent('Event');
e.initEvent( event, true, true);
this.each( function( d ) {
this.dispatchEvent( e );
});
return this;
}
// this syntax is to trigger an SVG mouseover using D3:
d3.select('g.nv-scatterWrap g#spectrum-hover-1').trigger('mouseover');
expect($('tr.spectrum-1').hasClass('highlight')).toBe(true);
expect($('tr.spectrum-2').hasClass('highlight')).toBe(false);
expect($('tr.spectrum-4').hasClass('highlight')).toBe(false);
expect($('tr.spectrum-6').hasClass('highlight')).toBe(false);
});
/*
// hover circles; should highlight table row
d3.selectAll('g.nv-scatterWrap g.nv-groups g').mouseover();
d3.selectAll('g#spectrum-line-'+datum.id).classed( 'highlight', true );
// each table row should have a colored key matching its graph line
$('tr.spectrum-'+datum.id+' div.key').css('background', $('g#spectrum-line-' + datum.id).css('stroke'));
*/
});