-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Atchley
committed
Mar 14, 2017
1 parent
750c18a
commit dc57577
Showing
4 changed files
with
85 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 80 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = 0 | ||
trim_trailing_whitespace = false | ||
|
||
[COMMIT_EDITMSG] | ||
max_line_length = 0 |
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,64 @@ | ||
import { camelize, getStyle, getOverflow, hasOverflow } from '../utils'; | ||
|
||
function createMockDiv (width, height, styles = {}) { | ||
const div = document.createElement("div"); | ||
Object.assign(div.style, { | ||
width: width+"px", | ||
height: height+"px", | ||
}, styles); | ||
|
||
// we have to mock this for jsdom. | ||
div.getBoundingClientRect = () => ({ | ||
width: div.style.width || width, | ||
height: div.style.height || height, | ||
top: 0, | ||
left: 0, | ||
right: div.style.width || width, | ||
bottom: div.style.height || height, | ||
}); | ||
return div; | ||
} | ||
|
||
describe('camelize()', () => { | ||
it('correctly camelizes a dashed string', () => { | ||
const before = 'not-camelized-string'; | ||
const after = 'notCamelizedString'; | ||
expect(camelize(before)).toEqual(after); | ||
}); | ||
it('correctly camelizes a flat string', () => { | ||
const before = 'singlestring'; | ||
const after = 'singlestring'; | ||
expect(camelize(before)).toEqual(after); | ||
}); | ||
}); | ||
|
||
describe('getStyle()', () => { | ||
it('correctly gets style properties from an element', () => { | ||
document.body.innerHTML = `<html><body> | ||
<div class="target" style="font-size: 12px">testing</div> | ||
</body></html>`; | ||
|
||
const target = document.querySelector('.target'); | ||
expect(getStyle(target, 'font-size')).toEqual('12px'); | ||
}); | ||
}); | ||
|
||
describe('getOverflow() + hasOverflow()', () => { | ||
it('detects and tests for overflow', () => { | ||
document.body.innerHTML = '<html><body></body></html>'; | ||
|
||
const parent = createMockDiv(100, 100, { overflow: 'hidden' }); | ||
document.body.appendChild(parent); | ||
const child = createMockDiv(200, 200); | ||
parent.appendChild(child); | ||
|
||
expect(getOverflow(parent, child)).toMatchObject({ horizontal: true, vertical: true }); | ||
expect(hasOverflow(parent, child)).toEqual(true); | ||
child.style.height = '100px'; | ||
expect(getOverflow(parent, child)).toMatchObject({ horizontal: true, vertical: false }); | ||
expect(hasOverflow(parent, child)).toEqual(true); | ||
child.style.width = '100px'; | ||
expect(getOverflow(parent, child)).toMatchObject({ horizontal: false, vertical: false }); | ||
expect(hasOverflow(parent, child)).toEqual(false); | ||
}); | ||
}); |
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