Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Flow strict for some files
Browse files Browse the repository at this point in the history
Summary: I went through all the test files and was able to make some of them flow strict.

Reviewed By: sophiebits

Differential Revision: D10236583

fbshipit-source-id: 480b6dc959ab9e93cb27efb8ac4d85817a76eb53
  • Loading branch information
niveditc authored and facebook-github-bot committed Oct 8, 2018
1 parent 800d6b5 commit bbd3ef1
Show file tree
Hide file tree
Showing 31 changed files with 53 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @emails oncall+draft_js
* @format
* @flow
* @flow strict-local
*/

'use strict';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const ContentBlock = require('ContentBlock');
const ContentBlockNode = require('ContentBlockNode');
const ContentState = require('ContentState');
const DraftEntityInstance = require('DraftEntityInstance');
const Immutable = require('immutable');

const convertFromDraftStateToRaw = require('convertFromDraftStateToRaw');
const getSampleStateForTesting = require('getSampleStateForTesting');
const Immutable = require('immutable');

const {contentState} = getSampleStateForTesting();

Expand Down
3 changes: 2 additions & 1 deletion src/model/encoding/__tests__/decodeInlineStyleRanges-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand All @@ -17,7 +18,7 @@ jest.disableAutomock();
const decodeInlineStyleRanges = require('decodeInlineStyleRanges');

test('must decode for an unstyled block', () => {
const block = {text: 'Hello'};
const block = {text: 'Hello', inlineStyleRanges: []};
expect(
decodeInlineStyleRanges(block.text, block.inlineStyleRanges).map(r =>
r.toJS(),
Expand Down
3 changes: 2 additions & 1 deletion src/model/encoding/__tests__/encodeEntityRanges-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand All @@ -15,10 +16,10 @@
jest.disableAutomock();

const ContentBlock = require('ContentBlock');
const Immutable = require('immutable');

const createCharacterList = require('createCharacterList');
const encodeEntityRanges = require('encodeEntityRanges');
const Immutable = require('immutable');

const {OrderedSet, Repeat} = Immutable;

Expand Down
3 changes: 2 additions & 1 deletion src/model/encoding/__tests__/encodeInlineStyleRanges-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand All @@ -15,11 +16,11 @@
jest.disableAutomock();

const ContentBlock = require('ContentBlock');
const Immutable = require('immutable');
const SampleDraftInlineStyle = require('SampleDraftInlineStyle');

const createCharacterList = require('createCharacterList');
const encodeInlineStyleRanges = require('encodeInlineStyleRanges');
const Immutable = require('immutable');

const {
BOLD,
Expand Down
1 change: 1 addition & 0 deletions src/model/encoding/__tests__/sanitizeDraftText-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down
1 change: 1 addition & 0 deletions src/model/entity/__mocks__/DraftEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
* @flow strict-local
* @emails oncall+draft_js
*/

Expand Down
2 changes: 1 addition & 1 deletion src/model/entity/__tests__/DraftEntity-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down Expand Up @@ -40,7 +41,6 @@ test('must retrieve an instance given a key', () => {
test('must throw when retrieving for an invalid key', () => {
createLink();
expect(() => DraftEntity.__get('asdfzxcvqweriuop')).toThrow();
expect(() => DraftEntity.__get(null)).toThrow();
});

test('must merge data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down
1 change: 1 addition & 0 deletions src/model/immutable/__tests__/CharacterMetadata-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down
6 changes: 4 additions & 2 deletions src/model/immutable/__tests__/ContentBlock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand All @@ -16,9 +17,10 @@ jest.disableAutomock();

const CharacterMetadata = require('CharacterMetadata');
const ContentBlock = require('ContentBlock');
const Immutable = require('immutable');
const {BOLD} = require('SampleDraftInlineStyle');

const Immutable = require('immutable');

const ENTITY_KEY = 'x';

const getSampleBlock = () => {
Expand Down Expand Up @@ -53,7 +55,7 @@ test('must have appropriate default values', () => {
});

test('must provide default values', () => {
const block = new ContentBlock();
const block = new ContentBlock({});
expect(block.getType()).toMatchSnapshot();
expect(block.getText()).toMatchSnapshot();
expect(
Expand Down
3 changes: 2 additions & 1 deletion src/model/immutable/__tests__/ContentBlockNode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ jest.disableAutomock();

const CharacterMetadata = require('CharacterMetadata');
const ContentBlockNode = require('ContentBlockNode');
const Immutable = require('immutable');
const {BOLD, NONE} = require('SampleDraftInlineStyle');

const Immutable = require('immutable');

const entity_KEY = 'x';

const DEFAUL_BLOCK_CONFIG = {
Expand Down
2 changes: 1 addition & 1 deletion src/model/immutable/__tests__/ContentState-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down Expand Up @@ -101,7 +102,6 @@ test('must retrieve an entities instance given a key', () => {
test('must throw when retrieving entities for an invalid key', () => {
const contentState = createLink();
expect(() => contentState.getEntity('asdfzxcvqweriuop')).toThrow();
expect(() => contentState.getEntity(null)).toThrow();
});

test('must merge entities data', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/model/immutable/__tests__/EditorBidiService-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand All @@ -17,6 +18,7 @@ jest.disableAutomock();
const ContentBlock = require('ContentBlock');
const ContentState = require('ContentState');
const EditorBidiService = require('EditorBidiService');

const Immutable = require('immutable');

const {OrderedMap, Seq} = Immutable;
Expand Down
1 change: 1 addition & 0 deletions src/model/immutable/__tests__/SelectionState-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down
4 changes: 2 additions & 2 deletions src/model/immutable/__tests__/findRangesImmutable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

'use strict';

jest.disableAutomock();

const Immutable = require('immutable');

const findRangesImmutable = require('findRangesImmutable');
const Immutable = require('immutable');

const {List} = Immutable;

Expand Down
9 changes: 5 additions & 4 deletions src/model/modifier/__tests__/AtomicBlockUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down Expand Up @@ -40,8 +41,6 @@ const getInvariantViolation = msg => {
} catch (e) {
return e;
}

throw new Error('We should never reach here!');
};

const toggleExperimentalTreeDataSupport = enabled => {
Expand Down Expand Up @@ -76,7 +75,7 @@ const assertMoveAtomicBlock = (
atomicBlock,
seletion,
state = editorState,
insertionType = null,
insertionType,
) => {
const newState = AtomicBlockUtils.moveAtomicBlock(
state,
Expand All @@ -88,7 +87,9 @@ const assertMoveAtomicBlock = (
return newState;
};

beforeEach(() => jest.resetModules());
beforeEach(() => {
jest.resetModules();
});

test('must insert atomic at start of block with collapsed seletion', () => {
assertInsertAtomicBlock();
Expand Down
1 change: 1 addition & 0 deletions src/model/modifier/__tests__/DraftRemovableWord-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand All @@ -20,10 +21,10 @@ const ContentBlock = require('ContentBlock');
const ContentBlockNode = require('ContentBlockNode');
const ContentState = require('ContentState');
const EditorState = require('EditorState');
const Immutable = require('immutable');
const SelectionState = require('SelectionState');

const getContentStateFragment = require('getContentStateFragment');
const Immutable = require('immutable');

const {List} = Immutable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

Expand All @@ -19,10 +20,10 @@ jest.mock('generateRandomKey');
const BlockMapBuilder = require('BlockMapBuilder');
const ContentBlock = require('ContentBlock');
const ContentBlockNode = require('ContentBlockNode');
const Immutable = require('immutable');
const SelectionState = require('SelectionState');

const getSampleStateForTesting = require('getSampleStateForTesting');
const Immutable = require('immutable');
const insertFragmentIntoContentState = require('insertFragmentIntoContentState');
const invariant = require('invariant');

Expand All @@ -33,7 +34,7 @@ const DEFAULT_BLOCK_CONFIG = {
key: 'j',
type: 'unstyled',
text: 'xx',
data: new Map({a: 1}),
data: Map({a: 1}),
};

const initialBlock = contentState.getBlockMap().first();
Expand All @@ -46,18 +47,16 @@ const getInvariantViolation = msg => {
} catch (e) {
return e;
}

throw new Error('We should never reach here!');
};

const createFragment = (fragment = {}, experimentalTreeDataSupport = false) => {
const ContentBlockNodeRecord = experimentalTreeDataSupport
? ContentBlockNode
: ContentBlock;
fragment = Array.isArray(fragment) ? fragment : [fragment];
const newFragment = Array.isArray(fragment) ? fragment : [fragment];

return BlockMapBuilder.createFromArray(
fragment.map(
newFragment.map(
config =>
new ContentBlockNodeRecord({
...DEFAULT_BLOCK_CONFIG,
Expand Down Expand Up @@ -124,7 +123,7 @@ test('must apply multiblock fragments', () => {
{
key: 'k',
text: 'yy',
data: new Map({b: 2}),
data: Map({b: 2}),
},
]),
);
Expand All @@ -138,7 +137,6 @@ test('must be able to insert a fragment with a single ContentBlockNode', () => {
{
key: 'A',
text: '',
data: null,
},
]),
);
Expand Down Expand Up @@ -375,7 +373,6 @@ test('must throw an error when trying to apply ContentBlockNode fragments when s
{
key: 'A',
text: '',
data: null,
children: List(['B']),
},
{
Expand Down
Loading

0 comments on commit bbd3ef1

Please sign in to comment.