Skip to content

Commit

Permalink
Merge branch 'main' into poc/reusing-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MadameSheema authored Jul 18, 2023
2 parents 23f0392 + 731f587 commit 00f3a69
Show file tree
Hide file tree
Showing 73 changed files with 2,280 additions and 600 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ export const TabbedTableListView = ({
[activeTabId, tabs]
);

const onFetchSuccess = useCallback(() => {
setHasInitialFetchReturned(true);
}, []);

const [tableList, setTableList] = useState<React.ReactNode>(null);

useEffect(() => {
async function loadTableList() {
const newTableList = await getActiveTab().getTableList({
onFetchSuccess: () => {
if (!hasInitialFetchReturned) {
setHasInitialFetchReturned(true);
}
},
onFetchSuccess,
setPageDataTestSubject,
});
setTableList(newTableList);
}

loadTableList();
}, [hasInitialFetchReturned, activeTabId, tabs, getActiveTab]);
}, [activeTabId, tabs, getActiveTab, onFetchSuccess]);

return (
<KibanaPageTemplate panelled data-test-subj={pageDataTestSubject}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ export const TableListView = <T extends UserContentCommonSchema>({
const [pageDataTestSubject, setPageDataTestSubject] = useState<string>();

const onFetchSuccess = useCallback(() => {
if (!hasInitialFetchReturned) {
setHasInitialFetchReturned(true);
}
}, [hasInitialFetchReturned]);
setHasInitialFetchReturned(true);
}, []);

return (
<PageTemplate panelled data-test-subj={pageDataTestSubject}>
Expand Down
10 changes: 10 additions & 0 deletions packages/content-management/table_list_view_table/src/reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@ export function getReducer<T extends UserContentCommonSchema>() {
}
}

let hasNoItems = state.hasNoItems;

const hasQuery = state.searchQuery.text !== '';
if (hasQuery) {
hasNoItems = undefined;
} else {
hasNoItems = items.length === 0;
}

return {
...state,
hasInitialFetchReturned: true,
isFetchingItems: false,
items,
hasNoItems,
totalItems: action.data.response.total,
hasUpdatedAtMetadata,
tableSort: tableSort ?? state.tableSort,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { TestBed } from '@kbn/test-jest-helpers';
import { act } from 'react-dom/test-utils';

export const getActions = ({ find, form, component }: TestBed) => {
/** Open the sort select drop down menu */
const openSortSelect = () => {
find('tableSortSelectBtn').at(0).simulate('click');
};

// --- Search Box ---

/** Set the search box value */
const updateSearchText = async (value: string) => {
await act(async () => {
find('tableListSearchBox').simulate('keyup', {
key: 'Enter',
target: { value },
});
});
component.update();
};

/** Get the Search box value */
const getSearchBoxValue = () => find('tableListSearchBox').props().defaultValue;

// --- Row Actions ---
const selectRow = (rowId: string) => {
act(() => {
form.selectCheckBox(`checkboxSelectRow-${rowId}`);
});
component.update();
};

const clickDeleteSelectedItemsButton = () => {
act(() => {
find('deleteSelectedItems').simulate('click');
});
component.update();
};

const clickConfirmModalButton = async () => {
await act(async () => {
find('confirmModalConfirmButton').simulate('click');
});
component.update();
};

return {
openSortSelect,
updateSearchText,
getSearchBoxValue,
selectRow,
clickDeleteSelectedItemsButton,
clickConfirmModalButton,
};
};
Loading

0 comments on commit 00f3a69

Please sign in to comment.