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.
Merge pull request apex-enterprise-patterns#6 from OrtooApps/feature/…
…updates-after-qassign-implementations Feature/updates after qassign implementations
- Loading branch information
Showing
29 changed files
with
680 additions
and
157 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
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
33 changes: 33 additions & 0 deletions
33
framework/default/ortoo-core/default/lwc/elementFinder/__tests__/elementFinder.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,33 @@ | ||
import configureFindElement from 'c/elementFinder'; | ||
|
||
describe( 'configureFindElement', () => { | ||
it( 'will add a "findElement" function against the passed object', () => { | ||
|
||
const objectToRunAgainst = {}; | ||
|
||
configureFindElement( objectToRunAgainst ); | ||
|
||
expect( objectToRunAgainst.findElement ).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe( 'findElement', () => { | ||
it( 'will ask the bound object for the element with the specified data-ortoo-elem-id', () => { | ||
|
||
const mockQuerySelector = jest.fn(); | ||
|
||
const objectToRunAgainst = { | ||
template: { | ||
querySelector: mockQuerySelector | ||
} | ||
}; | ||
mockQuerySelector.mockReturnValueOnce( 'the element' ); | ||
|
||
configureFindElement( objectToRunAgainst ); | ||
|
||
const response = objectToRunAgainst.findElement( 'test-element' ); | ||
|
||
expect( response ).toBe( 'the element' ); | ||
expect( mockQuerySelector ).toBeCalledWith( '[data-ortoo-elem-id="test-element"]' ); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
framework/default/ortoo-core/default/lwc/elementFinder/elementFinder.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,18 @@ | ||
/** | ||
* Will bind a function that will allow the bound LWC to 'findElement' passing an Ortoo Element Id. | ||
* | ||
* Should be bound in the connectedCallback of the LWC. E.g. | ||
* | ||
* connectedCallback() { | ||
* configureFindElement( this ); | ||
* } | ||
* | ||
* @param bindTo The LWC to bind this function to | ||
*/ | ||
const configureFindElement = bindTo => { | ||
bindTo.findElement = function( ortooElemId ) { | ||
return this.template.querySelector( `[data-ortoo-elem-id="${ortooElemId}"]` ); | ||
}.bind( bindTo ); | ||
}; | ||
|
||
export default configureFindElement; |
5 changes: 5 additions & 0 deletions
5
framework/default/ortoo-core/default/lwc/elementFinder/elementFinder.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>52.0</apiVersion> | ||
<isExposed>false</isExposed> | ||
</LightningComponentBundle> |
93 changes: 93 additions & 0 deletions
93
...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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import configureElementIdGenerator from 'c/elementIdGenerator'; | ||
|
||
describe('configureElementIdGenerator', () => { | ||
afterEach(() => { | ||
}); | ||
|
||
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(); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
framework/default/ortoo-core/default/lwc/elementIdGenerator/elementIdGenerator.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,25 @@ | ||
const generateId = function( suffix ) { | ||
return suffix ? this.ortooElemIdPrefix + '-' + suffix : this.ortooElemIdPrefix;; | ||
} | ||
|
||
const configureElementIdGenerator = function( bindTo ) { | ||
|
||
if ( ! bindTo.ortooIdConfiguration ) { | ||
throw 'configureGenerator called against an object with no ortooIdConfiguration member variable - this should contain the mapping of properties to their suffixes: ' + bindTo; | ||
} | ||
|
||
if ( ! bindTo.ortooElemIdPrefix ) { | ||
throw new 'configureGenerator called against an object with no ortooElemIdPrefix member variable - this should contain the Id prefix' + bindTo; | ||
} | ||
|
||
for ( const idName in bindTo.ortooIdConfiguration ) { | ||
|
||
Object.defineProperty( bindTo, idName, { | ||
get: function() { | ||
return generateId.call( bindTo, bindTo.ortooIdConfiguration[ idName ] ); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export default configureElementIdGenerator; |
5 changes: 5 additions & 0 deletions
5
framework/default/ortoo-core/default/lwc/elementIdGenerator/elementIdGenerator.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>52.0</apiVersion> | ||
<isExposed>false</isExposed> | ||
</LightningComponentBundle> |
Oops, something went wrong.