| 
									
										
										
										
											2021-08-04 21:09:57 +08:00
										 |  |  | import { render, screen } from '@testing-library/react'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | import React from 'react'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 15:08:00 +08:00
										 |  |  | import { PluginErrorCode, PluginSignatureStatus } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2021-08-26 23:15:43 +08:00
										 |  |  | import { config } from '@grafana/runtime'; | 
					
						
							| 
									
										
										
										
											2021-08-04 21:09:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | import { CatalogPlugin } from '../types'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { PluginListItemBadges } from './PluginListItemBadges'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 23:23:40 +08:00
										 |  |  | describe('PluginListItemBadges', () => { | 
					
						
							| 
									
										
										
										
											2021-08-04 21:09:57 +08:00
										 |  |  |   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', | 
					
						
							|  |  |  |     hasUpdate: false, | 
					
						
							|  |  |  |     isInstalled: false, | 
					
						
							|  |  |  |     isCore: false, | 
					
						
							|  |  |  |     isDev: false, | 
					
						
							|  |  |  |     isEnterprise: false, | 
					
						
							| 
									
										
										
										
											2021-09-20 15:08:00 +08:00
										 |  |  |     isDisabled: false, | 
					
						
							| 
									
										
										
										
											2023-09-12 18:49:10 +08:00
										 |  |  |     isDeprecated: false, | 
					
						
							| 
									
										
										
										
											2021-11-15 23:58:15 +08:00
										 |  |  |     isPublished: true, | 
					
						
							| 
									
										
										
										
											2021-08-04 21:09:57 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-26 23:15:43 +08:00
										 |  |  |   afterEach(() => { | 
					
						
							|  |  |  |     jest.clearAllMocks(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:09:57 +08:00
										 |  |  |   it('renders a plugin signature badge', () => { | 
					
						
							| 
									
										
										
										
											2021-09-30 23:23:40 +08:00
										 |  |  |     render(<PluginListItemBadges plugin={plugin} />); | 
					
						
							| 
									
										
										
										
											2021-08-04 21:09:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(screen.getByText(/signed/i)).toBeVisible(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('renders an installed badge', () => { | 
					
						
							| 
									
										
										
										
											2021-09-30 23:23:40 +08:00
										 |  |  |     render(<PluginListItemBadges plugin={{ ...plugin, isInstalled: true }} />); | 
					
						
							| 
									
										
										
										
											2021-08-04 21:09:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(screen.getByText(/signed/i)).toBeVisible(); | 
					
						
							|  |  |  |     expect(screen.getByText(/installed/i)).toBeVisible(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('renders an enterprise badge (when a license is valid)', () => { | 
					
						
							| 
									
										
										
										
											2022-01-24 23:08:05 +08:00
										 |  |  |     config.licenseInfo.enabledFeatures = { 'enterprise.plugins': true }; | 
					
						
							| 
									
										
										
										
											2021-09-30 23:23:40 +08:00
										 |  |  |     render(<PluginListItemBadges plugin={{ ...plugin, isEnterprise: true }} />); | 
					
						
							| 
									
										
										
										
											2021-08-04 21:09:57 +08: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)', () => { | 
					
						
							| 
									
										
										
										
											2022-01-24 23:08:05 +08:00
										 |  |  |     config.licenseInfo.enabledFeatures = {}; | 
					
						
							| 
									
										
										
										
											2021-09-30 23:23:40 +08:00
										 |  |  |     render(<PluginListItemBadges plugin={{ ...plugin, isEnterprise: true }} />); | 
					
						
							| 
									
										
										
										
											2021-08-04 21:09:57 +08:00
										 |  |  |     expect(screen.getByText(/enterprise/i)).toBeVisible(); | 
					
						
							|  |  |  |     expect(screen.getByLabelText(/lock icon/i)).toBeInTheDocument(); | 
					
						
							|  |  |  |     expect(screen.getByRole('button', { name: /learn more/i })).toBeInTheDocument(); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-09-20 15:08:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-12 18:07:12 +08:00
										 |  |  |   it('renders a error badge (when plugin has an error)', () => { | 
					
						
							| 
									
										
										
										
											2021-09-30 23:23:40 +08:00
										 |  |  |     render(<PluginListItemBadges plugin={{ ...plugin, isDisabled: true, error: PluginErrorCode.modifiedSignature }} />); | 
					
						
							| 
									
										
										
										
											2021-09-20 15:08:00 +08:00
										 |  |  |     expect(screen.getByText(/disabled/i)).toBeVisible(); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-11-12 18:07:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('renders an upgrade badge (when plugin has an available update)', () => { | 
					
						
							|  |  |  |     render(<PluginListItemBadges plugin={{ ...plugin, hasUpdate: true, installedVersion: '0.0.9' }} />); | 
					
						
							|  |  |  |     expect(screen.getByText(/update available/i)).toBeVisible(); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2023-06-28 15:58:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('renders an angular badge (when plugin is angular)', () => { | 
					
						
							|  |  |  |     render(<PluginListItemBadges plugin={{ ...plugin, angularDetected: true }} />); | 
					
						
							|  |  |  |     expect(screen.getByText(/angular/i)).toBeVisible(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('does not render an angular badge (when plugin is not angular)', () => { | 
					
						
							|  |  |  |     render(<PluginListItemBadges plugin={{ ...plugin, angularDetected: false }} />); | 
					
						
							|  |  |  |     expect(screen.queryByText(/angular/i)).toBeNull(); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-08-04 21:09:57 +08:00
										 |  |  | }); |