-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! ✨(front) add components needed for uploading thumbnail
- Loading branch information
Showing
3 changed files
with
179 additions
and
55 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
108 changes: 108 additions & 0 deletions
108
...shboardVideoLiveControlPane/widgets/DashboardVideoLiveWidgetThumbnail/utils/utils.spec.ts
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,108 @@ | ||
import { defineMessages } from 'react-intl'; | ||
|
||
import { UploadManagerStatus } from 'components/UploadManager'; | ||
import { modelName } from 'types/models'; | ||
import { uploadState } from 'types/tracks'; | ||
import { thumbnailMockFactory } from 'utils/tests/factories'; | ||
import { determineMessage } from './utils'; | ||
|
||
jest.mock('data/appData', () => ({ | ||
appData: { | ||
jwt: 'some token', | ||
}, | ||
})); | ||
|
||
const genericThumbnail = thumbnailMockFactory(); | ||
const genericUploadManagerState = { | ||
[genericThumbnail.id]: { | ||
file: new File(['(⌐□_□)'], 'genericFile.png'), | ||
objectId: genericThumbnail.id, | ||
objectType: modelName.THUMBNAILS, | ||
progress: 50, | ||
status: UploadManagerStatus.UPLOADING, | ||
}, | ||
}; | ||
|
||
const messages = defineMessages({ | ||
thumbnailError: { | ||
defaultMessage: | ||
'An error happened while uploading your thumbnail. Please retry.', | ||
description: 'A text displayed when there is no uploaded thumbnail.', | ||
id: 'components.ThumbnailManager.thumbnailError', | ||
}, | ||
thumbnailUploaded: { | ||
defaultMessage: 'Your image is being uploaded.', | ||
description: 'A text displayed when the thumbnail is being uploaded.', | ||
id: 'components.ThumbnailManager.thumbnailUploaded', | ||
}, | ||
thumbnailProcessed: { | ||
defaultMessage: 'Your image is being processed.', | ||
description: 'A text displayed when the thumbnail is being processed.', | ||
id: 'components.ThumbnailManager.thumbnailProcessed', | ||
}, | ||
}); | ||
|
||
describe('DashboardVideoLiveWidgetThumbnail/utils', () => { | ||
it('determineMessage when thumbnail upload has an error', () => { | ||
const thumbnailInError = { | ||
...genericThumbnail, | ||
upload_state: uploadState.ERROR, | ||
}; | ||
|
||
expect( | ||
determineMessage(thumbnailInError, genericUploadManagerState), | ||
).toEqual(messages.thumbnailError); | ||
}); | ||
|
||
it('determineMessage when thumbnail is being uploaded', () => { | ||
const uploadingThumbnail = { | ||
...genericThumbnail, | ||
upload_state: uploadState.PENDING, | ||
}; | ||
const initializatingUploadManagerState = { | ||
[genericThumbnail.id]: { | ||
...genericUploadManagerState[genericThumbnail.id], | ||
status: UploadManagerStatus.INIT, | ||
}, | ||
}; | ||
|
||
expect( | ||
determineMessage(uploadingThumbnail, genericUploadManagerState), | ||
).toEqual(messages.thumbnailUploaded); | ||
|
||
expect( | ||
determineMessage(uploadingThumbnail, initializatingUploadManagerState), | ||
).toEqual(messages.thumbnailUploaded); | ||
}); | ||
|
||
it('determineMessage when thumbnail is being processed', () => { | ||
const uploadingThumbnail = { | ||
...genericThumbnail, | ||
upload_state: uploadState.PENDING, | ||
}; | ||
const processedThumbnail = { | ||
...genericThumbnail, | ||
upload_state: uploadState.PROCESSING, | ||
}; | ||
const successfulUploadManagerState = { | ||
[genericThumbnail.id]: { | ||
...genericUploadManagerState[genericThumbnail.id], | ||
status: UploadManagerStatus.SUCCESS, | ||
}, | ||
}; | ||
|
||
expect( | ||
determineMessage(processedThumbnail, genericUploadManagerState), | ||
).toEqual(messages.thumbnailProcessed); | ||
|
||
expect( | ||
determineMessage(uploadingThumbnail, successfulUploadManagerState), | ||
).toEqual(messages.thumbnailProcessed); | ||
}); | ||
|
||
it('determineMessage when there is no message to return', () => { | ||
expect( | ||
determineMessage(genericThumbnail, genericUploadManagerState), | ||
).toEqual(null); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
...ts/DashboardVideoLiveControlPane/widgets/DashboardVideoLiveWidgetThumbnail/utils/utils.ts
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,52 @@ | ||
import { defineMessages, MessageDescriptor } from 'react-intl'; | ||
|
||
import { | ||
UploadManagerState, | ||
UploadManagerStatus, | ||
} from 'components/UploadManager'; | ||
import { Thumbnail, uploadState } from 'types/tracks'; | ||
import { Nullable } from 'utils/types'; | ||
|
||
const messages = defineMessages({ | ||
thumbnailError: { | ||
defaultMessage: | ||
'An error happened while uploading your thumbnail. Please retry.', | ||
description: 'A text displayed when there is no uploaded thumbnail.', | ||
id: 'components.ThumbnailManager.thumbnailError', | ||
}, | ||
thumbnailUploaded: { | ||
defaultMessage: 'Your image is being uploaded.', | ||
description: 'A text displayed when the thumbnail is being uploaded.', | ||
id: 'components.ThumbnailManager.thumbnailUploaded', | ||
}, | ||
thumbnailProcessed: { | ||
defaultMessage: 'Your image is being processed.', | ||
description: 'A text displayed when the thumbnail is being processed.', | ||
id: 'components.ThumbnailManager.thumbnailProcessed', | ||
}, | ||
}); | ||
|
||
export const determineMessage = ( | ||
thumbnail: Thumbnail, | ||
uploadManagerState: UploadManagerState, | ||
): Nullable<MessageDescriptor> => { | ||
if (thumbnail.upload_state === uploadState.ERROR) { | ||
return messages.thumbnailError; | ||
} | ||
if ( | ||
(thumbnail.upload_state === uploadState.PENDING && | ||
uploadManagerState[thumbnail.id]?.status === | ||
UploadManagerStatus.UPLOADING) || | ||
uploadManagerState[thumbnail.id]?.status === UploadManagerStatus.INIT | ||
) { | ||
return messages.thumbnailUploaded; | ||
} | ||
if ( | ||
thumbnail.upload_state === uploadState.PROCESSING || | ||
(thumbnail.upload_state === uploadState.PENDING && | ||
uploadManagerState[thumbnail.id]?.status === UploadManagerStatus.SUCCESS) | ||
) { | ||
return messages.thumbnailProcessed; | ||
} | ||
return null; | ||
}; |