-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed
no implicit conversion of String into Integer
Error when Addi…
…ng/Editing Container Provider
- Loading branch information
1 parent
745d91d
commit 458cb18
Showing
3 changed files
with
141 additions
and
3 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,125 @@ | ||
import { trimFieldValue } from '../../components/provider-form/helper'; | ||
|
||
describe('trimFieldValue function', () => { | ||
it('should trim the hostname field', () => { | ||
const resource = { | ||
hostname: ' example.com ', | ||
otherField: 'value', | ||
}; | ||
|
||
const trimmedResource = trimFieldValue(resource); | ||
|
||
expect(trimmedResource.hostname).toEqual('example.com'); | ||
expect(trimmedResource.otherField).toEqual('value'); | ||
}); | ||
|
||
it('should handle nested objects and trim the hostname field', () => { | ||
const resource = { | ||
nestedObject: { | ||
hostname: ' nested-example.com ', | ||
}, | ||
otherField: 'value', | ||
}; | ||
|
||
const trimmedResource = trimFieldValue(resource); | ||
|
||
expect(trimmedResource.nestedObject.hostname).toEqual('nested-example.com'); | ||
expect(trimmedResource.otherField).toEqual('value'); | ||
}); | ||
|
||
it('should handle multiple nested objects and trim the hostname field', () => { | ||
const resource = { | ||
firstLevel: { | ||
nestedObject: { | ||
hostname: ' nested-example.com ', | ||
}, | ||
}, | ||
otherField: 'value', | ||
}; | ||
|
||
const trimmedResource = trimFieldValue(resource); | ||
|
||
expect(trimmedResource.firstLevel.nestedObject.hostname).toEqual('nested-example.com'); | ||
expect(trimmedResource.otherField).toEqual('value'); | ||
}); | ||
|
||
it('should handle undefined values', () => { | ||
const resource = { | ||
hostname: undefined, | ||
}; | ||
|
||
const trimmedResource = trimFieldValue(resource); | ||
|
||
expect(trimmedResource.hostname).toEqual(''); | ||
}); | ||
|
||
it('should handle null values', () => { | ||
const resource = { | ||
hostname: null, | ||
}; | ||
|
||
const trimmedResource = trimFieldValue(resource); | ||
|
||
expect(trimmedResource.hostname).toEqual(''); | ||
}); | ||
|
||
it('should not modify non-trimmed fields', () => { | ||
const resource = { | ||
username: 'user123', | ||
email: '[email protected]', | ||
}; | ||
|
||
const trimmedResource = trimFieldValue(resource); | ||
|
||
expect(trimmedResource.username).toEqual('user123'); | ||
expect(trimmedResource.email).toEqual('[email protected]'); | ||
}); | ||
|
||
it('should handle non-object values', () => { | ||
const resource = 'Hello'; | ||
|
||
const trimmedResource = trimFieldValue(resource); | ||
|
||
expect(trimmedResource).toEqual('Hello'); | ||
}); | ||
|
||
it('should handle non-object values inside an array', () => { | ||
const resource = [' example.com ', ' nested-example.com ', { hostname: ' test ' }]; | ||
|
||
const trimmedResource = trimFieldValue(resource); | ||
|
||
expect(trimmedResource).toEqual([' example.com ', ' nested-example.com ', { hostname: 'test' }]); | ||
}); | ||
|
||
it('should handle objects nested inside an array', () => { | ||
const resource = { | ||
otherField: ' example.com ', | ||
otherField2: [ | ||
{ | ||
firstLevel: { | ||
nestedObject: { | ||
hostname: ' nested-example.com ', | ||
}, | ||
}, | ||
nestedField: 'value', | ||
}, | ||
], | ||
}; | ||
|
||
const trimmedResource = trimFieldValue(resource); | ||
|
||
expect(trimmedResource).toEqual({ | ||
otherField: ' example.com ', | ||
otherField2: [ | ||
{ | ||
firstLevel: { | ||
nestedObject: { | ||
hostname: 'nested-example.com', | ||
}, | ||
}, | ||
nestedField: 'value', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |