-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve video size and format validation (#2755)
- Loading branch information
1 parent
13075c1
commit 715ecb2
Showing
20 changed files
with
462 additions
and
76 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
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
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
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
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
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,79 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { enforceFileSize } from '../'; | ||
import { Mock, AlternateMock, MockSelectionError } from './fixtures/mockClasses'; | ||
import { FILE_SIZE_ERROR_VIEW } from '../../constants'; | ||
|
||
describe( 'enforceFileSize', () => { | ||
it( 'should have a new error when the video file size is too big', () => { | ||
const mockThis = new Mock(); | ||
const selectButton = { model: new AlternateMock() }; | ||
mockThis.set( { | ||
secondary: new AlternateMock(), | ||
select: selectButton, | ||
} ); | ||
|
||
const attachment = new Mock(); | ||
const filesize = 12000000; | ||
const length = 4; | ||
attachment.set( { | ||
media_details: { filesize, length }, | ||
media_type: 'video', | ||
} ); | ||
|
||
enforceFileSize.call( mockThis, attachment, MockSelectionError ); | ||
const actualSelectionError = mockThis.secondary.get( FILE_SIZE_ERROR_VIEW ); | ||
|
||
expect( actualSelectionError.get( 'maxVideoMegabytesPerSecond' ) ).toBe( 1 ); | ||
expect( actualSelectionError.get( 'actualVideoMegabytesPerSecond' ) ).toBe( 3 ); | ||
|
||
// This shouldn't disable the 'Select' button in the Media Library. | ||
expect( selectButton.model.get( 'disabled' ) ).toBe( undefined ); | ||
} ); | ||
|
||
it( 'should not have an error when the video file size is under the maximum', () => { | ||
const mockThis = new Mock(); | ||
const selectButton = { model: new AlternateMock() }; | ||
mockThis.set( { | ||
secondary: new AlternateMock(), | ||
select: selectButton, | ||
} ); | ||
|
||
const attachment = new Mock(); | ||
const filesize = 6000000; | ||
const length = 6; | ||
attachment.set( { | ||
media_details: { filesize, length }, | ||
media_type: 'video', | ||
} ); | ||
|
||
enforceFileSize.call( mockThis, attachment, MockSelectionError ); | ||
|
||
expect( mockThis.secondary.get( FILE_SIZE_ERROR_VIEW ) ).toBe( undefined ); | ||
expect( selectButton.model.get( 'disabled' ) ).toBe( undefined ); | ||
} ); | ||
|
||
it( 'should not have an error if the file type is not a video', () => { | ||
const mockThis = new Mock(); | ||
const selectButton = { model: new AlternateMock() }; | ||
mockThis.set( { | ||
secondary: new AlternateMock(), | ||
select: selectButton, | ||
} ); | ||
|
||
const attachment = new Mock(); | ||
const filesize = 12000000; | ||
const length = 4; | ||
const nonVideo = 'image'; | ||
attachment.set( { | ||
media_details: { filesize, length }, | ||
media_type: nonVideo, | ||
} ); | ||
|
||
enforceFileSize.call( mockThis, attachment, MockSelectionError ); | ||
|
||
expect( mockThis.secondary.get( FILE_SIZE_ERROR_VIEW ) ).toBe( undefined ); | ||
expect( selectButton.model.get( 'disabled' ) ).toBe( undefined ); | ||
} ); | ||
} ); |
Oops, something went wrong.