Back to Repositories

Testing Loading Spinner Localization in Video.js

This test suite validates the loading spinner component in Video.js, focusing on localization functionality and text content updates. The tests ensure proper internationalization support for loading status messages across different language settings.

Test Coverage Overview

The test suite covers essential functionality of the Video.js loading spinner component, with particular emphasis on language localization features.

  • Verifies loading spinner text localization
  • Tests dynamic language switching behavior
  • Validates text content updates
  • Ensures proper player integration

Implementation Analysis

The testing approach utilizes QUnit’s module and test structure to validate the LoadingSpinner component. The implementation leverages TestHelpers for player instantiation and employs Video.js’s language API for internationalization testing.

Key patterns include mock player creation, language resource addition, and DOM content verification.

Technical Details

Testing infrastructure includes:

  • QUnit test framework
  • Video.js TestHelpers utility
  • ES modules for component imports
  • Custom language resource injection
  • DOM assertion capabilities

Best Practices Demonstrated

The test suite exemplifies strong testing practices through isolated component testing, clear test case organization, and proper setup of test dependencies.

  • Modular test structure
  • Clean component initialization
  • Explicit assertion messages
  • Focused test scope

videojs/videoJs

test/unit/loading-spinner.test.js

            
/* eslint-env qunit */
import LoadingSpinner from '../../src/js/loading-spinner.js';
import TestHelpers from './test-helpers.js';
import videojs from '../../src/js/video.js';

QUnit.module('Loading Spinner', {});

QUnit.test('should localize on languagechange', function(assert) {
  const player = TestHelpers.makePlayer({});
  const spinner = new LoadingSpinner(player);

  videojs.addLanguage('test', {'{1} is loading.': '{1} LOADING'});
  player.language('test');

  assert.equal(spinner.$('.vjs-control-text').textContent, 'Video Player LOADING', 'loading spinner text is localized');
});