-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ControlOption and improvements
- Add missed `className`s properties to components - Introduce `assert` function - Improve public modules exposure - Increase code coverage
- Loading branch information
Showing
17 changed files
with
12,732 additions
and
16,750 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function assert(condition: boolean, message: string): asserts condition { | ||
if (!condition) { | ||
throw new Error(message); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,22 @@ | ||
import EntitiesSearch from '@types'; | ||
|
||
import { assert } from '../utils/assert'; | ||
|
||
export class ControlOption<V> implements EntitiesSearch.ControlOption<V> { | ||
public readonly label: string; | ||
public readonly value: V; | ||
|
||
public constructor(label: string, value: V) { | ||
assert( | ||
label !== '', | ||
'ControlOption: Label must be a non empty string.' | ||
); | ||
assert( | ||
value !== '', | ||
'ControlOption: Value must be a non empty string.' | ||
); | ||
|
||
this.label = label; | ||
this.value = value; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/client/unit/components/__snapshots__/plural-select-control.test.tsx.snap
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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Posts Select Render the NoOptionsMessage component 1`] = ` | ||
<DocumentFragment> | ||
<p | ||
class="wp-entities-search-no-option-message" | ||
> | ||
No options | ||
</p> | ||
</DocumentFragment> | ||
`; |
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
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,16 @@ | ||
/* | ||
* Write tests cases to ensure the assert function behaves as expected | ||
*/ | ||
import { expect, it, describe } from '@jest/globals'; | ||
|
||
import { assert } from '../../../../sources/client/src/utils/assert'; | ||
|
||
describe('assert', () => { | ||
it('should throw an error if the condition is false', () => { | ||
expect(() => assert(false, 'Failed')).toThrow(); | ||
}); | ||
|
||
it('should not throw an error if the condition is true', () => { | ||
expect(() => assert(true, 'Failed')).not.toThrow(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.