-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSubmissionVideoModal.spec.tsx
More file actions
52 lines (39 loc) · 2.08 KB
/
Copy pathSubmissionVideoModal.spec.tsx
File metadata and controls
52 lines (39 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import i18n from '#i18n/index.js';
import { render, screen, fireEvent } from '#utils/testUtils.js';
import SubmissionVideoModal from '../SubmissionVideoModal.js';
const mockVideoUrl = 'https://example.com/video.mp4';
const mockTitle = 'testModelName #1';
const mockOnDismiss = vi.fn();
describe('<SubmissionVideoModal />', () => {
beforeEach(() => {
mockOnDismiss.mockClear();
});
it('renders the modal with the correct header', () => {
render(<SubmissionVideoModal videoUrl={mockVideoUrl} title={mockTitle} onDismiss={mockOnDismiss} />);
expect(screen.getByText(i18n.t('raceDetails:videoModal.header', { title: mockTitle }))).toBeInTheDocument();
});
it('renders a video element with the provided URL', () => {
render(<SubmissionVideoModal videoUrl={mockVideoUrl} title={mockTitle} onDismiss={mockOnDismiss} />);
const video = document.querySelector('video');
expect(video).toBeInTheDocument();
expect(video).toHaveAttribute('src', mockVideoUrl);
});
it('renders the video with autoPlay and controls attributes, and muted property', () => {
render(<SubmissionVideoModal videoUrl={mockVideoUrl} title={mockTitle} onDismiss={mockOnDismiss} />);
const video = document.querySelector('video') as HTMLVideoElement;
expect(video).toHaveAttribute('autoplay');
expect(video).toHaveAttribute('controls');
// jsdom does not reflect the muted React prop as an HTML attribute; check the property directly
expect(video.muted).toBe(true);
});
it('calls onDismiss when the modal dismiss button is clicked', () => {
render(<SubmissionVideoModal videoUrl={mockVideoUrl} title={mockTitle} onDismiss={mockOnDismiss} />);
// Cloudscape modal dismiss button has no accessible text; target it by its CSS class
const closeButton = document.querySelector('button[class*="dismiss-control"]') as HTMLButtonElement;
expect(closeButton).toBeInTheDocument();
fireEvent.click(closeButton);
expect(mockOnDismiss).toHaveBeenCalledTimes(1);
});
});