Skip to content

Commit

Permalink
Added objectHelper - which allows us to generate ids for use in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Mar 28, 2022
1 parent 4e86c73 commit 1380b62
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
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 );
}
});
});
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
};
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>

0 comments on commit 1380b62

Please sign in to comment.