|
1 | | -import { render, screen } from '@testing-library/react'; |
| 1 | +import { fireEvent, render, screen } from '@testing-library/react'; |
2 | 2 | import '@testing-library/jest-dom'; |
3 | 3 | import { Hero } from '../Hero'; |
4 | 4 | import { Props } from '../../../utils/types'; |
@@ -61,6 +61,39 @@ describe('Hero component', () => { |
61 | 61 | expect(uuidCopyButton).toBeInTheDocument(); |
62 | 62 | expect(secretCopyButton).toBeInTheDocument(); |
63 | 63 | }); |
| 64 | + |
| 65 | + test('show UUID by default', () => { |
| 66 | + render(<Hero {...mockProps} />); |
| 67 | + |
| 68 | + const uuidCode = screen.getAllByText(mockProps.uuid)[0]; |
| 69 | + expect(uuidCode).toBeInTheDocument(); |
| 70 | + }); |
| 71 | + |
| 72 | + test('Hides UUID when button is clicked', () => { |
| 73 | + render(<Hero {...mockProps} />); |
| 74 | + const togglebutton = screen.getByRole('button', { name: /hide uuid/i }); |
| 75 | + |
| 76 | + fireEvent.click(togglebutton); |
| 77 | + |
| 78 | + const maskedUuid = '•'.repeat(mockProps.uuid.length); |
| 79 | + expect(screen.getByText(maskedUuid)).toBeInTheDocument(); |
| 80 | + expect( |
| 81 | + screen.getByRole('button', { name: /show uuid/i }) |
| 82 | + ).toBeInTheDocument(); |
| 83 | + }); |
| 84 | + |
| 85 | + test('Hides encryption secret when button is clicked', () => { |
| 86 | + render(<Hero {...mockProps} />); |
| 87 | + const togglebutton = screen.getByRole('button', { name: /hide secret/i }); |
| 88 | + |
| 89 | + fireEvent.click(togglebutton); |
| 90 | + |
| 91 | + const maskedsecret = '•'.repeat(mockProps.encryption_secret.length); |
| 92 | + expect(screen.getByText(maskedsecret)).toBeInTheDocument(); |
| 93 | + expect( |
| 94 | + screen.getByRole('button', { name: /show secret/i }) |
| 95 | + ).toBeInTheDocument(); |
| 96 | + }); |
64 | 97 | }); |
65 | 98 |
|
66 | 99 | describe('Hero component using snapshot', () => { |
|
0 commit comments