Skip to content

Commit

Permalink
Fix cypress test and subcategory url reading
Browse files Browse the repository at this point in the history
  • Loading branch information
criamico committed Jan 18, 2023
1 parent 7b2946f commit 9d2f603
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ describe('Add Integration - Real API', () => {

it('should filter integrations by category', () => {
setupIntegrations();
cy.getBySel(getIntegrationCategories('aws')).click();
cy.getBySel(getIntegrationCategories('aws')).click({ scrollBehavior: false });

cy.getBySel(INTEGRATIONS_SEARCHBAR.BADGE).contains('AWS').should('exist');
cy.getBySel(INTEGRATION_LIST).find('.euiCard').should('have.length.greaterThan', 29);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export interface Props {
showCardLabels?: boolean;
title?: string;
availableSubCategories?: CategoryFacet[];
selectedSubCategory?: CategoryFacet;
setSelectedSubCategory?: (c: CategoryFacet | undefined) => void;
selectedSubCategory?: string;
setSelectedSubCategory?: (c: string | undefined) => void;
showMissingIntegrationMessage?: boolean;
}

Expand Down Expand Up @@ -111,7 +111,7 @@ export const PackageListGrid: FunctionComponent<Props> = ({
setUrlandReplaceHistory({
searchString: queryText,
categoryId: selectedCategory,
subCategoryId: selectedSubCategory?.id,
subCategoryId: selectedSubCategory,
});
};

Expand All @@ -121,11 +121,11 @@ export const PackageListGrid: FunctionComponent<Props> = ({
};

const onSubCategoryClick = useCallback(
(subCategory: CategoryFacet) => {
(subCategory: string) => {
if (setSelectedSubCategory) setSelectedSubCategory(subCategory);
setUrlandPushHistory({
categoryId: selectedCategory,
subCategoryId: subCategory.id,
subCategoryId: subCategory,
});
},
[selectedCategory, setSelectedSubCategory, setUrlandPushHistory]
Expand Down Expand Up @@ -171,7 +171,7 @@ export const PackageListGrid: FunctionComponent<Props> = ({
<EuiContextMenuItem
key={subCategory.id}
onClick={() => {
onSubCategoryClick(subCategory);
onSubCategoryClick(subCategory.id);
closePopover();
}}
>
Expand All @@ -194,7 +194,7 @@ export const PackageListGrid: FunctionComponent<Props> = ({
>
<ControlsColumn controls={controls} title={title} />
</EuiFlexItem>
<EuiFlexItem grow={5}>
<EuiFlexItem grow={5} data-test-subj="epmList.mainColumn">
<EuiFieldSearch
data-test-subj="epmList.searchBar"
placeholder={i18n.translate('xpack.fleet.epmList.searchPackagesPlaceholder', {
Expand Down Expand Up @@ -269,7 +269,7 @@ export const PackageListGrid: FunctionComponent<Props> = ({
<EuiButton
color="text"
aria-label={subCategory?.title}
onClick={() => onSubCategoryClick(subCategory)}
onClick={() => onSubCategoryClick(subCategory.id)}
>
<FormattedMessage
id="xpack.fleet.epmList.subcategoriesButton"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ export const useAvailablePackages = () => {
const { http } = useStartServices();
const addBasePath = http.basePath.prepend;

const { selectedCategory: initialSelectedCategory, searchParam } = getParams(
useParams<CategoryParams>(),
useLocation().search
);
const {
selectedCategory: initialSelectedCategory,
selectedSubcategory: initialSubcategory,
searchParam,
} = getParams(useParams<CategoryParams>(), useLocation().search);

const [selectedCategory, setCategory] = useState(initialSelectedCategory);
const [selectedSubCategory, setSelectedSubCategory] = useState<CategoryFacet | undefined>();
const [selectedSubCategory, setSelectedSubCategory] = useState<string | undefined>(
initialSubcategory
);
const [searchTerm, setSearchTerm] = useState(searchParam || '');

const { getHref, getAbsolutePath } = useLink();
Expand Down Expand Up @@ -211,7 +215,7 @@ export const useAvailablePackages = () => {
}
if (!selectedSubCategory) return c.categories.includes(selectedCategory);

return c.categories.includes(selectedSubCategory.id);
return c.categories.includes(selectedSubCategory);
}),
[cards, selectedCategory, selectedSubCategory]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ import { AvailablePackages } from './available_packages';

export interface CategoryParams {
category?: ExtendedIntegrationCategory;
subcategory?: string;
}

export const getParams = (params: CategoryParams, search: string) => {
const { category } = params;
const { category, subcategory } = params;
const selectedCategory: ExtendedIntegrationCategory = category || '';
const queryParams = new URLSearchParams(search);
const searchParam = queryParams.get(INTEGRATIONS_SEARCH_QUERYPARAM) || '';
return { selectedCategory, searchParam };
return { selectedCategory, searchParam, selectedSubcategory: subcategory };
};

export const categoryExists = (category: string, categories: CategoryFacet[]) => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/public/constants/page_paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const FLEET_ROUTING_PATHS = {
export const INTEGRATIONS_SEARCH_QUERYPARAM = 'q';
export const INTEGRATIONS_ROUTING_PATHS = {
integrations: '/:tabId',
integrations_all: '/browse/:category?',
integrations_all: '/browse/:category?/:subcategory?',
integrations_installed: '/installed/:category?',
integrations_installed_updates_available: '/installed/updates_available/:category?',
integration_details: '/detail/:pkgkey/:panel?',
Expand Down

0 comments on commit 9d2f603

Please sign in to comment.