Skip to content

Revert "Revert "Revert "Revert "NetSim: Teacher view dropdown bug""""#9830

Merged
islemaster merged 2 commits into
stagingfrom
revert-9829-revert-9819-revert-9818-revert-9809-netsim-teacher-view-dropdown-bug
Aug 4, 2016
Merged

Revert "Revert "Revert "Revert "NetSim: Teacher view dropdown bug""""#9830
islemaster merged 2 commits into
stagingfrom
revert-9829-revert-9819-revert-9818-revert-9809-netsim-teacher-view-dropdown-bug

Conversation

@islemaster

@islemaster islemaster commented Aug 4, 2016

Copy link
Copy Markdown
Contributor

Reverts #9829 (Third attempt at merging #9809)

Okay. This change failed on staging twice in a row, but has passed CircleCI and local tests every time. Something must be different about the staging box. Starting an investigation...

Here's the failure from the build log (repeated several times - it retried, I think?)

FAILED TESTS:
  SentByDropdown
    – only shows each name once
      PhantomJS 2.1.1 (Linux 0.0.0)
    expected { Object (component, root, ...) } to have a length of 1 but got 0
    AssertionError@[CDO]/apps/test/unit-tests.js:470:25 <- webpack:///~/chai/~/assertion-error/index.js:74:0
    assert@[CDO]/apps/test/unit-tests.js:4571:32 <- webpack:///~/chai/lib/chai/assertion.js:107:0
    assertLength@[CDO]/apps/test/unit-tests.js:5646:17 <- webpack:///~/chai/lib/chai/core/assertions.js:1045:0
    assert@[CDO]/apps/test/unit-tests.js:4370:55 <- webpack:///~/chai/lib/chai/utils/addChainableMethod.js:84:0
    [CDO]/apps/test/unit-tests.js:261874:89 <- webpack:///test/unit/netsim/NetSimLogBrowserFilters.js:81:67

Here's the source of that test, along with everything I think is relevant:

// ./apps/test/unit/netsim/NetSimLogBrowserFilters.js
import React from 'react';
import {shallow, mount} from 'enzyme';
import {spy} from 'sinon';
import {expect} from '../../util/configuredChai';
import {throwOnConsoleErrors} from '../../util/testUtils';
import NetSimLogBrowserFilters, {SentByDropdown} from '@cdo/apps/netsim/NetSimLogBrowserFilters';
import i18n from '@cdo/netsim/locale';

describe('SentByDropdown', function () { // Line 55
  it('only shows each name once', function () {   // Line 73
    const result = mountWithLogRows([
      {'sent-by': 'Alice'},
      {'sent-by': 'Alice'},
      {'sent-by': 'Bob'},
      {'sent-by': 'Bob'},
      {'sent-by': 'Bob'}
    ]);
    expect(result.find('option[value="by Alice"]')).to.have.length(1); // Line 81, the failed assertion
    expect(result.find('option[value="by Bob"]')).to.have.length(1);
  });

function mountWithLogRows(logRows) { // Line 107
    return mount(
      <SentByDropdown
        i18n={i18n}
        currentSentByFilter="none"
        setSentByFilter={spy()}
        logRows={logRows}
      />
    );
  }
});

Checking for environmental differences between my machine and staging:

Property Staging My machine Different?
Node version 0.12.15 0.12.15
NPM version 2.15.9 2.15.1 Yes
react 15.2.1 (dependencies using 15.1.0, 15.3.0) 15.2.1 (dependencies using 15.3.0)
enzyme 2.3.0 2.4.1 Yes
chai 3.5.0 3.5.0
chai-enzyme 0.5.0 0.5.0
chai-subset 1.2.0 1.2.0
sinon 2.0.0-pre 2.0.0-pre.2 Yes

Suspect #1 is enzyme, which is important to this test and is off by a minor version. Installing enzyme 2.3.0 on my local machine and running grunt unitTest reproduces the failure!

Pinning enzyme to 2.4.1 will fix the problem, but I'd like to understand what changed and why my test is failing. The enzyme 2.4.0 changelog contains some fixes to attribute selectors; sure enough, rewriting my assertions to avoid attribute selectors gets them passing under 2.3.0:

// expect(result.find('option[value="by Alice"]')).to.have.length(1);
expect(result.find('option').findWhere(n => n.prop('value') === "by Alice")).to.have.length(1);

What bothers me is that I can't figure out which change actually fixed this selector. enzymejs/enzyme#412 and enzymejs/enzyme#387 look most relevant but it's not clear that either should have directly affected the selector option[value="by Alice"] which freaks me out a bit. Update: Found it! This PR fixes a bug with spaces in selectors, and was not listed in the changelog for some reason. I'll contact enzyme and suggest this get mentioned.

In any case, I'd prefer not to switch to this; CSS-style attribute selectors are supposedly supported by Enzyme and they do work under 2.4.1. Instead we're going to pin to enzyme 2.4.1 which supports selectors with spaces, to avoid differences between dev and staging in the future.

islemaster added a commit to islemaster/enzyme that referenced this pull request Aug 4, 2016
Support for spaces in attribute selector values was added in 2.4.0 ([PR enzymejs#427](enzymejs#427)) but was not documented in the changelog.  It took me a while to sort out why my selectors `option[value="by Alice"]` were working in 2.4.1 but not 2.3.0 ([see my gradual realization here](code-dot-org/code-dot-org#9830)).  I'm recommending this get added to the changelog to save others some time.
Fix enzyme version to avoid future differences between development boxes and the staging machine.  Use 2.4.1 in particular because it's currently the latest, and 2.4.0 introduces support for spaces in attribute selector values (which this test uses).
@balderdash

Copy link
Copy Markdown
Contributor

Sounds like this was a fun investigation.

LGTM

@islemaster islemaster merged commit bc62be1 into staging Aug 4, 2016
@islemaster islemaster deleted the revert-9829-revert-9819-revert-9818-revert-9809-netsim-teacher-view-dropdown-bug branch August 4, 2016 20:06
@jeremydstone

Copy link
Copy Markdown

LGTM as well

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.

3 participants