Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('app renders stuff!', async () => {
// this is how you render a component that has it's own suspense.
// no need to render our own suspense in the test.
render()
const lazyElement = await screen.findByText(/i am lazy/i)
expect(lazyElement).toBeInTheDocument()
})
active_stamp: 28271937429,
id: '42',
is_ready_to_show: true,
language: 'fr',
mode: timedTextMode.SUBTITLE,
title: 'foo',
upload_state: uploadState.READY,
url: 'https://example.com/timedtexttrack/42',
video: '142',
}}
/>,
),
),
);
await screen.findByText('French');
screen.getByText((content) => content.startsWith('Ready'));
// No polling takes place as the track is already READY
expect(
fetchMock.called('/api/timedtexttracks/1/', { method: 'GET' }),
).not.toBeTruthy();
});
it('renders', async () => {
const mockVideo: any = {
id: 'dd44',
thumbnail: null,
timed_text_tracks: [],
upload_state: uploadState.PROCESSING,
};
render(
wrapInIntlProvider(
}>
,
),
);
await screen.findByText('Dashboard');
await screen.findByTitle('dd44');
});
});
it('allows video download when the video object specifies it', async () => {
mockIsMSESupported.mockReturnValue(false);
appData.video!.show_download = true;
render(wrapInIntlProvider());
await screen.findByText(/Download this video/i);
screen.getByText('Show a transcript');
});
fireEvent.click(button);
expect(
fetchMock.calls('/api/timedtexttracks/', { method: 'POST' }).length,
).toEqual(1);
expect(
fetchMock.lastCall('/api/timedtexttracks/', { method: 'POST' })![1],
).toEqual({
body: '{"language":"fr","mode":"st"}',
headers: {
Authorization: 'Bearer some token',
'Content-Type': 'application/json',
},
method: 'POST',
});
await screen.findByText('Upload form: timedtexttracks 42');
});
{
active_stamp: 1549385921,
id: 'ttt-1',
is_ready_to_show: true,
language: 'fr',
mode: 'st',
upload_state: 'ready',
url: 'https://example.com/timedtext/ttt-1.vtt',
},
]);
const { container } = render(
wrapInIntlProvider(),
);
await screen.findByText('Show a transcript');
expect(container.querySelector('option[value="ttt-1"]')).not.toBeNull();
});
render(
wrapInIntlProvider(
wrapInRouter(
,
),
),
);
screen.getByText('Our title');
await screen.findByText('French');
screen.getByText('English');
});
});
Promise.reject(new Error('Failed!')),
);
const { getByText } = render(
wrapInIntlProvider(
wrapInRouter(, [
{
path: ERROR_COMPONENT_ROUTE(),
render: ({ match }) => (
<span>{`Error Component: ${match.params.code}`}</span>
),
},
]),
),
);
await screen.findByText('Error Component: notFound');
expect(report).toBeCalledWith(new Error('Failed!'));
});
});
},
],
),
),
);
await screen.findByText('Add a language');
const input = screen.getByRole('textbox');
fireEvent.change(input!, { target: { value: 'French' } });
fireEvent.keyDown(input!, { keyCode: 9, key: 'Tab' });
fireEvent.click(screen.getByText('French'));
const button = screen.getByRole('button', { name: /Upload the file/i });
fireEvent.click(button);
await screen.findByText('There was an error during track creation.');
expect(report).toHaveBeenCalledWith(
new Error('Failed to create a new TimedTextTrack with fr, st: 500.'),
);
});
});
mockGetResource.mockResolvedValue(object);
const { container } = render(
wrapInIntlProvider(
wrapInRouter(
,
[
{
path: DASHBOARD_ROUTE(),
render: () => <span>dashboard</span>,
},
],
),
),
);
await screen.findByText('Create a new video');
fireEvent.drop(container.querySelector('input[type="file"]')!, {
target: {
files: [new File(['(⌐□_□)'], 'course.mp4', { type: 'video/mp4' })],
},
});
await waitFor(() =>
expect(
fetchMock.called('/api/videos/video-id/initiate-upload/', {
method: 'POST',
}),
).toBe(true),
);
await waitFor(() =>
expect(fetchMock.called('/api/videos/video-id/', { method: 'PUT' })).toBe(
true,