|
| 1 | +// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +import { render, screen } from '@testing-library/react'; |
| 4 | +import { describe, expect, test } from 'vitest'; |
| 5 | +import { SvConfigProvider } from '../../utils'; |
| 6 | +import userEvent from '@testing-library/user-event'; |
| 7 | +import App from '../../App'; |
| 8 | + |
| 9 | +type UserEvent = ReturnType<typeof userEvent.setup>; |
| 10 | + |
| 11 | +const GovernanceWithConfig = () => { |
| 12 | + return ( |
| 13 | + <SvConfigProvider> |
| 14 | + <App /> |
| 15 | + </SvConfigProvider> |
| 16 | + ); |
| 17 | +}; |
| 18 | + |
| 19 | +async function login(user: UserEvent) { |
| 20 | + render(<GovernanceWithConfig />); |
| 21 | + |
| 22 | + expect(await screen.findByText('Log In')).toBeDefined(); |
| 23 | + |
| 24 | + const input = screen.getByRole('textbox'); |
| 25 | + await user.type(input, 'sv1'); |
| 26 | + |
| 27 | + const button = screen.getByRole('button', { name: 'Log In' }); |
| 28 | + user.click(button); |
| 29 | +} |
| 30 | + |
| 31 | +async function navigateToGovernancePage(user: UserEvent) { |
| 32 | + expect(await screen.findByTestId('navlink-governance-beta')).toBeDefined(); |
| 33 | + await user.click(screen.getByText('Governance')); |
| 34 | +} |
| 35 | + |
| 36 | +// Skipping this test until we switch to the new UI |
| 37 | +describe.skip('Governance Page', () => { |
| 38 | + test('Login and navigate to Governance Page', async () => { |
| 39 | + const user = userEvent.setup(); |
| 40 | + |
| 41 | + await login(user); |
| 42 | + await navigateToGovernancePage(user); |
| 43 | + |
| 44 | + const title = screen.getByTestId('governance-page-title'); |
| 45 | + expect(title).toBeDefined(); |
| 46 | + }); |
| 47 | + |
| 48 | + test('should render all Governance Page sections', async () => { |
| 49 | + const user = userEvent.setup(); |
| 50 | + |
| 51 | + render(<GovernanceWithConfig />); |
| 52 | + |
| 53 | + await navigateToGovernancePage(user); |
| 54 | + |
| 55 | + const actionRequired = screen.getByTestId('action-required-section'); |
| 56 | + expect(actionRequired).toBeDefined(); |
| 57 | + |
| 58 | + const inflightVoteRequests = screen.getByTestId('inflight-vote-requests-section'); |
| 59 | + expect(inflightVoteRequests).toBeDefined(); |
| 60 | + |
| 61 | + const voteHistory = screen.getByTestId('vote-history-section'); |
| 62 | + expect(voteHistory).toBeDefined(); |
| 63 | + }); |
| 64 | + |
| 65 | + test('should display the correct number of Action Required Requests', async () => { |
| 66 | + const user = userEvent.setup(); |
| 67 | + |
| 68 | + render(<GovernanceWithConfig />); |
| 69 | + |
| 70 | + await navigateToGovernancePage(user); |
| 71 | + |
| 72 | + const actions = screen.getAllByTestId('action-required-card'); |
| 73 | + expect(actions.length).toBe(4); |
| 74 | + }); |
| 75 | + |
| 76 | + test('should show the correct number of Inflight Vote Requests', async () => { |
| 77 | + const user = userEvent.setup(); |
| 78 | + |
| 79 | + render(<GovernanceWithConfig />); |
| 80 | + |
| 81 | + await navigateToGovernancePage(user); |
| 82 | + |
| 83 | + expect(() => screen.getAllByTestId('inflight-vote-requests-row')).toThrowError( |
| 84 | + /Unable to find an element/ |
| 85 | + ); |
| 86 | + }); |
| 87 | + |
| 88 | + test('should correctly display the number of completed Vote Requests (History)', async () => { |
| 89 | + const user = userEvent.setup(); |
| 90 | + |
| 91 | + render(<GovernanceWithConfig />); |
| 92 | + |
| 93 | + await navigateToGovernancePage(user); |
| 94 | + |
| 95 | + const voteRequests = screen.getAllByTestId('vote-history-row'); |
| 96 | + expect(voteRequests.length).toBe(5); |
| 97 | + |
| 98 | + expect(true).toBe(true); |
| 99 | + }); |
| 100 | +}); |
0 commit comments