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 the test for the elementIdGenerator
- Loading branch information
1 parent
94dced8
commit 87088b5
Showing
2 changed files
with
114 additions
and
39 deletions.
There are no files selected for viewing
95 changes: 85 additions & 10 deletions
95
...rk/default/ortoo-core/default/lwc/elementIdGenerator/__tests__/elementIdGenerator.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 |
---|---|---|
@@ -1,18 +1,93 @@ | ||
import configureElementIdGenerator from 'c/elementIdGenerator'; | ||
|
||
let showToastEvent = function ShowToastEvent( details ) { | ||
this.detail = details | ||
}; | ||
|
||
jest.mock('lightning/platformShowToastEvent', () => ({ | ||
ShowToastEvent: showToastEvent | ||
})); | ||
|
||
describe('c-element-id-generator', () => { | ||
afterEach(() => { | ||
}); | ||
|
||
it( 'is tested', () => { | ||
expect( false ).toBe( true ); | ||
it( 'will add properties to the passed object based on the ortooIdConfiguration property names with values built from the combination of the ortooIdConfiguration property values and the ortooElemIdPrefix', () => { | ||
|
||
const objectToRunAgainst = { | ||
ortooElemIdPrefix: 'theprefix', | ||
ortooIdConfiguration: { | ||
field1: 'thefield1', | ||
field2: 'thefield2' | ||
} | ||
}; | ||
|
||
configureElementIdGenerator( objectToRunAgainst ); | ||
|
||
expect( objectToRunAgainst.field1 ).toBe( 'theprefix-thefield1' ); | ||
expect( objectToRunAgainst.field2 ).toBe( 'theprefix-thefield2' ); | ||
}); | ||
|
||
it( 'will skip the value if it is not specified', () => { | ||
|
||
const objectToRunAgainst = { | ||
ortooElemIdPrefix: 'theprefix', | ||
ortooIdConfiguration: { | ||
field1: '', | ||
field2: 'thefield2' | ||
} | ||
}; | ||
|
||
configureElementIdGenerator( objectToRunAgainst ); | ||
|
||
expect( objectToRunAgainst.field1 ).toBe( 'theprefix' ); | ||
expect( objectToRunAgainst.field2 ).toBe( 'theprefix-thefield2' ); | ||
}); | ||
|
||
it( 'will throw an error if given an object with no ortooElemIdPrefix property', () => { | ||
|
||
const objectToRunAgainst = { | ||
ortooIdConfiguration: { | ||
field1: '', | ||
field2: 'thefield2' | ||
} | ||
}; | ||
|
||
expect( () => configureElementIdGenerator( objectToRunAgainst ) ).toThrow(); | ||
}); | ||
it( 'will throw an error if given an object with an empty ortooElemIdPrefix property', () => { | ||
|
||
const objectToRunAgainst = { | ||
ortooElemIdPrefix: '', | ||
ortooIdConfiguration: { | ||
field1: '', | ||
field2: 'thefield2' | ||
} | ||
}; | ||
|
||
expect( () => configureElementIdGenerator( objectToRunAgainst ) ).toThrow(); | ||
}); | ||
it( 'will throw an error if given an object with a null ortooElemIdPrefix property', () => { | ||
|
||
const objectToRunAgainst = { | ||
ortooElemIdPrefix: null, | ||
ortooIdConfiguration: { | ||
field1: '', | ||
field2: 'thefield2' | ||
} | ||
}; | ||
|
||
expect( () => configureElementIdGenerator( objectToRunAgainst ) ).toThrow(); | ||
}); | ||
|
||
it( 'will throw an error if given an object with no ortooIdConfiguration property', () => { | ||
|
||
const objectToRunAgainst = { | ||
ortooElemIdPrefix: 'theprefix' | ||
}; | ||
|
||
expect( () => configureElementIdGenerator( objectToRunAgainst ) ).toThrow(); | ||
}); | ||
|
||
it( 'will not throw an error if given an object with an empty object for the ortooIdConfiguration property', () => { | ||
|
||
const objectToRunAgainst = { | ||
ortooElemIdPrefix: 'theprefix', | ||
ortooIdConfiguration: {} | ||
}; | ||
|
||
expect( () => configureElementIdGenerator( objectToRunAgainst ) ).not.toThrow(); | ||
}); | ||
}); |
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