/* * Copyright (C) 2026 - present Instructure, Inc. * * This file is part of Canvas. * * Canvas is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation, version 3 of the License. * * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License along * with this program. If not, see . */ import {interpolate} from '../interpolate' describe('interpolate', () => { it('returns the template unchanged when no values are given', () => { expect(interpolate('Remove {lang} closed captions')).toEqual('Remove {lang} closed captions') }) it('substitutes a named placeholder', () => { expect(interpolate('Remove {lang} closed captions', {lang: 'French'})).toEqual( 'Remove French closed captions', ) }) it('tolerates whitespace inside the braces', () => { expect(interpolate('Selected file: { name }', {name: 'caps.srt'})).toEqual( 'Selected file: caps.srt', ) }) it('substitutes multiple occurrences of the same placeholder', () => { expect(interpolate('{lang} and {lang} again', {lang: 'French'})).toEqual( 'French and French again', ) }) it('substitutes multiple distinct placeholders', () => { expect( interpolate('{captionName} caption upload failed for {lang}', { captionName: 'foo.vtt', lang: 'French', }), ).toEqual('foo.vtt caption upload failed for French') }) it('leaves a placeholder untouched when its value is missing', () => { expect(interpolate('Remove {lang} closed captions', {})).toEqual( 'Remove {lang} closed captions', ) }) it('coerces non-string values to strings', () => { expect( interpolate('The selected file exceeds the {maxSize} Byte limit', {maxSize: 500}), ).toEqual('The selected file exceeds the 500 Byte limit') }) })