Skip to content

Commit

Permalink
Added the elementFinder library functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Jan 11, 2022
1 parent bfcd7df commit c3f53fe
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
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"]' );
});
});
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;
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>

0 comments on commit c3f53fe

Please sign in to comment.