Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hover text bug #70

Merged
merged 5 commits into from Dec 4, 2015
Merged

Hover text bug #70

merged 5 commits into from Dec 4, 2015

Conversation

cldougl
Copy link
Member

@cldougl cldougl commented Dec 3, 2015

@@ -12,7 +12,7 @@ describe('Test plot structure', function () {

afterEach(destroyGraphDiv);

describe('cartesian plots', function() {
describe('cartesian plots', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cldougl you might want to try http://nategood.com/sublime-text-strip-whitespace-save

to avoid those nasty diff lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@@ -778,8 +778,9 @@ function createHoverText(hoverData, opts) {
var i, traceHoverinfo;
for (i = 0; i < hoverData.length; i++) {
traceHoverinfo = hoverData[i].trace.hoverinfo;
if (traceHoverinfo.indexOf('all')===-1 &&
traceHoverinfo.indexOf(hovermode)===-1) {
var parts = traceHoverinfo.split('+');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcjohnson this has me thinking that perhaps flaglist attributes should be stored in fullData as arrays instead of strings, to make comparison more seamless. Moreover, maybe the all flag should be expected to e.g. x+y+text+name in the default step.

Alternatively, we could cook a nice general lib function isInFlagList that would take care of the logic on demand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like isInFlagList better (I like it a lot, in fact 👍 ) - fullData isn't supposed to change things from data unless they're invalid, it's just supposed to fill in the blanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Let's keep that in mind when we get to #34. There are only a few flaglist attributes at the moment, but more are coming.


expect(d3.selectAll('g.axistext').size()).toEqual(0);
expect(d3.selectAll('g.hovertext').size()).toEqual(1);
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('<tspan class="line" dy="0em" x="9" y="-3.9453125">hover</tspan><tspan class="line" dy="1.3em" x="9" y="-3.9453125">text</tspan>');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥 nice <tspan>s

var mockCopy = Lib.extendDeep({}, mock);

beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we could have 1 beforeEach and multiple its?
pseudocode

var mockData, mockLayout

describe('hover tests', function () {
   mockData = mockData()
   mockLayout = mockLayout()

   beforeEach( function (done) {
       Plotly.plot(gd, mockData, mockLayout).then(done)
   })

   it('responds to hover', function () { // test that uses mockData and mockLayout }
   it('resonds to hover x', function () { // test ... }
})

We can put the var declarations global scope and then assign fresh copies in the single BeforeEach. No need for multiple describes and beforeEach's. If that is dooable is should really clear up the test.

For comparison check out the many Jest (Jasmine fork) tests in Filewell. We have a set of patterns that might be useful. https://github.com/plotly/streambed/blob/master/shelly/filewell/static/filewell/src/stores/__tests__/DirectoryStore-test.js

Here there is one BeforeEach to refresh state before each test and a few describe blocks that break the test into logical chunks. If we are just testing hover here one describe is probably enough

Check around the filewell src tree, every folder has a __test__ folder with Jest tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nop. That won't because we call Plotly.plot with different data each time.

We could only force update hovermode in gd directly without a plot call and test the labels then. But that feels kind of dirty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah aight - the only other suggestion I can think of is to remove the multiple BeforeEach and Describes and do something like

it('does hover things', function(done) {
    Plotly.plot(newGD(), newData(), newLayout()).then( function () {
       expect(thingsToHappen()).toBe(true)
       done()
    })
})

where you get shorter code but have 1 level of nesting in the tests.

@bpostlethwaite
Copy link
Member

looks pretty good to me. I think we can refactor the test to simplify it somewhat. Let me know if I can help with that. We have written hundreds of these damn things in Filewell and have a set of test helpers and patterns for dealing with State refresh

@bpostlethwaite
Copy link
Member

Okay previous suggestion was not going to work as @etpinard pointed out. Made another suggestion. It may or may not be worth it, your call. Looks 💃 to me!

Nice work!

@cldougl
Copy link
Member Author

cldougl commented Dec 4, 2015

Thanks for the tests suggestions/explanations @bpostlethwaite ! I have both options worked out- @etpinard or @mdtusz do you have a preference on which format we use for this (ben's nested suggestion or the current nested describes)?

@cldougl
Copy link
Member Author

cldougl commented Dec 4, 2015

@bpostlethwaite @etpinard false alarm- the new (done) pattern doesn't actually work (same problem as yesterday you can test expect(d3.selectAll('g.axistext').select('text').html()).toEqual(''); or expect(d3.selectAll('g.axistext').select('text').html()).toEqual('1');) or expect(d3.selectAll('g.axistext').select('text').html()).toEqual('a'); and the test will pass. We should just leave them as is with the beforeEach()

@etpinard
Copy link
Contributor

etpinard commented Dec 4, 2015

💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants