Skip to content

Commit

Permalink
colocate some QUnit tests
Browse files Browse the repository at this point in the history
Change-Id: If111507b32fbb46603537e13768ce14e32bf2860
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/349223
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Spencer Olson <solson@instructure.com>
QA-Review: Drake Harper <drake.harper@instructure.com>
Product-Review: Drake Harper <drake.harper@instructure.com>
  • Loading branch information
aaronshaf committed Jun 5, 2024
1 parent 7c308e3 commit dfb5cce
Show file tree
Hide file tree
Showing 63 changed files with 115 additions and 97 deletions.
31 changes: 31 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const {glob} = require('glob')
const path = require('path')

module.exports = {
Expand Down Expand Up @@ -258,6 +259,36 @@ module.exports = {
},
},
overrides: [
{
files: ['ui/**/*Spec.js', 'ui/**/*Spec.jsx'],
extends: ['plugin:qunit/recommended', 'plugin:qunit/two'],
plugins: ['qunit'],
globals: {
module: true,
test: true,
equal: true,
ok: true,
sandbox: true,
sinon: true,
deepEqual: true,
},
env: {
qunit: true,
},
rules: {
'func-names': 'off',
'prefer-arrow-callback': 'off',
'jest/no-identical-title': 'off',
'qunit/no-identical-names': 'off',
'qunit/no-setup-teardown': 'off',
'qunit/no-global-assertions': 'off',
'qunit/no-global-module-test': 'off',
'qunit/require-expect': 'off',
'qunit/no-assert-logical-expression': 'error',
'qunit/no-commented-tests': 'error',
'qunit/no-compare-relation-boolean': 'error',
},
},
{
files: require('./jest.config').testMatch,
plugins: ['jest'],
Expand Down
4 changes: 2 additions & 2 deletions jest/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import filterUselessConsoleMessages from '@instructure/filter-console-messages'
import rceFormatMessage from '@instructure/canvas-rce/es/format-message'
import {up as configureDateTime} from '../ui/boot/initializers/configureDateTime'
import {up as configureDateTimeMomentParser} from '../ui/boot/initializers/configureDateTimeMomentParser'
import {up as configureDateTime} from '@canvas/datetime/configureDateTime'
import {up as configureDateTimeMomentParser} from '@canvas/datetime/configureDateTimeMomentParser'
import {useTranslations} from '@canvas/i18n'
import MockBroadcastChannel from './MockBroadcastChannel'

Expand Down
2 changes: 1 addition & 1 deletion spec/coffeescripts/handlebars_helpersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import detroit from 'timezone/America/Detroit'
import chicago from 'timezone/America/Chicago'
import newYork from 'timezone/America/New_York'
import I18n from 'i18n-js'
import {getI18nFormats} from 'ui/boot/initializers/configureDateTime'
import {getI18nFormats} from '@canvas/datetime/configureDateTime'

const {helpers} = Handlebars
const {contains} = assertions
Expand Down
3 changes: 2 additions & 1 deletion spec/coffeescripts/helpers/I18nStubber.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-throw-literal */
/*
* Copyright (C) 2015 - present Instructure, Inc.
*
Expand All @@ -16,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import I18n, {useTranslations} from '@canvas/i18n'
import I18n from '@canvas/i18n'
import enTranslations from 'translations/en.json'

const frames = []
Expand Down
3 changes: 2 additions & 1 deletion spec/coffeescripts/instructureDateAndTimeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
timeString,
unfudgeDateForProfileTimezone,
} from '@canvas/datetime/date-functions'
import {getI18nFormats} from 'ui/boot/initializers/configureDateTime'
import {getI18nFormats} from '@canvas/datetime/configureDateTime'
import '@canvas/datetime/jquery/datepicker'

QUnit.module('fudgeDateForProfileTimezone', {
setup() {
Expand Down
2 changes: 1 addition & 1 deletion spec/coffeescripts/jsx/shared/helpers/dateHelperSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import timezone from 'timezone'
import detroit from 'timezone/America/Detroit'
import juneau from 'timezone/America/Juneau'
import tokyo from 'timezone/Asia/Tokyo'
import {getI18nFormats} from 'ui/boot/initializers/configureDateTime'
import {getI18nFormats} from '@canvas/datetime/configureDateTime'

const defaultAssignment = () => ({
title: 'assignment',
Expand Down
2 changes: 1 addition & 1 deletion spec/coffeescripts/views/SyllabusViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import SyllabusView from 'ui/features/syllabus/backbone/views/SyllabusView'
import SyllabusViewPrerendered from './SyllabusViewPrerendered'
import fakeENV from 'helpers/fakeENV'
import '@canvas/jquery/jquery.simulate'
import {getI18nFormats} from 'ui/boot/initializers/configureDateTime'
import {getI18nFormats} from '@canvas/datetime/configureDateTime'

function setupServerResponses() {
const server = sinon.fakeServer.create()
Expand Down
2 changes: 1 addition & 1 deletion spec/javascripts/jsx/moment_formatsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import I18nStubber from 'helpers/I18nStubber'
import {prepareFormats} from '../../../ui/boot/initializers/configureDateTimeMomentParser'
import {prepareFormats} from '@canvas/datetime/configureDateTimeMomentParser'

QUnit.module('Moment formats', {
setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import newYork from 'timezone/America/New_York'

import AssessmentSummary from 'ui/features/speed_grader/react/AssessmentAuditTray/components/AssessmentSummary'
import {overallAnonymityStates} from 'ui/features/speed_grader/react/AssessmentAuditTray/AuditTrailHelpers'
import {getI18nFormats} from 'ui/boot/initializers/configureDateTime'
import {getI18nFormats} from '@canvas/datetime/configureDateTime'

const {FULL, NA, PARTIAL} = overallAnonymityStates

Expand Down
4 changes: 2 additions & 2 deletions spec/javascripts/webpack_spec_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import en_US from 'timezone/en_US'
import './jsx/spec-support/specProtection'
import filterUselessConsoleMessages from '@instructure/filter-console-messages'
import './jsx/spec-support/timezoneBackwardsCompatLayer'
import {up as configureDateTime} from 'ui/boot/initializers/configureDateTime'
import {up as configureDateTimeMomentParser} from 'ui/boot/initializers/configureDateTimeMomentParser'
import {up as configureDateTime} from '@canvas/datetime/configureDateTime'
import {up as configureDateTimeMomentParser} from '@canvas/datetime/configureDateTimeMomentParser'
import {useTranslations} from '@canvas/i18n'
import CoreTranslations from 'translations/en.json'

Expand Down
4 changes: 2 additions & 2 deletions ui/boot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import filterUselessConsoleMessages from '../../packages/filter-console-messages
import moment from 'moment'
import './initializers/fakeRequireJSFallback'
import './initializers/ujsLinks'
import {up as configureDateTimeMomentParser} from './initializers/configureDateTimeMomentParser'
import {up as configureDateTime} from './initializers/configureDateTime'
import {up as configureDateTimeMomentParser} from '@canvas/datetime/configureDateTimeMomentParser'
import {up as configureDateTime} from '@canvas/datetime/configureDateTime'
import {initSentry} from './initializers/initSentry'
import {up as renderRailsFlashNotifications} from './initializers/renderRailsFlashNotifications'
import {up as activateCourseMenuToggler} from './initializers/activateCourseMenuToggler'
Expand Down
4 changes: 2 additions & 2 deletions ui/boot/initializers/__tests__/configureDateTime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import zh_CN from 'timezone/zh_CN'
import en_US from 'timezone/en_US'
import MockDate from 'mockdate'
import I18nStubber from '../../../../spec/coffeescripts/helpers/I18nStubber'
import {up as configureDateTime, down as resetDateTime} from '../configureDateTime'
import {up as configureDateTime, down as resetDateTime} from '@canvas/datetime/configureDateTime'
import {
up as configureDateTimeMomentParser,
down as resetDateTimeMomentParser,
} from '../configureDateTimeMomentParser'
} from '@canvas/datetime/configureDateTimeMomentParser'

const equal = (a, b, _message) => expect(a).toEqual(b)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import '../../../ext/custom_moment_locales/hy_am'
import '../../../ext/custom_moment_locales/sl'

import {parse, format, hasMeridiem, dateString} from '@instructure/moment-utils'
import * as configureDateTime from '../configureDateTime'
import * as configureDateTimeMomentParser from '../configureDateTimeMomentParser'
import * as configureDateTime from '@canvas/datetime/configureDateTime'
import * as configureDateTimeMomentParser from '@canvas/datetime/configureDateTimeMomentParser'
// eslint-disable-next-line import/no-nodejs-modules
import fs from 'fs'
import I18n, {useTranslations} from '@canvas/i18n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ReactDOM from 'react-dom'
import {Simulate} from 'react-dom/test-utils'
import axios from '@canvas/axios'
import {defaults} from 'lodash'
import GradingPeriod from 'ui/features/account_grading_standards/react/AccountGradingPeriod'
import GradingPeriod from '../AccountGradingPeriod'

const wrapper = document.getElementById('fixtures')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import React from 'react'
import ReactDOM from 'react-dom'
import {Simulate} from 'react-dom/test-utils'
import _ from 'lodash'
import GradingPeriodSetForm from 'ui/features/account_grading_standards/react/EditGradingPeriodSetForm'
import GradingPeriodSetForm from '../EditGradingPeriodSetForm'

const wrapper = document.getElementById('fixtures')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
*/

import React from 'react'

import ReactDOM from 'react-dom'
import {findRenderedDOMComponentWithClass} from 'react-dom/test-utils'
import {defaults, map} from 'lodash'
import Input from 'ui/features/account_grading_standards/react/EnrollmentTermInput'
import Input from '../EnrollmentTermInput'

const wrapper = document.getElementById('fixtures')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import React from 'react'
import ReactDOM from 'react-dom'
import {Simulate} from 'react-dom/test-utils'
import _ from 'lodash'
import Dropdown from 'ui/features/account_grading_standards/react/EnrollmentTermsDropdown'
import Dropdown from '../EnrollmentTermsDropdown'

const wrapper = document.getElementById('fixtures')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as tz from '@instructure/moment-utils'
import tzInTest from '@instructure/moment-utils/specHelpers'
import timezone from 'timezone'
import GradingPeriodForm from '../GradingPeriodForm'
import {getI18nFormats} from '../../../../boot/initializers/configureDateTime'
import {getI18nFormats} from '@canvas/datetime/configureDateTime'

const onSave = jest.fn()
const onCancel = jest.fn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import React from 'react'
import ReactDOM from 'react-dom'
import {Simulate, findRenderedDOMComponentWithTag} from 'react-dom/test-utils'
import gradingPeriodSetsApi from '@canvas/grading/jquery/gradingPeriodSetsApi'
import enrollmentTermsApi from 'ui/features/account_grading_standards/enrollmentTermsApi'
import GradingPeriodSetCollection from 'ui/features/account_grading_standards/react/GradingPeriodSetCollection'
import enrollmentTermsApi from '../../enrollmentTermsApi'
import GradingPeriodSetCollection from '../GradingPeriodSetCollection'

const wrapper = document.getElementById('fixtures')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ReactDOM from 'react-dom'
import {Simulate} from 'react-dom/test-utils'
import _ from 'lodash'
import axios from '@canvas/axios'
import GradingPeriodSet from 'ui/features/account_grading_standards/react/GradingPeriodSet'
import GradingPeriodSet from '../GradingPeriodSet'
import gradingPeriodsApi from '@canvas/grading/jquery/gradingPeriodsApi'

const wrapper = document.getElementById('fixtures')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ReactDOM from 'react-dom'
import {Simulate} from 'react-dom/test-utils'
import {defaults} from 'lodash'
import setsApi from '@canvas/grading/jquery/gradingPeriodSetsApi'
import NewSetForm from 'ui/features/account_grading_standards/react/NewGradingPeriodSetForm'
import NewSetForm from '../NewGradingPeriodSetForm'
import * as FlashAlert from '@canvas/alerts/react/FlashAlert'

const wrapper = document.getElementById('fixtures')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import React from 'react'

import ReactDOM from 'react-dom'
import {Simulate} from 'react-dom/test-utils'
import SearchGradingPeriodsField from 'ui/features/account_grading_standards/react/SearchGradingPeriodsField'
import SearchGradingPeriodsField from '../SearchGradingPeriodsField'

const wrapper = document.getElementById('fixtures')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import CommonEvent from '@canvas/calendar/jquery/CommonEvent/CommonEvent'
import commonEventFactory from '@canvas/calendar/jquery/CommonEvent/index'
import CalendarEventFilter from 'ui/features/calendar/CalendarEventFilter'
import CalendarEventFilter from '../CalendarEventFilter'
import fakeENV from 'helpers/fakeENV'

const test_events = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable qunit/assert-args */
/* eslint-disable qunit/no-ok-equality */

/*
* Copyright (C) 2013 - present Instructure, Inc.
*
Expand All @@ -19,6 +16,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* eslint-disable qunit/assert-args */
/* eslint-disable qunit/no-ok-equality */

import $ from 'jquery'
import 'jquery-migrate'
import {isArray, isObject, uniq} from 'lodash'
Expand All @@ -28,7 +28,7 @@ import fcUtil from '@canvas/calendar/jquery/fcUtil'
import denver from 'timezone/America/Denver'
import juneau from 'timezone/America/Juneau'
import french from 'timezone/fr_FR'
import AgendaView from 'ui/features/calendar/backbone/views/AgendaView'
import AgendaView from '../AgendaView'
import EventDataSource from '@canvas/calendar/jquery/EventDataSource'
import eventResponse from 'helpers/ajax_mocks/api/v1/calendarEvents'
import plannerItemsResponse from 'helpers/ajax_mocks/api/planner/items'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

import $ from 'jquery'
import 'jquery-migrate'
import EditAssignmentDetails from 'ui/features/calendar/backbone/views/EditAssignmentDetails'
import EditAssignmentDetails from '../EditAssignmentDetails'
import fcUtil from '@canvas/calendar/jquery/fcUtil'
import timezone from 'timezone'
import tzInTest from '@instructure/moment-utils/specHelpers'
import detroit from 'timezone/America/Detroit'
import french from 'timezone/fr_FR'
import fakeENV from 'helpers/fakeENV'
import commonEventFactory from '@canvas/calendar/jquery/CommonEvent/index'
import {getI18nFormats} from 'ui/boot/initializers/configureDateTime'
import {getI18nFormats} from '@canvas/datetime/configureDateTime'

const fixtures = $('#fixtures')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import $ from 'jquery'
import 'jquery-migrate'
import EditPlannerNoteDetails from 'ui/features/calendar/backbone/views/EditPlannerNoteDetails'
import EditPlannerNoteDetails from '../EditPlannerNoteDetails'
import tzInTest from '@instructure/moment-utils/specHelpers'
import fakeENV from 'helpers/fakeENV'
import commonEventFactory from '@canvas/calendar/jquery/CommonEvent/index'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import Calendar from 'ui/features/calendar/jquery/index'
import Calendar from '../index'
import CalendarEvent from '@canvas/calendar/jquery/CommonEvent/CalendarEvent'
import {useScope as useI18nScope} from '@canvas/i18n'
import fcUtil from '@canvas/calendar/jquery/fcUtil'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import $ from 'jquery'
import 'jquery-migrate'
import EditAppointmentGroupDetails from 'ui/features/calendar/jquery/EditAppointmentGroupDetails'
import EditAppointmentGroupDetails from '../EditAppointmentGroupDetails'
import fcUtil from '@canvas/calendar/jquery/fcUtil'
import * as tz from '@instructure/moment-utils'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import $ from 'jquery'
import 'jquery-migrate'
import TimeBlockList from 'ui/features/calendar/jquery/TimeBlockList'
import moment from 'moment'
import TimeBlockList from '../TimeBlockList'
import fcUtil from '@canvas/calendar/jquery/fcUtil'

QUnit.module('TimeBlockList', {
Expand Down Expand Up @@ -103,7 +102,6 @@ test('should not validate if a row is incomplete', function () {
})

test('should still validate if a row is fully blank', function () {
const row = this.me.addRow()
ok(this.me.validate(), 'should validate')
})

Expand All @@ -124,8 +122,6 @@ test('should split correctly', function () {

QUnit.module('TimeBlockList with no time blocks', {
setup() {
const wrappedDate = str => moment(new Date(str))

this.$holder = $('<table>').appendTo('#fixtures')
this.$splitter = $('<a>').appendTo('#fixtures')
this.blocks = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import $ from 'jquery'
import 'jquery-migrate'
import fcUtil from '@canvas/calendar/jquery/fcUtil'
import TimeBlockList from 'ui/features/calendar/jquery/TimeBlockList'
import TimeBlockRow from 'ui/features/calendar/jquery/TimeBlockRow'
import TimeBlockList from '../TimeBlockList'
import TimeBlockRow from '../TimeBlockRow'
import * as tz from '@instructure/moment-utils'
import tzInTest from '@instructure/moment-utils/specHelpers'
import timezone from 'timezone'
import detroit from 'timezone/America/Detroit'
import {getI18nFormats} from 'ui/boot/initializers/configureDateTime'
import {getI18nFormats} from '@canvas/datetime/configureDateTime'

const nextYear = new Date().getFullYear() + 1
const unfudged_start = tz.parse(`${nextYear}-02-03T12:32:00Z`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import tz from 'timezone'
import chicago from 'timezone/America/Chicago'
import detroit from 'timezone/America/Detroit'
import tzInTest from '@instructure/moment-utils/specHelpers'
import {getI18nFormats} from '../../../../../../boot/initializers/configureDateTime'
import {getI18nFormats} from '@canvas/datetime/configureDateTime'

const observerEnrollment = {
id: '1',
Expand Down
Loading

0 comments on commit dfb5cce

Please sign in to comment.