-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COMPASS-468 schema shows undefined (#689)
* sort types on mount rather than during render phase * pushed sorting field types up to index level * COMPASS-469 show minicharts for unique long type * attempting enzyme test * adding tooltip to d3/shared * getting tests for minicharts working. * added a couple of tests * added tests * COMPASS-468 pushed sorting back to fields from index * fixed error and improved test cases
- Loading branch information
1 parent
e8cfb38
commit 57ee4a0
Showing
2 changed files
with
152 additions
and
8 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* eslint no-unused-expressions: 0 */ | ||
/* eslint no-unused-vars: 0 */ | ||
const app = require('ampersand-app'); | ||
const chai = require('chai'); | ||
const chaiEnzyme = require('chai-enzyme'); | ||
const expect = chai.expect; | ||
const React = require('react'); | ||
const AppRegistry = require('hadron-app-registry'); | ||
|
||
const mount = require('enzyme').mount; | ||
|
||
chai.use(chaiEnzyme()); | ||
|
||
describe('<Schema />', () => { | ||
let component; | ||
|
||
const fieldProp = { | ||
count: 2, | ||
has_duplicates: true, | ||
name: 'foo', | ||
path: 'foo', | ||
probability: 0.4 | ||
}; | ||
|
||
const typesWithUndefined = [ | ||
{ | ||
count: 2, | ||
has_duplicates: true, | ||
name: 'String', | ||
path: 'foo', | ||
probability: 0.4, | ||
total_count: 0, | ||
unique: 1, | ||
values: ['bar', 'bar'] | ||
}, | ||
{ | ||
count: 3, | ||
has_duplicates: true, | ||
name: 'Undefined', | ||
path: 'foo', | ||
probability: 0.6, | ||
total_count: 0, | ||
type: 'Undefined' | ||
} | ||
]; | ||
|
||
const typesWithMultiple = [ | ||
{ | ||
count: 2, | ||
has_duplicates: true, | ||
name: 'Long', | ||
path: 'foo', | ||
probability: 0.2, | ||
total_count: 0, | ||
unique: 1, | ||
values: [4, 2] | ||
}, | ||
{ | ||
count: 3, | ||
has_duplicates: true, | ||
name: 'String', | ||
path: 'foo', | ||
probability: 0.3, | ||
total_count: 0, | ||
unique: 1, | ||
values: ['bar', 'bar', 'foo'] | ||
}, | ||
{ | ||
count: 5, | ||
has_duplicates: true, | ||
name: 'Undefined', | ||
path: 'foo', | ||
probability: 0.5, | ||
total_count: 0, | ||
type: 'Undefined' | ||
} | ||
]; | ||
|
||
let appRegistry = app.appRegistry; | ||
before(function() { | ||
// Mock the AppRegistry with a new one so tests don't complain about | ||
// appRegistry.getComponent (i.e. appRegistry being undefined) | ||
app.appRegistry = new AppRegistry(); | ||
// register QueryStore | ||
require('../src/internal-packages/query').activate(); | ||
}); | ||
after(function() { | ||
// unregister QueryStore | ||
require('../src/internal-packages/query').deactivate(); | ||
// Restore properties on the global app object, | ||
// so they don't affect other tests | ||
app.appRegistry = appRegistry; | ||
}); | ||
|
||
context('when adding fields to the schema view', () => { | ||
it('renders field types', () => { | ||
const Field = require('../src/internal-packages/schema/lib/component/field'); | ||
const Type = require('../src/internal-packages/schema/lib/component/type'); | ||
|
||
fieldProp.types = typesWithUndefined; | ||
component = mount(<Field {...fieldProp} />); | ||
expect(component.find(Type)).to.have.length(2); | ||
}); | ||
|
||
it('renders the first type as string', () => { | ||
const Field = require('../src/internal-packages/schema/lib/component/field'); | ||
const Type = require('../src/internal-packages/schema/lib/component/type'); | ||
|
||
fieldProp.types = typesWithUndefined; | ||
component = mount(<Field {...fieldProp} />); | ||
expect(component.find(Type).at(0)).to.have.data('tip', 'String (40%)'); | ||
expect(component.find('.schema-field-type-string')).to.have.className('active'); | ||
}); | ||
|
||
it('renders the second type as undefined', () => { | ||
const Field = require('../src/internal-packages/schema/lib/component/field'); | ||
const Type = require('../src/internal-packages/schema/lib/component/type'); | ||
|
||
fieldProp.types = typesWithUndefined; | ||
component = mount(<Field {...fieldProp} />); | ||
expect(component.find(Type).at(1)).to.have.data('tip', 'Undefined (60%)'); | ||
expect(component.find('.schema-field-type-undefined')).to.not.have.className('active'); | ||
}); | ||
|
||
context('when rendering multiple fields', () => { | ||
it('renders type with highest probability first', () => { | ||
const Field = require('../src/internal-packages/schema/lib/component/field'); | ||
const Type = require('../src/internal-packages/schema/lib/component/type'); | ||
|
||
fieldProp.types = typesWithMultiple; | ||
component = mount(<Field {...fieldProp} />); | ||
expect(component.find(Type).at(0)).to.have.data('tip', 'String (30%)'); | ||
expect(component.find('.schema-field-type-string')).to.have.className('active'); | ||
expect(component.find(Type).at(1)).to.have.data('tip', 'Long (20%)'); | ||
expect(component.find('.schema-field-type-long')).to.not.have.className('active'); | ||
expect(component.find(Type).at(2)).to.have.data('tip', 'Undefined (50%)'); | ||
expect(component.find('.schema-field-type-undefined')).to.not.have.className('active'); | ||
}); | ||
}); | ||
}); | ||
}); |