File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
x-pack/platform/plugins/shared/streams_app/public/components/data_management/stream_detail_routing Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+ * or more contributor license agreements. Licensed under the Elastic License
4+ * 2.0; you may not use this file except in compliance with the Elastic License
5+ * 2.0.
6+ */
7+
8+ import { getHelpText } from './stream_name_form_row' ;
9+
10+ const prefix = 'logs.' ;
11+
12+ describe ( 'getHelpText' , ( ) => {
13+ it ( 'should return empty error help text when stream name is shorter than the prefix' , ( ) => {
14+ const streamNameWithEmptyChildName = 'logs.' ;
15+ const result = getHelpText ( prefix , streamNameWithEmptyChildName , false ) ;
16+ expect ( result ) . toBe ( 'Stream name must not be empty.' ) ;
17+ } ) ;
18+
19+ it ( 'should return name too long error help text when stream name is longer than 200 characters' , ( ) => {
20+ const streamNameLongerThan200Chars =
21+ 'logs.xwdaqmsegtkamcrofcfcomnlkkkrkqtlkbqizvjvtrbwereqygqaaxmodzccqipzpwymyowrtvljtxevczoohrbpgijilsdptszgssmrkpwhvkukkgiqhvmcuzygmolyyadbxwngbkqjkretmzhgntkjkhrmltgyurufizwlelvmaqtngwhwqhxpfsuxiivxspvtwfcem' ;
22+ const result = getHelpText ( prefix , streamNameLongerThan200Chars , false ) ;
23+ expect ( result ) . toBe ( 'Stream name cannot be longer than 200 characters.' ) ;
24+ } ) ;
25+
26+ it ( 'should return undefined help text when input is valid' , ( ) => {
27+ const validStreamName = 'logs.multiplayer' ;
28+ const result = getHelpText ( prefix , validStreamName , false ) ;
29+ expect ( result ) . toBeUndefined ( ) ;
30+ } ) ;
31+ } ) ;
Original file line number Diff line number Diff line change @@ -30,8 +30,11 @@ const MIN_NAME_LENGTH = 1;
3030const MAX_NAME_LENGTH = 200 ;
3131const PREFIX_MAX_VISIBLE_CHARACTERS = 25 ;
3232
33- // TODO: write a unit test for this function
34- const getHelpText = ( prefix : string , value : string , readOnly : boolean ) : string | undefined => {
33+ export const getHelpText = (
34+ prefix : string ,
35+ value : string ,
36+ readOnly : boolean
37+ ) : string | undefined => {
3538 if ( value . length <= prefix . length && ! readOnly ) {
3639 return i18n . translate ( 'xpack.streams.streamDetailRouting.emptyNameErrorHelpText' , {
3740 defaultMessage : 'Stream name must not be empty.' ,
You can’t perform that action at this time.
0 commit comments