mirror of
https://github.com/podman-desktop/podman-desktop
synced 2026-04-21 09:37:22 +00:00
* fix: show recommended ext card when podman is ready This PR introduces optional when field for recommendations.json entries. Recommendation card is shown if 'when' condition is evaluated to true. Example: ```when="provider.podman.status==='ready'"``` shows recommendation card when there is running podman VM. ```when="provider.kind.status==='ready'"``` shows recommendation card when there is running kind instance. This PR also improves component tests implementation. Signed-off-by: Denis Golovin <dgolovin@redhat.com>
84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
/**********************************************************************
|
|
* Copyright (C) 2024 Red Hat, Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
***********************************************************************/
|
|
|
|
import { render, screen } from '@testing-library/svelte';
|
|
import { expect, test } from 'vitest';
|
|
|
|
import ExtensionBanners from '/@/lib/recommendation/ExtensionBanners.svelte';
|
|
import { extensionBannerInfos } from '/@/stores/extensionBanners';
|
|
import { providerInfos } from '/@/stores/providers';
|
|
import type { ProviderInfo } from '/@api/provider-info';
|
|
|
|
import type { FeaturedExtension } from '../../../../main/src/plugin/featured/featured-api';
|
|
import type { ExtensionBanner } from '../../../../main/src/plugin/recommendations/recommendations-api';
|
|
|
|
test('multiple banners should be rendered', async () => {
|
|
const banners: ExtensionBanner[] = Array.from({ length: 10 }, (_, i) => ({
|
|
extensionId: `dummy.id-${i}`,
|
|
title: `Title ${i}`,
|
|
featured: {} as unknown as FeaturedExtension,
|
|
description: 'dummy description',
|
|
icon: 'data:image/png;base64-icon',
|
|
thumbnail: 'data:image/png;base64-thumbnail',
|
|
}));
|
|
|
|
extensionBannerInfos.set(banners);
|
|
|
|
render(ExtensionBanners);
|
|
|
|
for (const banner of banners) {
|
|
const text = screen.getByText(banner.title);
|
|
expect(text).toBeDefined();
|
|
}
|
|
});
|
|
|
|
test('only banners with when condition evaluated to true should be rendered', async () => {
|
|
const banner1 = {
|
|
extensionId: `dummy.id-when-visible-1`,
|
|
title: 'Visible',
|
|
featured: {} as unknown as FeaturedExtension,
|
|
description: 'dummy description',
|
|
icon: 'data:image/png;base64-icon',
|
|
thumbnail: 'data:image/png;base64-thumbnail',
|
|
when: `provider.podman.status === 'ready'`,
|
|
};
|
|
|
|
const banner2 = {
|
|
extensionId: `dummy.id-when-invisible-1`,
|
|
title: 'Invisible',
|
|
featured: {} as unknown as FeaturedExtension,
|
|
description: 'dummy description',
|
|
icon: 'data:image/png;base64-icon',
|
|
thumbnail: 'data:image/png;base64-thumbnail',
|
|
when: `provider.kubectl.status === 'ready'`,
|
|
};
|
|
|
|
const providerInfo = {
|
|
internalId: '0',
|
|
id: 'podman',
|
|
status: 'ready',
|
|
};
|
|
|
|
providerInfos.set([providerInfo as unknown as ProviderInfo]);
|
|
extensionBannerInfos.set([banner1, banner2]);
|
|
|
|
render(ExtensionBanners);
|
|
|
|
expect(screen.getByText(banner1.title)).toBeDefined();
|
|
expect(screen.queryByText(banner2.title)).toBeNull();
|
|
});
|