Copy Link button implemented
This commit is contained in:
@@ -1,11 +1,51 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import ResultsDisplay from '../src/components/ResultsDisplay';
|
||||
import { Decision } from '../src/hooks/useSession';
|
||||
|
||||
// Mock the Clipboard API
|
||||
Object.defineProperty(navigator, 'clipboard', {
|
||||
value: {
|
||||
writeText: jest.fn(),
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
|
||||
describe('ResultsDisplay responsiveness and touch functionality', () => {
|
||||
const mockDecision: Decision = {
|
||||
goTo: 'Go-to decision',
|
||||
alsoGood: 'Also good decision',
|
||||
considerable: 'Considerable decision',
|
||||
needsDiscussion: 'Needs discussion decision',
|
||||
noGoes: 'No-goes decision',
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('renders without crashing', () => {
|
||||
render(<ResultsDisplay />);
|
||||
// Add assertions specific to ResultsDisplay
|
||||
render(<ResultsDisplay decision={mockDecision} />);
|
||||
expect(screen.getByText('Cooperative Decision')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should display the Copy Link button', () => {
|
||||
render(<ResultsDisplay decision={mockDecision} />);
|
||||
expect(screen.getByRole('button', { name: /copy link/i })).toBeInTheDocument();
|
||||
expect(screen.getByTestId('ContentCopyIcon')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should copy the session URL to clipboard when Copy Link button is clicked', async () => {
|
||||
render(<ResultsDisplay decision={mockDecision} />);
|
||||
const copyButton = screen.getByRole('button', { name: /copy link/i });
|
||||
fireEvent.click(copyButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(navigator.clipboard.writeText).toHaveBeenCalledTimes(1);
|
||||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(window.location.href);
|
||||
expect(screen.getByRole('button', { name: /copied!/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
// Placeholder for responsive tests
|
||||
|
||||
Reference in New Issue
Block a user