github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/services/frontend-service/src/ui/components/LocksTable/LocksTable.test.tsx (about) 1 /*This file is part of kuberpult. 2 3 Kuberpult is free software: you can redistribute it and/or modify 4 it under the terms of the Expat(MIT) License as published by 5 the Free Software Foundation. 6 7 Kuberpult is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 MIT License for more details. 11 12 You should have received a copy of the MIT License 13 along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>. 14 15 Copyright 2023 freiheit.com*/ 16 import { render } from '@testing-library/react'; 17 import React from 'react'; 18 import { LockDisplay } from '../LockDisplay/LockDisplay'; 19 import { DisplayLock } from '../../utils/store'; 20 21 describe('Run Locks Table', () => { 22 interface dataT { 23 name: string; 24 lock: DisplayLock; 25 expect: (container: HTMLElement) => HTMLElement | void; 26 } 27 28 const getNode = (overrides?: {}): JSX.Element | any => { 29 // given 30 const defaultProps: any = { 31 children: null, 32 }; 33 return <LockDisplay {...defaultProps} {...overrides} />; 34 }; 35 const getWrapper = (overrides: { lock: DisplayLock }) => render(getNode(overrides)); 36 37 const sampleApps: dataT[] = [ 38 { 39 name: 'one normal application lock', 40 lock: { 41 date: new Date(), 42 environment: 'test-env', 43 application: 'test-app', 44 lockId: 'test-id', 45 message: 'test-message', 46 authorName: 'defaultUser', 47 authorEmail: 'testEmail.com', 48 }, 49 expect: (container) => expect(container.getElementsByClassName('date-display--normal')).toHaveLength(1), 50 }, 51 { 52 name: 'one normal environment lock', 53 lock: { 54 date: new Date(), 55 environment: 'test-env', 56 lockId: 'test-id', 57 message: 'test-message', 58 authorName: 'defaultUser', 59 authorEmail: 'testEmail.com', 60 }, 61 expect: (container) => expect(container.getElementsByClassName('date-display--normal')).toHaveLength(1), 62 }, 63 { 64 name: 'one outadeted application lock', 65 lock: { 66 date: new Date('1995-12-17T03:24:00'), 67 environment: 'test-env', 68 application: 'test-app', 69 lockId: 'test-id', 70 message: 'test-message', 71 authorName: 'defaultUser', 72 authorEmail: 'testEmail.com', 73 }, 74 expect: (container) => expect(container.getElementsByClassName('date-display--outdated')).toHaveLength(1), 75 }, 76 { 77 name: 'one outdated existing lock', 78 lock: { 79 date: new Date('1995-12-17T03:24:00'), 80 environment: 'test-env', 81 application: 'test-app', 82 lockId: 'test-id', 83 message: 'test-message', 84 authorName: 'defaultUser', 85 authorEmail: 'testEmail.com', 86 }, 87 expect: (container) => expect(container.getElementsByClassName('date-display--outdated')).toHaveLength(1), 88 }, 89 ]; 90 91 describe.each(sampleApps)(`Renders an Application Card`, (testcase) => { 92 it(testcase.name, () => { 93 // when 94 const { container } = getWrapper({ lock: testcase.lock }); 95 testcase.expect(container); 96 }); 97 }); 98 });