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#7 from OrtooApps/feature/…
…filter-and-paging Feature/filter and paging
- Loading branch information
Showing
11 changed files
with
1,189 additions
and
25 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
196 changes: 196 additions & 0 deletions
196
framework/default/ortoo-core/default/lwc/filterAndResults/__tests__/filterAndResults.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,196 @@ | ||
import { createElement } from 'lwc'; | ||
import FilterAndResults from 'c/filterAndResults'; | ||
|
||
jest.mock('@salesforce/label/c.ortoo_core_loading', () => { return { default: "Loading" } }, { virtual: true } ); | ||
|
||
const CARD_SELECTOR = '[data-ortoo-elem-id="filterandresults-card"]'; | ||
const SEARCH_BUTTON_SELECTOR = '[data-ortoo-elem-id="filterandresults-search"]'; | ||
const TOP_PAGE_NAVIGATION_SELECTOR = '[data-ortoo-elem-id="filterandresults-pageselectortop"]'; | ||
const BOTTOM_PAGE_NAVIGATION_SELECTOR = '[data-ortoo-elem-id="filterandresults-pageselectorbottom"]'; | ||
|
||
describe( 'c-filter-and-results', () => { | ||
|
||
beforeEach( () => { | ||
const element = createElement('c-filter-and-result', { | ||
is: FilterAndResults | ||
}); | ||
|
||
document.body.appendChild( element ); | ||
}); | ||
|
||
afterEach(() => { | ||
// The jsdom instance is shared across test cases in a single file so reset the DOM | ||
while (document.body.firstChild) { | ||
document.body.removeChild(document.body.firstChild); | ||
} | ||
}); | ||
|
||
it( 'when rendered, includes slots for the info, form, action buttons and the data', () => { | ||
|
||
const element = document.body.querySelector( 'c-filter-and-result' ); | ||
|
||
return Promise.resolve() | ||
.then( () => { | ||
expect( element.shadowRoot.querySelector( 'slot[name="info"]' ) ).not.toBeNull(); | ||
expect( element.shadowRoot.querySelector( 'slot[name="form"]' ) ).not.toBeNull(); | ||
expect( element.shadowRoot.querySelector( 'slot[name="action-buttons"]' ) ).not.toBeNull(); | ||
expect( element.shadowRoot.querySelector( 'slot[name="data"]' ) ).not.toBeNull(); | ||
}) | ||
}); | ||
|
||
it( 'when loaded is set to true, will show a loading spinner', () => { | ||
|
||
const element = document.body.querySelector( 'c-filter-and-result' ); | ||
|
||
element.loading = true; | ||
|
||
return Promise.resolve() | ||
.then( () => { | ||
expect( element.shadowRoot.querySelector( 'lightning-spinner' ) ).not.toBeNull(); | ||
}) | ||
}); | ||
|
||
it( 'when loaded is set to false, will not show a loading spinner', () => { | ||
|
||
const element = document.body.querySelector( 'c-filter-and-result' ); | ||
|
||
element.loading = false; | ||
|
||
return Promise.resolve() | ||
.then( () => { | ||
expect( element.shadowRoot.querySelector( 'lightning-spinner' ) ).toBeNull(); | ||
}) | ||
}); | ||
|
||
it( 'when showPaginationControls flag is set to true will show pagination controls above and below the data', () => { | ||
|
||
const element = document.body.querySelector( 'c-filter-and-result' ); | ||
|
||
element.showPaginationControls = true; | ||
|
||
return Promise.resolve() | ||
.then( () => { | ||
expect( element.shadowRoot.querySelector( TOP_PAGE_NAVIGATION_SELECTOR ) ).not.toBeNull(); | ||
expect( element.shadowRoot.querySelector( BOTTOM_PAGE_NAVIGATION_SELECTOR ) ).not.toBeNull(); | ||
}) | ||
}); | ||
|
||
it( 'when showPaginationControls flag is set to true will configure the pagination controls with record information', () => { | ||
|
||
const NUMBER_OF_RECORDS = 100; | ||
const WINDOW_SIZE = 20; | ||
const OFFSET = 40; | ||
|
||
const element = document.body.querySelector( 'c-filter-and-result' ); | ||
|
||
element.showPaginationControls = true; | ||
element.numberOfRecords = NUMBER_OF_RECORDS; | ||
element.recordsWindowSize = WINDOW_SIZE; | ||
element.offset = OFFSET; | ||
|
||
return Promise.resolve() | ||
.then( () => { | ||
const topNavigator = element.shadowRoot.querySelector( TOP_PAGE_NAVIGATION_SELECTOR ); | ||
const bottomNavigator = element.shadowRoot.querySelector( BOTTOM_PAGE_NAVIGATION_SELECTOR ); | ||
|
||
expect( topNavigator.numberOfRecords ).toBe( NUMBER_OF_RECORDS ); | ||
expect( bottomNavigator.numberOfRecords ).toBe( NUMBER_OF_RECORDS ); | ||
expect( topNavigator.recordsPerPage ).toBe( WINDOW_SIZE ); | ||
expect( bottomNavigator.recordsPerPage ).toBe( WINDOW_SIZE ); | ||
expect( topNavigator.offset ).toBe( OFFSET ); | ||
expect( bottomNavigator.offset ).toBe( OFFSET ); | ||
}) | ||
}); | ||
|
||
it( 'when showPaginationControls flag is set to false will not show pagination controls', () => { | ||
|
||
const element = document.body.querySelector( 'c-filter-and-result' ); | ||
|
||
element.showPaginationControls = false; | ||
|
||
return Promise.resolve() | ||
.then( () => { | ||
expect( element.shadowRoot.querySelector( TOP_PAGE_NAVIGATION_SELECTOR ) ).toBeNull(); | ||
expect( element.shadowRoot.querySelector( BOTTOM_PAGE_NAVIGATION_SELECTOR ) ).toBeNull(); | ||
}) | ||
}); | ||
|
||
it( 'when the title is set, will set the card title to the passed value', () => { | ||
|
||
const element = document.body.querySelector( 'c-filter-and-result' ); | ||
|
||
element.title = 'The title'; | ||
|
||
return Promise.resolve() | ||
.then( () => { | ||
expect( element.shadowRoot.querySelector( CARD_SELECTOR ).title ).toBe( 'The title' ); | ||
}) | ||
}); | ||
|
||
it( 'when the the search button is clicked, will issue a search event', () => { | ||
|
||
const element = document.body.querySelector( 'c-filter-and-result' ); | ||
|
||
const eventHandler = jest.fn(); | ||
element.addEventListener( 'search', eventHandler ); | ||
|
||
return Promise.resolve() | ||
.then( () => { | ||
element.shadowRoot.querySelector( SEARCH_BUTTON_SELECTOR ).click(); | ||
}) | ||
.then( () => { | ||
expect( eventHandler ).toHaveBeenCalledTimes( 1 ); | ||
}) | ||
}); | ||
|
||
it( 'when the top pagination control issues a navigation event, will forward the detail as a new navigation event', () => { | ||
|
||
const element = document.body.querySelector( 'c-filter-and-result' ); | ||
element.showPaginationControls = true; | ||
|
||
const eventHandler = jest.fn(); | ||
element.addEventListener( 'navigate', eventHandler ); | ||
|
||
const eventPayload = { | ||
detail: 'the original detail' | ||
} | ||
|
||
return Promise.resolve() | ||
.then( () => { | ||
const navigateEvent = new CustomEvent( 'navigate', eventPayload ); | ||
element.shadowRoot.querySelector( TOP_PAGE_NAVIGATION_SELECTOR ).dispatchEvent( navigateEvent ); | ||
}) | ||
.then( () => { | ||
expect( eventHandler ).toHaveBeenCalledTimes( 1 ); | ||
const receivedEventPayload = eventHandler.mock.calls[0][0]; | ||
|
||
expect( receivedEventPayload.detail ).toEqual( eventPayload.detail ); | ||
expect( receivedEventPayload ).not.toBe( eventPayload ); | ||
}) | ||
}); | ||
it( 'when the bottom pagination control issues a navigation event, will forward the detail as a new navigation event', () => { | ||
|
||
const element = document.body.querySelector( 'c-filter-and-result' ); | ||
element.showPaginationControls = true; | ||
|
||
const eventHandler = jest.fn(); | ||
element.addEventListener( 'navigate', eventHandler ); | ||
|
||
const eventPayload = { | ||
detail: 'the original detail' | ||
} | ||
|
||
return Promise.resolve() | ||
.then( () => { | ||
const navigateEvent = new CustomEvent( 'navigate', eventPayload ); | ||
element.shadowRoot.querySelector( BOTTOM_PAGE_NAVIGATION_SELECTOR ).dispatchEvent( navigateEvent ); | ||
}) | ||
.then( () => { | ||
expect( eventHandler ).toHaveBeenCalledTimes( 1 ); | ||
const receivedEventPayload = eventHandler.mock.calls[0][0]; | ||
|
||
expect( receivedEventPayload.detail ).toEqual( eventPayload.detail ); | ||
expect( receivedEventPayload ).not.toBe( eventPayload ); | ||
}) | ||
}); | ||
}); |
Oops, something went wrong.