rewrite i18n! to useScope in QUnit specs
refs FOO-2696 flag = none see the related patch for JavaScripts for context, this is the same but for typescripts also, specs that were stubbing/spying on I18n.Scope prototype methods had to be adjusted to reach out to the constructor since modules no longer share the same (dynamically generated) instance Change-Id: Ie0e4a2fcc97edb25f986c810a2196aa490341d7d Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/286751 Tested-by: James Butters <jbutters@instructure.com> Reviewed-by: Charley Kline <ckline@instructure.com> QA-Review: Charley Kline <ckline@instructure.com> Product-Review: Charley Kline <ckline@instructure.com>
This commit is contained in:
parent
bf46b5cc33
commit
6ea74a0d0a
|
@ -18,7 +18,7 @@
|
|||
|
||||
import Calendar from 'ui/features/calendar/jquery/index.js'
|
||||
import CalendarEvent from '@canvas/calendar/jquery/CommonEvent/CalendarEvent'
|
||||
import I18n from 'i18n!calendar'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
import fcUtil from '@canvas/calendar/jquery/fcUtil.coffee'
|
||||
import moment from 'moment'
|
||||
import tz from '@canvas/timezone'
|
||||
|
@ -30,6 +30,8 @@ import $ from 'jquery'
|
|||
import {subscribe} from 'jquery-tinypubsub'
|
||||
import fakeENV from 'helpers/fakeENV'
|
||||
|
||||
const I18n = useI18nScope('calendar');
|
||||
|
||||
QUnit.module('Calendar', {
|
||||
setup() {
|
||||
tzInTest.configureAndRestoreLater({
|
||||
|
@ -85,14 +87,14 @@ test('creates a fullcalendar instance', () => {
|
|||
|
||||
test('returns correct format for 24 hour times', () => {
|
||||
const cal = makeCal()
|
||||
const stub = sinon.stub(I18n, 'lookup').returns('%k:%M')
|
||||
const stub = sinon.stub(I18n.constructor.prototype, 'lookup').returns('%k:%M')
|
||||
strictEqual(cal.eventTimeFormat(), 'HH:mm')
|
||||
stub.restore()
|
||||
})
|
||||
|
||||
test('return correct format for non 24 hour times', () => {
|
||||
const cal = makeCal()
|
||||
const stub = sinon.stub(I18n, 'lookup').returns('whatever')
|
||||
const stub = sinon.stub(I18n.constructor.prototype, 'lookup').returns('whatever')
|
||||
strictEqual(cal.eventTimeFormat(), null)
|
||||
stub.restore()
|
||||
})
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
import {isEqual} from 'underscore'
|
||||
import Grid from '@canvas/outcome-gradebook-grid'
|
||||
import fakeENV from 'helpers/fakeENV'
|
||||
import 'i18n!gradebookOutcomeGradebookGrid'
|
||||
|
||||
QUnit.module('OutcomeGradebookGrid', {
|
||||
setup() {
|
||||
|
|
|
@ -21,7 +21,9 @@ import React from 'react'
|
|||
import ReactDOM from 'react-dom'
|
||||
import TestUtils from 'react-dom/test-utils'
|
||||
import DownloadLink from 'ui/features/epub_exports/react/DownloadLink.js'
|
||||
import I18n from 'i18n!epub_exports'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
|
||||
const I18n = useI18nScope('epub_exports');
|
||||
|
||||
QUnit.module('DownloadLink', {
|
||||
setup() {
|
||||
|
|
|
@ -23,7 +23,9 @@ import ReactDOM from 'react-dom'
|
|||
import TestUtils from 'react-dom/test-utils'
|
||||
import GenerateLink from 'ui/features/epub_exports/react/GenerateLink.js'
|
||||
import CourseEpubExportStore from 'ui/features/epub_exports/react/CourseStore.js'
|
||||
import I18n from 'i18n!epub_exports'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
|
||||
const I18n = useI18nScope('epub_exports');
|
||||
|
||||
QUnit.module('GenerateLink', {
|
||||
setup() {
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
*/
|
||||
|
||||
import Section from '@canvas/sections/backbone/models/Section.coffee'
|
||||
import I18n from 'i18n!modelsSection'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
|
||||
const I18n = useI18nScope('modelsSection');
|
||||
|
||||
QUnit.module('Section')
|
||||
|
||||
|
|
|
@ -20,9 +20,11 @@ import $ from 'jquery'
|
|||
import CurveGradesDialog from '@canvas/grading/jquery/CurveGradesDialog.coffee'
|
||||
import AsyncComponents from 'ui/features/gradebook/react/default_gradebook/AsyncComponents'
|
||||
import CurveGradesDialogManager from 'ui/features/gradebook/react/default_gradebook/CurveGradesDialogManager'
|
||||
import I18n from 'i18n!gradebook'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
import '@canvas/rails-flash-notifications'
|
||||
|
||||
const I18n = useI18nScope('gradebook');
|
||||
|
||||
const {createCurveGradesAction} = CurveGradesDialogManager
|
||||
|
||||
QUnit.module('CurveGradesDialogManager.createCurveGradesAction.isDisabled', {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import I18n from 'i18n!gradebook'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
import ReactDOM from 'react-dom'
|
||||
import {
|
||||
createGradebook,
|
||||
|
@ -25,6 +25,8 @@ import {
|
|||
import CustomColumnHeaderRenderer from 'ui/features/gradebook/react/default_gradebook/GradebookGrid/headers/CustomColumnHeaderRenderer'
|
||||
import {getCustomColumnId} from 'ui/features/gradebook/react/default_gradebook/Gradebook.utils'
|
||||
|
||||
const I18n = useI18nScope('gradebook');
|
||||
|
||||
QUnit.module('GradebookGrid CustomColumnHeaderRenderer', suiteHooks => {
|
||||
let $container
|
||||
let gradebook
|
||||
|
@ -75,7 +77,7 @@ QUnit.module('GradebookGrid CustomColumnHeaderRenderer', suiteHooks => {
|
|||
})
|
||||
|
||||
test('uses translated label for teacher notes', () => {
|
||||
sinon.stub(I18n, 't').withArgs('Notes').returns('Translated Notes')
|
||||
sinon.stub(I18n.constructor.prototype, 't').withArgs('Notes').returns('Translated Notes')
|
||||
render()
|
||||
equal(component.props.title, 'Translated Notes')
|
||||
I18n.t.restore()
|
||||
|
|
|
@ -16,21 +16,23 @@
|
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import I18n from 'i18n!sharedGradeFormatHelper'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
import numberHelper from '@canvas/i18n/numberHelper'
|
||||
import GradeFormatHelper from '@canvas/grading/GradeFormatHelper'
|
||||
|
||||
const I18n = useI18nScope('sharedGradeFormatHelper');
|
||||
|
||||
QUnit.module('GradeFormatHelper#formatGrade', {
|
||||
setup() {
|
||||
this.translateString = I18n.t
|
||||
sandbox.stub(numberHelper, 'validate').callsFake(val => !isNaN(parseFloat(val)))
|
||||
sandbox.stub(I18n, 't').callsFake(this.translateString)
|
||||
sandbox.stub(I18n.constructor.prototype, 't').callsFake(this.translateString)
|
||||
}
|
||||
})
|
||||
|
||||
test('uses I18n#n to format numerical integer grades', () => {
|
||||
sandbox
|
||||
.stub(I18n, 'n')
|
||||
.stub(I18n.constructor.prototype, 'n')
|
||||
.withArgs(1000)
|
||||
.returns('* 1,000')
|
||||
equal(GradeFormatHelper.formatGrade(1000), '* 1,000')
|
||||
|
@ -50,7 +52,7 @@ test('uses formatPointsOutOf to format points grade type', () => {
|
|||
|
||||
test('uses I18n#n to format numerical decimal grades', () => {
|
||||
sandbox
|
||||
.stub(I18n, 'n')
|
||||
.stub(I18n.constructor.prototype, 'n')
|
||||
.withArgs(123.45)
|
||||
.returns('* 123.45')
|
||||
equal(GradeFormatHelper.formatGrade(123.45), '* 123.45')
|
||||
|
@ -106,7 +108,7 @@ test('returns the given grade when it is numbers followed by letters', () => {
|
|||
})
|
||||
|
||||
test('does not format letter grades', () => {
|
||||
sandbox.spy(I18n, 'n')
|
||||
sandbox.spy(I18n.constructor.prototype, 'n')
|
||||
GradeFormatHelper.formatGrade('A')
|
||||
equal(I18n.n.callCount, 0, 'I18n.n was not called')
|
||||
})
|
||||
|
@ -136,7 +138,7 @@ test('returns the grade when given an empty string and no defaultValue option',
|
|||
})
|
||||
|
||||
test('formats numerical integer grades as percent when given a gradingType of "percent"', () => {
|
||||
sandbox.spy(I18n, 'n')
|
||||
sandbox.spy(I18n.constructor.prototype, 'n')
|
||||
GradeFormatHelper.formatGrade(10, {gradingType: 'percent'})
|
||||
const [value, options] = I18n.n.getCall(0).args
|
||||
strictEqual(value, 10)
|
||||
|
@ -144,7 +146,7 @@ test('formats numerical integer grades as percent when given a gradingType of "p
|
|||
})
|
||||
|
||||
test('formats numerical decimal grades as percent when given a gradingType of "percent"', () => {
|
||||
sandbox.spy(I18n, 'n')
|
||||
sandbox.spy(I18n.constructor.prototype, 'n')
|
||||
GradeFormatHelper.formatGrade(10.1, {gradingType: 'percent'})
|
||||
const [value, options] = I18n.n.getCall(0).args
|
||||
strictEqual(value, 10.1)
|
||||
|
@ -152,7 +154,7 @@ test('formats numerical decimal grades as percent when given a gradingType of "p
|
|||
})
|
||||
|
||||
test('formats string percentage grades as points when given a gradingType of "points"', () => {
|
||||
sandbox.spy(I18n, 'n')
|
||||
sandbox.spy(I18n.constructor.prototype, 'n')
|
||||
GradeFormatHelper.formatGrade('10%', {gradingType: 'points'})
|
||||
const [value, options] = I18n.n.getCall(0).args
|
||||
strictEqual(value, 10)
|
||||
|
@ -312,7 +314,7 @@ QUnit.module('GradeFormatHelper', suiteHooks => {
|
|||
|
||||
suiteHooks.beforeEach(() => {
|
||||
sinon.stub(numberHelper, 'validate').callsFake(val => !isNaN(parseFloat(val)))
|
||||
sinon.stub(I18n, 't').callsFake(translateString)
|
||||
sinon.stub(I18n.constructor.prototype, 't').callsFake(translateString)
|
||||
})
|
||||
|
||||
suiteHooks.afterEach(() => {
|
||||
|
|
|
@ -19,13 +19,15 @@
|
|||
import _ from 'lodash'
|
||||
|
||||
import $ from 'jquery'
|
||||
import I18n from 'i18n!gradingGradeSummary'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
import fakeENV from 'helpers/fakeENV'
|
||||
import numberHelper from '@canvas/i18n/numberHelper'
|
||||
import CourseGradeCalculator from '@canvas/grading/CourseGradeCalculator'
|
||||
import GradeSummary from 'ui/features/grade_summary/jquery/index.js'
|
||||
import {createCourseGradesWithGradingPeriods} from '../gradebook/GradeCalculatorSpecHelper'
|
||||
|
||||
const I18n = useI18nScope('gradingGradeSummary');
|
||||
|
||||
const $fixtures = $('#fixtures')
|
||||
|
||||
let exampleGrades
|
||||
|
@ -387,7 +389,7 @@ QUnit.module('GradeSummary.calculateTotals', suiteHooks => {
|
|||
})
|
||||
|
||||
test('localizes displayed grade', () => {
|
||||
sandbox.stub(I18n, 'n').returns('1,234')
|
||||
sandbox.stub(I18n.constructor.prototype, 'n').returns('1,234')
|
||||
GradeSummary.calculateTotals(createExampleGrades(), 'current', 'percent')
|
||||
const $teaser = $fixtures.find('.student_assignment.final_grade .score_teaser')
|
||||
ok($teaser.text().includes('1,234'), 'includes internationalized score')
|
||||
|
@ -569,7 +571,7 @@ QUnit.module('GradeSummary.formatPercentGrade')
|
|||
|
||||
test('returns an internationalized number value', () => {
|
||||
sandbox
|
||||
.stub(I18n, 'n')
|
||||
.stub(I18n.constructor.prototype, 'n')
|
||||
.withArgs(1234)
|
||||
.returns('1,234%')
|
||||
equal(GradeSummary.formatPercentGrade(1234), '1,234%')
|
||||
|
@ -578,7 +580,7 @@ test('returns an internationalized number value', () => {
|
|||
QUnit.module('GradeSummary.calculateGrade')
|
||||
|
||||
test('returns an internationalized percentage when given a score and nonzero points possible', () => {
|
||||
sandbox.stub(I18n, 'n').callsFake(number => `${number}%`)
|
||||
sandbox.stub(I18n.constructor.prototype, 'n').callsFake(number => `${number}%`)
|
||||
equal(GradeSummary.calculateGrade(97, 100), '97%')
|
||||
equal(I18n.n.getCall(0).args[1].percentage, true)
|
||||
})
|
||||
|
|
|
@ -16,12 +16,14 @@
|
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import I18n from 'i18n!shared.flash_notices'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
|
||||
import $ from 'jquery'
|
||||
import htmlEscape from 'html-escape'
|
||||
import NotificationsHelper from '@canvas/rails-flash-notifications/jquery/helper'
|
||||
|
||||
const I18n = useI18nScope('shared.flash_notices');
|
||||
|
||||
let helper
|
||||
let fixtures
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ import '@canvas/rails-flash-notifications'
|
|||
|
||||
import fakeENV from 'helpers/fakeENV'
|
||||
import rubric_assessment from '@canvas/rubrics/jquery/rubric_assessment'
|
||||
import I18n from 'i18n!rubric_assessment'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
|
||||
const I18n = useI18nScope('rubric_assessment');
|
||||
|
||||
QUnit.module('RubricAssessment#roundAndFormat')
|
||||
|
||||
|
@ -31,7 +33,7 @@ test('rounds given number to two decimal places', () => {
|
|||
})
|
||||
|
||||
test('formats given number with I18n.n', () => {
|
||||
sandbox.stub(I18n, 'n').returns('formatted_number')
|
||||
sandbox.stub(I18n.constructor.prototype, 'n').returns('formatted_number')
|
||||
strictEqual(rubric_assessment.roundAndFormat(42), 'formatted_number')
|
||||
strictEqual(I18n.n.callCount, 1)
|
||||
ok(I18n.n.calledWith(42))
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import I18n from 'i18n!calendar'
|
||||
import { useScope as useI18nScope } from '@canvas/i18n';
|
||||
import datePickerFormat from '@canvas/datetime/datePickerFormat'
|
||||
|
||||
const I18n = useI18nScope('calendar');
|
||||
|
||||
QUnit.module('Date Picker Format Spec')
|
||||
|
||||
test('formats medium with weekday correcly', () => {
|
||||
|
|
|
@ -427,4 +427,4 @@ if (I18n.translations) {
|
|||
}
|
||||
|
||||
export default I18n
|
||||
export const useScope = I18n.useScope
|
||||
export const useScope = I18n.useScope
|
||||
|
|
Loading…
Reference in New Issue