generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests for Body, NextCloudVideoView, NextCloudEmbed - r…
…efs #253277
- Loading branch information
Showing
4 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import Body from './Body'; | ||
import { isInternalURL } from '@plone/volto/helpers'; | ||
import { getFieldURL } from '@eeacms/volto-nextcloud-video-block/helpers'; | ||
|
||
jest.mock('@eeacms/volto-nextcloud-video-block/helpers', () => ({ | ||
getFieldURL: jest.fn(), | ||
})); | ||
|
||
jest.mock('@plone/volto/helpers', () => ({ | ||
isInternalURL: jest.fn(), | ||
flattenToAppURL: jest.fn(), | ||
withBlockExtensions: jest.fn((Component) => Component), | ||
})); | ||
|
||
jest.mock('./players', () => ({ | ||
nextCloud: jest.fn(() => <div>NextCloud Player</div>), | ||
})); | ||
|
||
describe('Body', () => { | ||
it('renders correctly', () => { | ||
const props = { | ||
data: { | ||
url: 'nextCloud', | ||
align: 'full', | ||
preview_image: '/path/to/image', | ||
}, | ||
}; | ||
|
||
const component = renderer.create(<Body {...props} />); | ||
const json = component.toJSON(); | ||
expect(json).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders the correct player based on the url', () => { | ||
const props = { | ||
data: { | ||
url: 'nextCloud', | ||
align: 'full', | ||
preview_image: '/path/to/image', | ||
}, | ||
}; | ||
|
||
isInternalURL.mockReturnValue(true); | ||
getFieldURL.mockReturnValue('/path/to/video'); | ||
|
||
const component = renderer.create(<Body {...props} />); | ||
expect(component.toJSON().props.className).toContain('video-inner'); | ||
}); | ||
|
||
it('renders the correct player based on the url', () => { | ||
const props = { | ||
data: { | ||
url: 'nextCloud', | ||
align: 'full', | ||
preview_image: '/path/to/image', | ||
}, | ||
}; | ||
|
||
isInternalURL.mockReturnValue(false); | ||
getFieldURL.mockReturnValue('nextCloud'); | ||
|
||
const component = renderer.create(<Body {...props} />); | ||
|
||
expect(component.toJSON().props.className).toContain('video-inner'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import View from './NextCloudVideoView'; | ||
|
||
jest.mock('@plone/volto/helpers', () => ({ | ||
withBlockExtensions: jest.fn((Component) => Component), | ||
})); | ||
|
||
describe('View', () => { | ||
it('renders the video block', () => { | ||
const data = { align: 'center' }; | ||
const { container } = render(<View data={data} className="test-class" />); | ||
|
||
expect(container).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Body renders correctly 1`] = `null`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import NextCloudEmbed from './NextCloudEmbed'; | ||
import { isInternalURL, flattenToAppURL } from '@plone/volto/helpers'; | ||
import config from '@plone/volto/registry'; | ||
|
||
config.settings = { | ||
eea: { | ||
languages: [{ code: 'en', name: 'English' }], | ||
}, | ||
}; | ||
jest.mock('@plone/volto/helpers', () => ({ | ||
isInternalURL: jest.fn(), | ||
flattenToAppURL: jest.fn(), | ||
})); | ||
|
||
describe('NextCloudEmbed', () => { | ||
beforeEach(() => { | ||
isInternalURL.mockClear(); | ||
flattenToAppURL.mockClear(); | ||
}); | ||
|
||
it('renders without crashing', () => { | ||
const embedSettings = { | ||
placeholder: 'Placeholder', | ||
}; | ||
const data = { | ||
url: 'some/url', | ||
autoPlay: false, | ||
loop: false, | ||
}; | ||
const { container } = render( | ||
<NextCloudEmbed data={data} embedSettings={embedSettings} />, | ||
); | ||
expect(container.querySelector('video')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should apply the correct src for internal url', () => { | ||
const embedSettings = { | ||
placeholder: 'Placeholder', | ||
}; | ||
const data = { | ||
url: 'internal/url', | ||
autoPlay: false, | ||
loop: false, | ||
}; | ||
|
||
isInternalURL.mockReturnValueOnce(true); | ||
flattenToAppURL.mockReturnValueOnce('flattened/url'); | ||
|
||
const { container } = render( | ||
<NextCloudEmbed data={data} embedSettings={embedSettings} />, | ||
); | ||
expect(container.querySelector('video')).toHaveAttribute( | ||
'src', | ||
'flattened/url/@@download/file', | ||
); | ||
}); | ||
|
||
it('should apply the correct src for internal url with @@download', () => { | ||
const embedSettings = { | ||
placeholder: 'Placeholder', | ||
}; | ||
const data = { | ||
url: 'internal/url/@@download', | ||
autoPlay: false, | ||
loop: false, | ||
}; | ||
|
||
isInternalURL.mockReturnValueOnce(true); | ||
flattenToAppURL.mockReturnValueOnce('flattened/url'); | ||
|
||
const { container } = render( | ||
<NextCloudEmbed data={data} embedSettings={embedSettings} />, | ||
); | ||
expect(container.querySelector('video')).toHaveAttribute( | ||
'src', | ||
'flattened/url', | ||
); | ||
}); | ||
|
||
it('should apply the correct src for external url and no file path for subtitles', () => { | ||
const data = { | ||
url: 'external/url', | ||
autoPlay: false, | ||
loop: false, | ||
subtitles: [{ file: undefined, language: 'en' }], | ||
}; | ||
const embedSettings = { | ||
placeholder: 'Placeholder', | ||
}; | ||
|
||
isInternalURL.mockReturnValueOnce(false); | ||
|
||
const { container } = render( | ||
<NextCloudEmbed data={data} embedSettings={embedSettings} />, | ||
); | ||
expect(container.querySelector('video')).toBeInTheDocument(); | ||
expect(container.querySelector('video')).toHaveAttribute( | ||
'src', | ||
'external/url/download', | ||
); | ||
}); | ||
|
||
it('should apply the correct src for external url and subtitles and the file url is external', () => { | ||
const data = { | ||
url: 'external/url', | ||
autoPlay: false, | ||
loop: false, | ||
subtitles: [{ file: 'external/url/subtitle', language: 'en' }], | ||
}; | ||
const embedSettings = { | ||
placeholder: 'Placeholder', | ||
}; | ||
|
||
isInternalURL.mockReturnValueOnce(false); | ||
|
||
const { container } = render( | ||
<NextCloudEmbed data={data} embedSettings={embedSettings} />, | ||
); | ||
|
||
expect(container.querySelector('video')).toBeInTheDocument(); | ||
expect(container.querySelector('video')).toHaveAttribute( | ||
'src', | ||
'external/url/download', | ||
); | ||
}); | ||
|
||
it('should apply the correct src for external url and subtitles and the file url is internal', () => { | ||
const data = { | ||
url: 'external/url', | ||
autoPlay: false, | ||
loop: false, | ||
subtitles: [{ file: 'internal/url/subtitle', language: 'en' }], | ||
}; | ||
const embedSettings = { | ||
placeholder: 'Placeholder', | ||
}; | ||
|
||
isInternalURL.mockReturnValueOnce(true); | ||
flattenToAppURL.mockReturnValueOnce('flattened/url'); | ||
|
||
const { container } = render( | ||
<NextCloudEmbed data={data} embedSettings={embedSettings} />, | ||
); | ||
expect(container.querySelector('video')).toBeInTheDocument(); | ||
expect(container.querySelector('video')).toHaveAttribute( | ||
'src', | ||
'flattened/url/@@download/file', | ||
); | ||
}); | ||
}); |