-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from mkozhukharenko/feature/tests
refactor dictionary helpers + tests + table dimensions generator
- Loading branch information
Showing
18 changed files
with
486 additions
and
64 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/modules/commons/loader/spinner.jsx → src/modules/commons/loader/Spinner.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
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,13 @@ | ||
|
||
// FIXME: need to find out a better way to calculate a table dimensions. | ||
// maybe we can set a different column width depending how wide a user screen is | ||
export function setTableDimensions ({width, widthGutter, minHeight = 200, heightGutter}) { | ||
widthGutter = widthGutter || 20; | ||
heightGutter = heightGutter || 80; | ||
width = width || window.innerWidth - widthGutter; | ||
let height = window.innerHeight - heightGutter; | ||
return { | ||
width: width, | ||
height: height > minHeight ? height : minHeight | ||
} | ||
} |
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,136 @@ | ||
/** | ||
* Created by nikolaykozhukharenko on 4/24/16. | ||
*/ | ||
|
||
import chai, {expect} from 'chai'; | ||
chai.should(); | ||
import {isDictLoaded, createDataMap} from './helpers' | ||
|
||
describe('dictionary helper', () => { | ||
|
||
let listOfDict = ['dic_01', 'dic_02']; | ||
let dictState = { | ||
'dic_01': { | ||
isLoading: false, | ||
resources: [1,3,4] | ||
}, | ||
'dic_02': { | ||
isLoading: false, | ||
resources: [5,7,9] | ||
} | ||
}; | ||
|
||
describe('isDictLoaded fn', () => { | ||
|
||
it('should throw an error if wrong parameters were passed', () => { | ||
expect(isDictLoaded.bind({}, false, 1)).to.throw(Error) | ||
}); | ||
|
||
it('should return "false" if dictionaries state it empty', () => { | ||
isDictLoaded([], {}).should.equal(false) | ||
}); | ||
|
||
it('should throw an error if dic does not exists', () => { | ||
expect(isDictLoaded.bind({}, ['DontExistDictName'], dictState)) | ||
.to.throw(ReferenceError) | ||
}); | ||
|
||
it('should not throw an error if listOfDict eq to string', () => { | ||
expect(isDictLoaded.bind({}, 'dic_01', dictState)) | ||
.to.not.throw(Error) | ||
}); | ||
|
||
it('should return "true" if data for dictionaries exists', () => { | ||
isDictLoaded(listOfDict, dictState).should.equal(true) | ||
}); | ||
|
||
it('should return "false" if one of dict "isLoading" right now', () => { | ||
isDictLoaded(listOfDict, { | ||
'dic_01': { | ||
isLoading: true, | ||
resources: [1,3,5] | ||
}, | ||
'dic_02': { | ||
isLoading: false, | ||
resources: [4,6,7] | ||
} | ||
}).should.equal(false) | ||
}); | ||
|
||
it('should return "false" if one of dict do not have "resources" field ', () => { | ||
isDictLoaded(listOfDict, { | ||
'dic_01': { | ||
isLoading: false | ||
}, | ||
'dic_02': { | ||
isLoading: false, | ||
resources: [4,6,7] | ||
} | ||
}).should.equal(false) | ||
}); | ||
|
||
it('should return "false" if one of dict has an empty "resources"', () => { | ||
isDictLoaded(listOfDict, { | ||
'dic_01': { | ||
isLoading: false, | ||
resources: [1,3,5] | ||
}, | ||
'dic_02': { | ||
isLoading: false, | ||
resources: [] | ||
} | ||
}).should.equal(false) | ||
}); | ||
|
||
it('should return "true" when one dict (as a string) was passed ', () => { | ||
isDictLoaded('dic_011', { | ||
'dic_011': { | ||
isLoading: false, | ||
resources: [1,3,5] | ||
}, | ||
'dic_02': { | ||
isLoading: false, | ||
resources: [] | ||
} | ||
}).should.equal(true) | ||
}); | ||
}); | ||
|
||
|
||
describe('isDictLoaded fn', () => { | ||
it('should return an array', () => { | ||
expect(createDataMap([ | ||
{ | ||
id: 0, | ||
name: 'name_01' | ||
} | ||
])).to.be.instanceof(Array); | ||
}); | ||
|
||
it('should return a map', () => { | ||
expect(createDataMap([ | ||
{ | ||
id: 0, | ||
name: 'name_01' | ||
}, | ||
{ | ||
id: 1, | ||
name: 'name_02' | ||
} | ||
])).to.eql(['name_01','name_02']) | ||
}); | ||
|
||
it('should return a map when id order is different', () => { | ||
expect(createDataMap([ | ||
{ | ||
id: 1, | ||
name: 'name_01' | ||
}, | ||
{ | ||
id: 3, | ||
name: 'name_02' | ||
} | ||
])).to.eql([,'name_01',,'name_02']) | ||
}); | ||
}) | ||
}); |
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
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
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
Oops, something went wrong.