-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block Editor: Separate onChange from onInput as committing change
- Loading branch information
Showing
4 changed files
with
263 additions
and
6 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
95 changes: 95 additions & 0 deletions
95
packages/block-editor/src/components/provider/test/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
hasSameKeys, | ||
isUpdatingSameBlockAttribute, | ||
} from '../'; | ||
|
||
describe( 'hasSameKeys()', () => { | ||
it( 'returns false if two objects do not have the same keys', () => { | ||
const a = { foo: 10 }; | ||
const b = { bar: 10 }; | ||
|
||
expect( hasSameKeys( a, b ) ).toBe( false ); | ||
} ); | ||
|
||
it( 'returns false if two objects have the same keys', () => { | ||
const a = { foo: 10 }; | ||
const b = { foo: 20 }; | ||
|
||
expect( hasSameKeys( a, b ) ).toBe( true ); | ||
} ); | ||
} ); | ||
|
||
describe( 'isUpdatingSameBlockAttribute()', () => { | ||
it( 'should return false if not updating block attributes', () => { | ||
const action = { | ||
type: 'START_TYPING', | ||
edits: {}, | ||
}; | ||
const previousAction = { | ||
type: 'START_TYPING', | ||
edits: {}, | ||
}; | ||
|
||
expect( isUpdatingSameBlockAttribute( action, previousAction ) ).toBe( false ); | ||
} ); | ||
|
||
it( 'should return false if not updating the same block', () => { | ||
const action = { | ||
type: 'UPDATE_BLOCK_ATTRIBUTES', | ||
clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', | ||
attributes: { | ||
foo: 10, | ||
}, | ||
}; | ||
const previousAction = { | ||
type: 'UPDATE_BLOCK_ATTRIBUTES', | ||
clientId: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', | ||
attributes: { | ||
foo: 20, | ||
}, | ||
}; | ||
|
||
expect( isUpdatingSameBlockAttribute( action, previousAction ) ).toBe( false ); | ||
} ); | ||
|
||
it( 'should return false if not updating the same block attributes', () => { | ||
const action = { | ||
type: 'UPDATE_BLOCK_ATTRIBUTES', | ||
clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', | ||
attributes: { | ||
foo: 10, | ||
}, | ||
}; | ||
const previousAction = { | ||
type: 'UPDATE_BLOCK_ATTRIBUTES', | ||
clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', | ||
attributes: { | ||
bar: 20, | ||
}, | ||
}; | ||
|
||
expect( isUpdatingSameBlockAttribute( action, previousAction ) ).toBe( false ); | ||
} ); | ||
|
||
it( 'should return true if updating the same block attributes', () => { | ||
const action = { | ||
type: 'UPDATE_BLOCK_ATTRIBUTES', | ||
clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', | ||
attributes: { | ||
foo: 10, | ||
}, | ||
}; | ||
const previousAction = { | ||
type: 'UPDATE_BLOCK_ATTRIBUTES', | ||
clientId: '9db792c6-a25a-495d-adbd-97d56a4c4189', | ||
attributes: { | ||
foo: 20, | ||
}, | ||
}; | ||
|
||
expect( isUpdatingSameBlockAttribute( action, previousAction ) ).toBe( true ); | ||
} ); | ||
} ); |
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