Skip to content

Commit

Permalink
feat: Use video tile for description, if description is empty (#24)
Browse files Browse the repository at this point in the history
* use video tile for description if short description is empty

* falback to video title if long description is preferred

Co-authored-by: Jing Liu <jing.liu@rea-group.com>
  • Loading branch information
lanmengyujing and jingliu-rea authored May 24, 2021
1 parent d957dac commit 869b6fb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ const schema = function(options) {
});

if (options.preferLongDescription) {
ld.description = this.mediainfo.longDescription || this.mediainfo.description;
ld.description = this.mediainfo.longDescription || this.mediainfo.description || this.mediainfo.name;
} else {
ld.description = this.mediainfo.description;
ld.description = this.mediainfo.description || this.mediainfo.name;
}

const formattedDuration = duration8601(this.mediainfo.duration);
Expand Down
46 changes: 46 additions & 0 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,30 @@ QUnit.test('merges onto base options', function(assert) {
assert.strictEqual(generatedSchema.param1, 'abc', 'merged onto base options');
});

QUnit.test('defaults to video title when prefer long description but both short description and long description are empty', function(assert) {
this.player.mediainfo = {
id: 1234,
referenceId: 'xyz',
name: 'NAME',
description: '',
duration: 3661,
publishedAt: '2019-02-12T09:07:44',
poster: 'https://loremflickr.com/1280/720',
tags: ['one', 'two', 'three'],
longDescription: ''
};
this.player.schema({
preferLongDescription: true
});
this.player.trigger('error');

this.clock.tick(1);

const generatedSchema = JSON.parse(this.player.schemaEl_.textContent);

assert.strictEqual(generatedSchema.description, 'NAME', 'used video title');
});

QUnit.test('defaults to short description', function(assert) {

this.player.schema();
Expand All @@ -222,6 +246,28 @@ QUnit.test('defaults to short description', function(assert) {
assert.strictEqual(generatedSchema.description, 'DESCRIPTION', 'used short description');
});

QUnit.test('defaults to video title if short description is empty', function(assert) {
this.player.mediainfo = {
id: 1234,
referenceId: 'xyz',
name: 'NAME',
description: '',
duration: 3661,
publishedAt: '2019-02-12T09:07:44',
poster: 'https://loremflickr.com/1280/720',
tags: ['one', 'two', 'three']
};
this.player.schema();
this.player.trigger('error');

// Tick the clock forward enough to trigger the player to be "ready".
this.clock.tick(1);

const generatedSchema = JSON.parse(this.player.schemaEl_.textContent);

assert.strictEqual(generatedSchema.description, 'NAME', 'used video title');
});

QUnit.test('long description can be used', function(assert) {

this.player.schema({
Expand Down

0 comments on commit 869b6fb

Please sign in to comment.