-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
135 additions
and
47 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
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,38 @@ | ||
// @flow | ||
import { warning } from '../../dev-warning'; | ||
|
||
const suffix: string = ` | ||
We expect a html5 doctype: <!doctype html> | ||
This is to ensure consistent browser layout and measurement | ||
More information: | ||
`; | ||
|
||
export default (doc: Document) => { | ||
const doctype: ?DocumentType = doc.doctype; | ||
|
||
if (!doctype) { | ||
warning(` | ||
No <!doctype html> found. | ||
${suffix} | ||
`); | ||
return; | ||
} | ||
|
||
if (doctype.name.toLowerCase() !== 'html') { | ||
warning(` | ||
Unexpected <!doctype> found: (${doctype.name}) | ||
${suffix} | ||
`); | ||
} | ||
|
||
if (doctype.publicId !== '') { | ||
warning(` | ||
Unexpected <!doctype> publicId found: (${doctype.publicId}) | ||
A html5 doctype does not have a publicId | ||
${suffix} | ||
`); | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @flow | ||
import invariant from 'tiny-invariant'; | ||
|
||
export default (): HTMLBodyElement => { | ||
const body: ?HTMLBodyElement = document.body; | ||
invariant(body, 'Cannot find document.body'); | ||
return body; | ||
}; |
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,8 @@ | ||
// @flow | ||
import invariant from 'tiny-invariant'; | ||
|
||
export default (): HTMLElement => { | ||
const doc: ?HTMLElement = document.documentElement; | ||
invariant(doc, 'Cannot find document.documentElement'); | ||
return doc; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// @flow | ||
import { JSDOM } from 'jsdom'; | ||
import checkDoctype from '../../../../src/view/drag-drop-context/check-doctype'; | ||
|
||
jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
||
afterEach(() => { | ||
console.warn.mockClear(); | ||
}); | ||
|
||
it('should pass if using a html doctype', () => { | ||
const jsdom = new JSDOM(`<!doctype html><p>Hello world</p>`); | ||
|
||
checkDoctype(jsdom.window.document); | ||
|
||
expect(console.warn).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should fail if there is no doctype', () => { | ||
const jsdom = new JSDOM(`<html><body>Hello world</body></html>`); | ||
|
||
checkDoctype(jsdom.window.document); | ||
|
||
expect(console.warn).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should fail if there is a non-html5 doctype', () => { | ||
// HTML 4.01 Strict | ||
const jsdom = new JSDOM( | ||
`<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><body>Hello world</body></html>`, | ||
); | ||
|
||
checkDoctype(jsdom.window.document); | ||
|
||
expect(console.warn).toHaveBeenCalled(); | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// @flow | ||
// $FlowFixMe - flow does not know what a SVGElement is | ||
export default (doc: HTMLDocument): SVGElement => | ||
export default (doc: HTMLElement): SVGElement => | ||
doc.createElementNS('http://www.w3.org/2000/svg', 'svg'); |
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