Skip to content

Commit

Permalink
DEV guestsList test, scroll event
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Jan 19, 2022
1 parent 6d9d28f commit 2803a5e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`GuestsList Component should handle an onScroll event: scroll event 1`] = `
Array [
Array [
Object {
"target": Object {
"clientHeight": 100,
"scrollHeight": 200,
"scrollTop": 100,
},
},
],
]
`;

exports[`GuestsList Component should handle multiple display states: fulfilled 1`] = `
<div
className="fadein "
Expand Down Expand Up @@ -95,7 +109,9 @@ exports[`GuestsList Component should handle variations in data: filtered data 1`
Array [
Object {
"title": "t(curiosity-inventory.header, {\\"context\\":\\"lorem\\"})",
"transforms": Array [],
"transforms": Array [
[Function],
],
},
]
}
Expand Down
30 changes: 29 additions & 1 deletion src/components/guestsList/__tests__/guestsList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('GuestsList Component', () => {

component.setProps({
useProductInventoryGuestsConfig: () => ({
filters: [{ id: 'lorem' }]
filters: [{ id: 'lorem', cellWidth: 20 }]
})
});

Expand Down Expand Up @@ -61,4 +61,32 @@ describe('GuestsList Component', () => {

expect(component).toMatchSnapshot('fulfilled');
});

it('should handle an onScroll event', async () => {
const mockOnScroll = jest.fn();
const props = {
id: 'lorem',
numberOfGuests: 200,
useOnScroll: () => mockOnScroll,
useGetGuestsInventory: () => ({
fulfilled: true,
data: {
data: [{ lorem: 'ipsum', dolor: 'sit' }]
}
})
};

const component = await shallowHookComponent(<GuestsList {...props} />);
component
.find('.curiosity-table-scroll-list')
.simulate('scroll', { target: { scrollHeight: 200, scrollTop: 100, clientHeight: 100 } });

component.setProps({
useGetGuestsInventory: () => ({
pending: true
})
});

expect(mockOnScroll.mock.calls).toMatchSnapshot('scroll event');
});
});
13 changes: 9 additions & 4 deletions src/components/guestsList/guestsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { DEFAULT_OFFSET, useGetGuestsInventory, useOnScroll } from './guestsList
* @param {number} props.numberOfGuests
* @param {object} props.session
* @param {Function} props.useGetGuestsInventory
* @param {Function} props.useOnScroll
* @param {Function} props.useProductInventoryGuestsQuery
* @param {Function} props.useProductInventoryGuestsConfig
* @fires onScroll
Expand All @@ -31,6 +32,7 @@ const GuestsList = ({
numberOfGuests,
session,
useGetGuestsInventory: useAliasGetGuestsInventory,
useOnScroll: useAliasOnScroll,
useProductInventoryGuestsQuery: useAliasProductInventoryGuestsQuery,
useProductInventoryGuestsConfig: useAliasProductInventoryGuestsConfig
}) => {
Expand All @@ -43,7 +45,7 @@ const GuestsList = ({
const { error, pending, data = {} } = useAliasGetGuestsInventory(id);
const { data: listData = [] } = data;

const onScroll = useOnScroll(id, () => {
const onScroll = useAliasOnScroll(id, () => {
const updatedData = [...previousData, ...(listData || [])];
setPreviousData(updatedData);
});
Expand Down Expand Up @@ -146,8 +148,9 @@ const GuestsList = ({
/**
* Prop types.
*
* @type {{useProductInventoryGuestsConfig: Function, session: object, defaultOffset: number, numberOfGuests: number,
* id: string, useGetGuestsInventory: Function, useProductInventoryGuestsQuery: Function, defaultPerPage: number}}
* @type {{useProductInventoryGuestsConfig: Function, session: object, defaultOffset: number, useOnScroll: Function,
* numberOfGuests: number, id: string, useGetGuestsInventory: Function, useProductInventoryGuestsQuery: Function,
* defaultPerPage: number}}
*/
GuestsList.propTypes = {
defaultOffset: PropTypes.number,
Expand All @@ -156,21 +159,23 @@ GuestsList.propTypes = {
numberOfGuests: PropTypes.number.isRequired,
session: PropTypes.object,
useGetGuestsInventory: PropTypes.func,
useOnScroll: PropTypes.func,
useProductInventoryGuestsConfig: PropTypes.func,
useProductInventoryGuestsQuery: PropTypes.func
};

/**
* Default props.
*
* @type {{useProductInventoryGuestsConfig: Function, session: object, defaultOffset: number,
* @type {{useProductInventoryGuestsConfig: Function, session: object, defaultOffset: number, useOnScroll: Function,
* useGetGuestsInventory: Function, useProductInventoryGuestsQuery: Function, defaultPerPage: number}}
*/
GuestsList.defaultProps = {
defaultOffset: DEFAULT_OFFSET,
defaultPerPage: 5,
session: {},
useGetGuestsInventory,
useOnScroll,
useProductInventoryGuestsConfig,
useProductInventoryGuestsQuery
};
Expand Down
20 changes: 0 additions & 20 deletions src/components/inventoryList/__tests__/inventoryCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,4 @@ describe('InventoryCard Component', () => {

expect(component.find(Table)).toMatchSnapshot('number of guests, id, and NO expandable guests display');
});

/*
it('should handle updating api data when query, or product id is updated', async () => {
const props = {
query: { lorem: 'ipsum' },
productId: 'lorem',
getInstancesInventory: jest.fn()
};
const component = await mountHookComponent(<InventoryCard {...props} />);
component.setProps({
query: { dolor: 'sit' },
productId: 'dolor'
});
expect(props.getInstancesInventory).toHaveBeenCalledTimes(2);
expect(props.getInstancesInventory.mock.calls).toMatchSnapshot('getInstancesInventory');
});
*/
});

0 comments on commit 2803a5e

Please sign in to comment.