forked from apex-enterprise-patterns/fflib-apex-common
-
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.
Added objectHelper - which allows us to generate ids for use in the UI
- Loading branch information
1 parent
4e86c73
commit 1380b62
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
framework/default/ortoo-core/default/lwc/objectHelper/__tests__/objectHelper.test.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,20 @@ | ||
import ObjectHelper from 'c/objectHelper'; | ||
|
||
describe( 'generateRowId', () => { | ||
|
||
it( 'returns an alpha numeric string that is 10 characters long', () => { | ||
|
||
const got = ObjectHelper.generateRowId(); | ||
expect( got ).toHaveLength( 10 ); | ||
}); | ||
|
||
it( 'does not return the same string when called multiple times', () => { | ||
|
||
let previousIds = []; | ||
for ( let i=0; i<100; i++ ) { | ||
const got = ObjectHelper.generateRowId(); | ||
expect( previousIds ).not.toContain( got ); | ||
previousIds.push( got ); | ||
} | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
framework/default/ortoo-core/default/lwc/objectHelper/objectHelper.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,16 @@ | ||
const generateRowId = function() { | ||
const length = 10; | ||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
const charactersLength = characters.length; | ||
|
||
let result = ''; | ||
for ( let i = 0; i < length; i++ ) { | ||
result += characters.charAt( Math.floor ( Math.random() * charactersLength ) ); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export default { | ||
generateRowId : generateRowId | ||
}; |
5 changes: 5 additions & 0 deletions
5
framework/default/ortoo-core/default/lwc/objectHelper/objectHelper.js-meta.xml
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>54.0</apiVersion> | ||
<isExposed>false</isExposed> | ||
</LightningComponentBundle> |