From 04c02179a9966c188ab7c3dcf29ce3cdf6ee9773 Mon Sep 17 00:00:00 2001 From: Stephan Schreiner Date: Tue, 30 Aug 2022 18:36:49 +0200 Subject: [PATCH] enhancing language selection tests, making them more sensitive, adding case with 3-letter code, using RegExp object instead of string with RegExp --- .../streaming.controllers.MediaController.js | 119 +++++++++--------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/test/unit/streaming.controllers.MediaController.js b/test/unit/streaming.controllers.MediaController.js index b08684543e..e1f3927b62 100644 --- a/test/unit/streaming.controllers.MediaController.js +++ b/test/unit/streaming.controllers.MediaController.js @@ -334,99 +334,100 @@ describe('MediaController', function () { }); describe('Initial Track Management', function () { + let streamInfo = { + id: 'id' + }; + let frTrack = { + type: trackType, + streamInfo: streamInfo, + lang: 'fr', + viewpoint: 'viewpoint', + roles: 1, + accessibility: 1, + audioChannelConfiguration: 1 + }; + const qtzTrack = { + type: trackType, + streamInfo: streamInfo, + lang: 'qtz', + viewpoint: 'viewpoint', + roles: 1, + accessibility: 1, + audioChannelConfiguration: 1 + }; it('should check initial media settings to choose initial track', function () { - let streamInfo = { - id: 'id' - }; - let track = { - type: trackType, - streamInfo: streamInfo, - lang: 'fr', - viewpoint: 'viewpoint', - roles: 1, - accessibility: 1, - audioChannelConfiguration: 1 - }; + mediaController.addTrack(frTrack); + mediaController.addTrack(qtzTrack); - mediaController.addTrack(track); + let trackList = mediaController.getTracksFor(trackType, streamInfo.id); + expect(trackList).to.have.lengthOf(2); + expect(objectUtils.areEqual(trackList[0], frTrack)).to.be.true; // jshint ignore:line + expect(objectUtils.areEqual(trackList[1], qtzTrack)).to.be.true; // jshint ignore:line + + let currentTrack = mediaController.getCurrentTrackFor(trackType, streamInfo.id); + expect(objectUtils.areEqual(currentTrack, frTrack)).to.be.false; // jshint ignore:line + + // call to setInitialMediaSettingsForType + mediaController.setInitialSettings(trackType, { + lang: 'qtz', + viewpoint: 'viewpoint' + }); + mediaController.setInitialMediaSettingsForType(trackType, streamInfo); + + currentTrack = mediaController.getCurrentTrackFor(trackType, streamInfo.id); + expect(objectUtils.areEqual(currentTrack, qtzTrack)).to.be.true; // jshint ignore:line + + }); + + it('should check initial media settings to choose initial track with 639-2 3-letter code', function () { + mediaController.addTrack(qtzTrack); + mediaController.addTrack(frTrack); let trackList = mediaController.getTracksFor(trackType, streamInfo.id); - expect(trackList).to.have.lengthOf(1); - expect(objectUtils.areEqual(trackList[0], track)).to.be.true; // jshint ignore:line + expect(trackList).to.have.lengthOf(2); + expect(objectUtils.areEqual(trackList[0], qtzTrack)).to.be.true; // jshint ignore:line + expect(objectUtils.areEqual(trackList[1], frTrack)).to.be.true; // jshint ignore:line let currentTrack = mediaController.getCurrentTrackFor(trackType, streamInfo.id); - expect(objectUtils.areEqual(currentTrack, track)).to.be.false; // jshint ignore:line + expect(objectUtils.areEqual(currentTrack, frTrack)).to.be.false; // jshint ignore:line // call to setInitialMediaSettingsForType mediaController.setInitialSettings(trackType, { - lang: 'fr', + lang: 'fre', viewpoint: 'viewpoint' }); mediaController.setInitialMediaSettingsForType(trackType, streamInfo); currentTrack = mediaController.getCurrentTrackFor(trackType, streamInfo.id); - expect(objectUtils.areEqual(currentTrack, track)).to.be.true; // jshint ignore:line + expect(objectUtils.areEqual(currentTrack, frTrack)).to.be.true; // jshint ignore:line }); it('should check initial media settings to choose initial track with a string/regex lang', function () { - const streamInfo = { - id: 'id' - }; - const track = { - type: trackType, - streamInfo: streamInfo, - lang: 'fr', - viewpoint: 'viewpoint', - roles: 1, - accessibility: 1, - audioChannelConfiguration: 1 - }; - - mediaController.addTrack(track); + mediaController.addTrack(frTrack); + mediaController.addTrack(qtzTrack); let trackList = mediaController.getTracksFor(trackType, streamInfo.id); - expect(trackList).to.have.lengthOf(1); - expect(objectUtils.areEqual(trackList[0], track)).to.be.true; // jshint ignore:line + expect(trackList).to.have.lengthOf(2); + expect(objectUtils.areEqual(trackList[0], frTrack)).to.be.true; // jshint ignore:line + expect(objectUtils.areEqual(trackList[1], qtzTrack)).to.be.true; // jshint ignore:line let currentTrack = mediaController.getCurrentTrackFor(trackType, streamInfo.id); - expect(objectUtils.areEqual(currentTrack, track)).to.be.false; // jshint ignore:line + expect(objectUtils.areEqual(currentTrack, frTrack)).to.be.false; // jshint ignore:line // call to setInitialMediaSettingsForType mediaController.setInitialSettings(trackType, { - lang: 'fr|en|qtz', + lang: /fr|en|qtz/, viewpoint: 'viewpoint' }); mediaController.setInitialMediaSettingsForType(trackType, streamInfo); currentTrack = mediaController.getCurrentTrackFor(trackType, streamInfo.id); - expect(objectUtils.areEqual(currentTrack, track)).to.be.true; // jshint ignore:line + expect(objectUtils.areEqual(currentTrack, frTrack)).to.be.true; // jshint ignore:line }); it('should check initial media settings to choose initial track with a regex lang', function () { - const streamInfo = { - id: 'id' - }; - const frTrack = { - type: trackType, - streamInfo: streamInfo, - lang: 'fr', - viewpoint: 'viewpoint', - roles: 1, - accessibility: 1, - audioChannelConfiguration: 1 - }; - const qtzTrack = { - type: trackType, - streamInfo: streamInfo, - lang: 'qtz', - viewpoint: 'viewpoint', - roles: 1, - accessibility: 1, - audioChannelConfiguration: 1 - }; - mediaController.addTrack(frTrack); mediaController.addTrack(qtzTrack);