-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨(video_player) lazy load embed video player
Instead of loading the external video player, it only loads the video player if the user clicks on the big ▶ icon.
- Loading branch information
Showing
5 changed files
with
160 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
""" | ||
Test the custom video player with a performance improvement. | ||
""" | ||
|
||
import lxml.html # nosec | ||
from cms.test_utils.testcases import CMSTestCase | ||
|
||
from richie.apps.courses.factories import CourseFactory, VideoSample | ||
|
||
|
||
class CoursesTemplatesCourseDetailRenderingCMSTestCase(CMSTestCase): | ||
""" | ||
Test the custom video player with a performance improvement. | ||
""" | ||
|
||
video_sample_without_image = VideoSample( | ||
"Anant Agarwal: Why massively open online courses (still) matter", | ||
None, | ||
"//www.youtube.com/embed/rYwTA5RA9eU", | ||
) | ||
|
||
def test_templates_course_detail_teaser_video_cover_empty(self): | ||
""" | ||
When the `course_teaser` placeholder is filled with a VideoPlayerPlugin. | ||
The course page should return an empty video cover image if: | ||
- the video poster image is empty; | ||
- the course page hasn't any `course_cover` placeholder. | ||
""" | ||
video_sample = self.video_sample_without_image | ||
course = CourseFactory(fill_teaser=video_sample, should_publish=True) | ||
|
||
response = self.client.get(course.extended_object.get_absolute_url()) | ||
self.assertEqual(response.status_code, 200) | ||
html = lxml.html.fromstring(response.content) | ||
iframe = html.cssselect(".subheader__teaser .aspect-ratio iframe")[0] | ||
self.assertEqual(iframe.get("data-src"), video_sample.url + "?&autoplay=1") | ||
self.assertEqual(iframe.get("title"), video_sample.label) | ||
self.assertEqual(iframe.get("style"), "display: none;") | ||
self.assertIn("allowfullscreen", iframe.keys()) | ||
# no video cover image | ||
self.assertEqual( | ||
len(html.cssselect(".subheader__teaser .aspect-ratio a img")), 0 | ||
) | ||
|
||
def test_templates_course_detail_teaser_video_cover_from_course_cover(self): | ||
""" | ||
When the `course_teaser` placeholder is filled with a VideoPlayerPlugin. | ||
The course page show the course cover image if: | ||
- the video poster image is empty; | ||
- the course page has a `course_cover` placeholder. | ||
""" | ||
cover_file_name = cover_file_name = "cover.jpg" | ||
video_sample = self.video_sample_without_image | ||
course = CourseFactory( | ||
fill_teaser=video_sample, | ||
fill_cover={"original_filename": cover_file_name}, | ||
should_publish=True, | ||
) | ||
|
||
response = self.client.get(course.extended_object.get_absolute_url()) | ||
self.assertEqual(response.status_code, 200) | ||
html = lxml.html.fromstring(response.content) | ||
iframe = html.cssselect(".subheader__teaser .aspect-ratio iframe")[0] | ||
self.assertEqual(iframe.get("data-src"), video_sample.url + "?&autoplay=1") | ||
self.assertEqual(iframe.get("title"), video_sample.label) | ||
self.assertEqual(iframe.get("style"), "display: none;") | ||
self.assertIn("allowfullscreen", iframe.keys()) | ||
img = html.cssselect(".subheader__teaser .aspect-ratio a img")[0] | ||
self.assertIn(cover_file_name, img.get("src")) |
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