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 elementFinder library functions
- Loading branch information
1 parent
bfcd7df
commit c3f53fe
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
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> |