Skip to content

Commit 0c4fa28

Browse files
authored
chore: Adds docs for setInputValue helper in date-input test utils (#3682)
1 parent 57a3f88 commit 0c4fa28

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37350,15 +37350,14 @@ Returns the current value of the input.
3735037350
},
3735137351
},
3735237352
{
37353-
"description": "Sets the value of the component and calls the \`onChange\` handler",
37354-
"inheritedFrom": {
37355-
"name": "BaseInputWrapper.setInputValue",
37356-
},
37353+
"description": "Sets the value of the component and calls the \`onChange\` handler.
37354+
The value needs to use the "YYYY/MM/DD" format,
37355+
but the subsequent \`onChange\` handler will contain the value in the "YYYY-MM-DD" format.",
3735737356
"name": "setInputValue",
3735837357
"parameters": [
3735937358
{
3736037359
"description": "
37361-
The value the input is set to.
37360+
The value the input is set to, using the "YYYY/MM/DD" format.
3736237361
",
3736337362
"flags": {
3736437363
"isOptional": false,

src/date-input/__tests__/date-input.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,10 @@ describe('Date Input component', () => {
314314
expect(onChangeSpy).toHaveBeenCalledWith(expect.objectContaining({ detail: { value: '2019-02-28' } }));
315315
});
316316
}); // end entering value in middle of input
317+
318+
test('uses setInputValue test utils method', () => {
319+
const { wrapper, onChangeSpy } = renderDateInput({ value: '' });
320+
wrapper.setInputValue('2019/01/31');
321+
expect(onChangeSpy).toHaveBeenCalledWith(expect.objectContaining({ detail: { value: '2019-01-31' } }));
322+
});
317323
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { usesDom } from '@cloudscape-design/test-utils-core/dom';
5+
36
import BaseInputWrapper from '../input/base-input';
47

58
import selectors from '../../../date-input/styles.selectors.js';
69

710
export default class DateInputWrapper extends BaseInputWrapper {
811
static rootSelector: string = selectors.root;
12+
13+
/**
14+
* Sets the value of the component and calls the `onChange` handler.
15+
* The value needs to use the "YYYY/MM/DD" format,
16+
* but the subsequent `onChange` handler will contain the value in the "YYYY-MM-DD" format.
17+
*
18+
* @param value The value the input is set to, using the "YYYY/MM/DD" format.
19+
*/
20+
@usesDom setInputValue(value: string): void {
21+
return super.setInputValue(value);
22+
}
923
}

0 commit comments

Comments
 (0)