2021-08-04 08:09:57 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import { PluginSignatureStatus } from '@grafana/data';
|
2021-08-30 07:00:11 -05:00
|
|
|
import { PluginListBadges } from './PluginListBadges';
|
2021-08-04 08:09:57 -05:00
|
|
|
import { CatalogPlugin } from '../types';
|
2021-08-26 10:15:43 -05:00
|
|
|
import { config } from '@grafana/runtime';
|
2021-08-04 08:09:57 -05:00
|
|
|
|
|
|
|
describe('PluginBadges', () => {
|
|
|
|
const plugin: CatalogPlugin = {
|
|
|
|
description: 'The test plugin',
|
|
|
|
downloads: 5,
|
|
|
|
id: 'test-plugin',
|
|
|
|
info: {
|
|
|
|
logos: {
|
|
|
|
small: 'https://grafana.com/api/plugins/test-plugin/versions/0.0.10/logos/small',
|
|
|
|
large: 'https://grafana.com/api/plugins/test-plugin/versions/0.0.10/logos/large',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
name: 'Testing Plugin',
|
|
|
|
orgName: 'Test',
|
|
|
|
popularity: 0,
|
|
|
|
signature: PluginSignatureStatus.valid,
|
|
|
|
publishedAt: '2020-09-01',
|
|
|
|
updatedAt: '2021-06-28',
|
|
|
|
version: '1.0.0',
|
|
|
|
hasUpdate: false,
|
|
|
|
isInstalled: false,
|
|
|
|
isCore: false,
|
|
|
|
isDev: false,
|
|
|
|
isEnterprise: false,
|
|
|
|
};
|
|
|
|
|
2021-08-26 10:15:43 -05:00
|
|
|
afterEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2021-08-04 08:09:57 -05:00
|
|
|
it('renders a plugin signature badge', () => {
|
2021-08-30 07:00:11 -05:00
|
|
|
render(<PluginListBadges plugin={plugin} />);
|
2021-08-04 08:09:57 -05:00
|
|
|
|
|
|
|
expect(screen.getByText(/signed/i)).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an installed badge', () => {
|
2021-08-30 07:00:11 -05:00
|
|
|
render(<PluginListBadges plugin={{ ...plugin, isInstalled: true }} />);
|
2021-08-04 08:09:57 -05:00
|
|
|
|
|
|
|
expect(screen.getByText(/signed/i)).toBeVisible();
|
|
|
|
expect(screen.getByText(/installed/i)).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an enterprise badge (when a license is valid)', () => {
|
2021-08-26 10:15:43 -05:00
|
|
|
config.licenseInfo.hasValidLicense = true;
|
2021-08-30 07:00:11 -05:00
|
|
|
render(<PluginListBadges plugin={{ ...plugin, isEnterprise: true }} />);
|
2021-08-04 08:09:57 -05:00
|
|
|
expect(screen.getByText(/enterprise/i)).toBeVisible();
|
|
|
|
expect(screen.queryByRole('button', { name: /learn more/i })).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an enterprise badge with icon and link (when a license is invalid)', () => {
|
2021-08-26 10:15:43 -05:00
|
|
|
config.licenseInfo.hasValidLicense = false;
|
2021-08-30 07:00:11 -05:00
|
|
|
render(<PluginListBadges plugin={{ ...plugin, isEnterprise: true }} />);
|
2021-08-04 08:09:57 -05:00
|
|
|
expect(screen.getByText(/enterprise/i)).toBeVisible();
|
|
|
|
expect(screen.getByLabelText(/lock icon/i)).toBeInTheDocument();
|
|
|
|
expect(screen.getByRole('button', { name: /learn more/i })).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|