Best Python code snippet using fMBT_python
AssignmentRowCellPropFactorySpec.js
Source:AssignmentRowCellPropFactorySpec.js
1/*2 * Copyright (C) 2017 - present Instructure, Inc.3 *4 * This file is part of Canvas.5 *6 * Canvas is free software: you can redistribute it and/or modify it under7 * the terms of the GNU Affero General Public License as published by the Free8 * Software Foundation, version 3 of the License.9 *10 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR12 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more13 * details.14 *15 * You should have received a copy of the GNU Affero General Public License along16 * with this program. If not, see <http://www.gnu.org/licenses/>.17 */18import AssignmentRowCellPropFactory from 'jsx/gradebook/default_gradebook/GradebookGrid/editors/AssignmentCellEditor/AssignmentRowCellPropFactory'19import {20 createGradebook,21 setFixtureHtml22} from 'jsx/gradebook/default_gradebook/__tests__/GradebookSpecHelper'23QUnit.module('GradebookGrid AssignmentRowCellPropFactory', () => {24 let $container25 let gradebook26 QUnit.module('#getProps()', hooks => {27 let editorOptions28 function getProps() {29 const factory = new AssignmentRowCellPropFactory(gradebook)30 return factory.getProps(editorOptions)31 }32 hooks.beforeEach(() => {33 $container = document.body.appendChild(document.createElement('div'))34 setFixtureHtml($container)35 gradebook = createGradebook({context_id: '1201'})36 gradebook.gradebookGrid.gridSupport = {37 helper: {38 commitCurrentEdit() {},39 focus() {}40 }41 }42 gradebook.students['1101'] = {id: '1101', isConcluded: false}43 gradebook.setAssignments({44 2301: {grading_type: 'points', id: '2301', points_possible: 10}45 })46 gradebook.updateSubmission({47 assignment_id: '2301',48 entered_grade: '7.8',49 entered_score: 7.8,50 excused: false,51 grade: '6.8',52 id: '2501',53 score: 6.8,54 user_id: '1101'55 })56 editorOptions = {57 column: {58 assignmentId: '2301'59 },60 item: {id: '1101'}61 }62 sinon.stub(gradebook, 'updateRowAndRenderSubmissionTray') // no rendering needed for these tests63 })64 hooks.afterEach(() => {65 gradebook.destroy()66 $container.remove()67 })68 test('.assignment.id is the id on the assignment', () => {69 equal(getProps().assignment.id, '2301')70 })71 test('.assignment.pointsPossible is the points possible on the assignment', () => {72 strictEqual(getProps().assignment.pointsPossible, 10)73 })74 test('.enterGradesAs is the "enter grades as" setting for the assignment', () => {75 gradebook.setEnterGradesAsSetting('2301', 'percent')76 equal(getProps().enterGradesAs, 'percent')77 })78 test('.gradeIsEditable is true when the grade for the submission is editable', () => {79 sinon80 .stub(gradebook, 'isGradeEditable')81 .withArgs('1101', '2301')82 .returns(true)83 strictEqual(getProps().gradeIsEditable, true)84 })85 test('.gradeIsEditable is false when the grade for the submission is not editable', () => {86 sinon87 .stub(gradebook, 'isGradeEditable')88 .withArgs('1101', '2301')89 .returns(false)90 strictEqual(getProps().gradeIsEditable, false)91 })92 test('.gradeIsVisible is true when the grade for the submission is visible', () => {93 sinon94 .stub(gradebook, 'isGradeVisible')95 .withArgs('1101', '2301')96 .returns(true)97 strictEqual(getProps().gradeIsVisible, true)98 })99 test('.gradeIsVisible is false when the grade for the submission is not visible', () => {100 sinon101 .stub(gradebook, 'isGradeVisible')102 .withArgs('1101', '2301')103 .returns(false)104 strictEqual(getProps().gradeIsVisible, false)105 })106 test('.gradingScheme is the grading scheme for the assignment', () => {107 const gradingScheme = {108 id: '2801',109 data: [110 ['ð', 0.9],111 ['ð', 0.8],112 ['ð', 0.7],113 ['ð¢', 0.6],114 ['ð©', 0]115 ],116 title: 'Emoji Grades'117 }118 gradebook.getAssignment('2301').grading_standard_id = '2801'119 gradebook.courseContent.gradingSchemes = [gradingScheme]120 deepEqual(getProps().gradingScheme, gradingScheme.data)121 })122 test('.isSubmissionTrayOpen is true when the tray is open for the current student and assignment', () => {123 gradebook.setSubmissionTrayState(true, '1101', '2301')124 strictEqual(getProps().isSubmissionTrayOpen, true)125 })126 test('.isSubmissionTrayOpen is false when the tray is closed', () => {127 gradebook.setSubmissionTrayState(false, '1101', '2301')128 strictEqual(getProps().isSubmissionTrayOpen, false)129 })130 test('.isSubmissionTrayOpen is true when the tray is open for a different student', () => {131 gradebook.setSubmissionTrayState(true, '1102', '2301')132 strictEqual(getProps().isSubmissionTrayOpen, false)133 })134 test('.isSubmissionTrayOpen is true when the tray is open for a different assignment', () => {135 gradebook.setSubmissionTrayState(true, '1101', '2302')136 strictEqual(getProps().isSubmissionTrayOpen, false)137 })138 test('.onGradeSubmission is the .gradeSubmission Gradebook method', () => {139 strictEqual(getProps().onGradeSubmission, gradebook.gradeSubmission)140 })141 test('.onToggleSubmissionTrayOpen toggles the tray', () => {142 getProps().onToggleSubmissionTrayOpen()143 strictEqual(gradebook.getSubmissionTrayState().open, true)144 })145 test('.onToggleSubmissionTrayOpen toggles the tray using .toggleSubmissionTrayOpen', () => {146 sinon.stub(gradebook, 'toggleSubmissionTrayOpen')147 getProps().onToggleSubmissionTrayOpen()148 strictEqual(gradebook.toggleSubmissionTrayOpen.callCount, 1)149 })150 test('.onToggleSubmissionTrayOpen toggles the tray for the current student', () => {151 getProps().onToggleSubmissionTrayOpen()152 strictEqual(gradebook.getSubmissionTrayState().studentId, '1101')153 })154 test('.onToggleSubmissionTrayOpen toggles the tray for the current assignment', () => {155 getProps().onToggleSubmissionTrayOpen()156 strictEqual(gradebook.getSubmissionTrayState().assignmentId, '2301')157 })158 test('.pendingGradeInfo is included when a valid pending grade exists', () => {159 const pendingGradeInfo = {160 enteredAs: 'points',161 excused: false,162 grade: 'A',163 score: 10,164 valid: true165 }166 gradebook.addPendingGradeInfo({assignmentId: '2301', userId: '1101'}, pendingGradeInfo)167 deepEqual(getProps().pendingGradeInfo, {168 ...pendingGradeInfo,169 assignmentId: '2301',170 userId: '1101'171 })172 })173 test('.pendingGradeInfo is null when no pending grade exists', () => {174 strictEqual(getProps().pendingGradeInfo, null)175 })176 test('.student is the student associated with the row of the cell', () => {177 deepEqual(getProps().student, gradebook.students['1101'])178 })179 test('.submission.assignmentId is the assignment id', () => {180 strictEqual(getProps().submission.assignmentId, '2301')181 })182 test('.submission.enteredGrade is the entered grade on the submission', () => {183 strictEqual(getProps().submission.enteredGrade, '7.8')184 })185 test('.submission.enteredScore is the entered score on the submission', () => {186 strictEqual(getProps().submission.enteredScore, 7.8)187 })188 test('.submission.excused is true when the submission is excused', () => {189 gradebook.getSubmission('1101', '2301').excused = true190 strictEqual(getProps().submission.excused, true)191 })192 test('.submission.excused is false when the value is undefined on the submission', () => {193 gradebook.getSubmission('1101', '2301').excused = undefined194 strictEqual(getProps().submission.excused, false)195 })196 test('.submission.grade is the final grade on the submission', () => {197 strictEqual(getProps().submission.grade, '6.8')198 })199 test('.submission.id is the submission id', () => {200 strictEqual(getProps().submission.id, '2501')201 })202 test('.submission.rawGrade is the raw grade on the submission', () => {203 strictEqual(getProps().submission.rawGrade, '6.8')204 })205 test('.submission.score is the final score on the submission', () => {206 strictEqual(getProps().submission.score, 6.8)207 })208 test('.submission.userId is the student id', () => {209 strictEqual(getProps().submission.userId, '1101')210 })211 QUnit.module('.submission.similarityInfo', () => {212 test('is null when not showing similarity scores in Gradebook', () => {213 strictEqual(getProps().submission.similarityInfo, null)214 })215 QUnit.module('when showing similarity scores in Gradebook', showSimilarityScoreHooks => {216 showSimilarityScoreHooks.beforeEach(() => {217 sinon.stub(gradebook, 'showSimilarityScore').returns(true)218 })219 showSimilarityScoreHooks.afterEach(() => {220 gradebook.showSimilarityScore.restore()221 })222 test('is null when the submission has no similarity data', () => {223 strictEqual(getProps().submission.similarityInfo, null)224 })225 test('is set to the first entry returned by extractSimilarityInfo if data is present', () => {226 const submission = {227 assignment_id: '2301',228 entered_grade: '7.8',229 entered_score: 7.8,230 excused: false,231 grade: '6.8',232 id: '2501',233 score: 6.8,234 submission_type: 'online_text_entry',235 turnitin_data: {236 submission_2501: {status: 'scored', similarity_score: 75}237 },238 user_id: '1101'239 }240 sinon.stub(gradebook, 'getSubmission').returns(submission)241 deepEqual(getProps().submission.similarityInfo, {status: 'scored', similarityScore: 75})242 gradebook.getSubmission.restore()243 })244 })245 })246 test('.submissionIsUpdating is true when a valid pending grade exists', () => {247 gradebook.addPendingGradeInfo(248 {assignmentId: '2301', userId: '1101'},249 {enteredAs: 'points', excused: false, grade: 'A', score: 10, valid: true}250 )251 strictEqual(getProps().submissionIsUpdating, true)252 })253 test('.submissionIsUpdating is false when an invalid pending grade exists', () => {254 gradebook.addPendingGradeInfo(255 {assignmentId: '2301', userId: '1101'},256 {enteredAs: null, excused: false, grade: null, score: null, valid: false}257 )258 strictEqual(getProps().submissionIsUpdating, false)259 })260 test('.submissionIsUpdating is false when no pending grade exists', () => {261 strictEqual(getProps().submissionIsUpdating, false)262 })263 })...
SimpleSchema2Bridge.js
Source:SimpleSchema2Bridge.js
1import SimpleSchema from 'simpl-schema';2import SimpleSchema2Bridge from 'uniforms/SimpleSchema2Bridge';3describe('SimpleSchema2Bridge', () => {4 const noop = () => {};5 const schema = new SimpleSchema({6 'a': {type: Object},7 'a.b': {type: Object},8 'a.b.c': {type: String},9 'd': {type: String, defaultValue: 'D'},10 'e': {type: String, allowedValues: ['E']},11 'f': {type: Number, min: 42},12 'g': {type: Number, max: 42},13 'h': {type: Number},14 'i': {type: Date},15 'j': {type: Array, minCount: 3},16 'j.$': {type: String},17 'k': {type: Array},18 'k.$': {type: String},19 'l': {type: String, uniforms: 'div'},20 'm': {type: String, uniforms: noop},21 'n': {type: String, uniforms: {component: 'div'}},22 'o': {type: Array},23 'o.$': {type: String, allowedValues: ['O']},24 'p': {type: Array},25 'p.$': {type: String, uniforms: {transform: noop}},26 'r': {type: String, uniforms: {options: {a: 1, b: 2}}},27 's': {type: String, uniforms: {options: [{label: 1, value: 'a'}, {label: 2, value: 'b'}]}},28 't': {type: String, uniforms: {options: () => ({a: 1, b: 2})}},29 'u': {type: SimpleSchema.Integer},30 'w': {type: new SimpleSchema({x: String})},31 'x': {type: String, autoValue: () => '$setOnInsert:hack!'}32 });33 const bridge = new SimpleSchema2Bridge(schema);34 describe('#check()', () => {35 it('works correctly with schema', () => {36 expect(SimpleSchema2Bridge.check(schema)).toBeTruthy();37 });38 it('works correctly without schema', () => {39 expect(SimpleSchema2Bridge.check()).not.toBeTruthy();40 });41 Object.keys(schema).forEach(method => {42 it(`works correctly without '${method}'`, () => {43 expect(SimpleSchema2Bridge.check({...schema, [method]: null})).not.toBeTruthy();44 });45 });46 });47 describe('#getError', () => {48 it('works without error', () => {49 expect(bridge.getError('a')).toBe(null);50 });51 it('works with invalid error', () => {52 expect(bridge.getError('a', {})).toBe(null);53 expect(bridge.getError('a', {invalid: true})).toBe(null);54 });55 it('works with correct error', () => {56 expect(bridge.getError('a', {details: [{name: 'a'}]})).toEqual({name: 'a'});57 expect(bridge.getError('a', {details: [{name: 'b'}]})).toBe(null);58 });59 });60 describe('#getErrorMessage', () => {61 it('works without error', () => {62 expect(bridge.getErrorMessage('a')).toBe('');63 });64 it('works with invalid error', () => {65 expect(bridge.getErrorMessage('a', {})).toBe('');66 expect(bridge.getErrorMessage('a', {invalid: true})).toBe('');67 });68 it('works with correct error', () => {69 expect(bridge.getErrorMessage('a', {details: [{name: 'a', details: {value: 1}}]})).toBe('a is invalid');70 expect(bridge.getErrorMessage('a', {details: [{name: 'b', details: {value: 1}}]})).toBe('');71 });72 });73 describe('#getErrorMessages', () => {74 it('works without error', () => {75 expect(bridge.getErrorMessages()).toEqual([]);76 });77 it('works with other errors', () => {78 expect(bridge.getErrorMessages('correct')).toEqual(['correct']);79 expect(bridge.getErrorMessages(999999999)).toEqual([999999999]);80 });81 it('works with Error', () => {82 expect(bridge.getErrorMessages(new Error('correct'))).toEqual(['correct']);83 });84 it('works with ValidationError', () => {85 expect(bridge.getErrorMessages({details: [{name: 'a', details: {value: 1}}]})).toEqual(['a is invalid']);86 expect(bridge.getErrorMessages({details: [{name: 'b', details: {value: 1}}]})).toEqual(['b is invalid']);87 });88 });89 describe('#getField', () => {90 it('return correct definition', () => {91 const definition = schema.getDefinition('a');92 const definitionComposed = {...definition, ...definition.type[0]};93 expect(bridge.getField('a')).toEqual(definitionComposed);94 });95 it('return correct definition (`autoValue` hack)', () => {96 const definition = schema.getDefinition('x');97 const definitionComposed = {...definition, ...definition.type[0], defaultValue: '$setOnInsert:hack!'};98 expect(bridge.getField('x')).toEqual(definitionComposed);99 });100 it('throws on not found field', () => {101 expect(() => bridge.getField('y')).toThrow(/Field not found in schema/);102 });103 });104 describe('#getInitialValue', () => {105 it('works with arrays', () => {106 expect(bridge.getInitialValue('k')).toEqual([]);107 expect(bridge.getInitialValue('k', {initialCount: 1})).toEqual([undefined]);108 });109 it('works with objects', () => {110 expect(bridge.getInitialValue('a')).toEqual({});111 });112 });113 describe('#getProps', () => {114 it('works with allowedValues', () => {115 expect(bridge.getProps('o')).toEqual({label: 'O', required: true, allowedValues: ['O']});116 });117 it('works with allowedValues from props', () => {118 expect(bridge.getProps('o', {allowedValues: ['O']})).toEqual({label: 'O', required: true});119 });120 it('works with custom component', () => {121 expect(bridge.getProps('l')).toEqual({label: 'L', required: true, component: 'div'});122 expect(bridge.getProps('m')).toEqual({label: 'M', required: true, component: noop});123 });124 it('works with custom component (field)', () => {125 expect(bridge.getProps('n')).toEqual({label: 'N', required: true, component: 'div'});126 });127 it('works with Number type', () => {128 expect(bridge.getProps('h')).toEqual({label: 'H', required: true, decimal: true});129 });130 it('works with options (array)', () => {131 expect(bridge.getProps('s').transform('a')).toBe(1);132 expect(bridge.getProps('s').transform('b')).toBe(2);133 expect(bridge.getProps('s').allowedValues[0]).toBe('a');134 expect(bridge.getProps('s').allowedValues[1]).toBe('b');135 });136 it('works with options (function)', () => {137 expect(bridge.getProps('t').transform('a')).toBe(1);138 expect(bridge.getProps('t').transform('b')).toBe(2);139 expect(bridge.getProps('t').allowedValues[0]).toBe('a');140 expect(bridge.getProps('t').allowedValues[1]).toBe('b');141 });142 it('works with options (object)', () => {143 expect(bridge.getProps('r').transform('a')).toBe(1);144 expect(bridge.getProps('r').transform('b')).toBe(2);145 expect(bridge.getProps('r').allowedValues[0]).toBe('a');146 expect(bridge.getProps('r').allowedValues[1]).toBe('b');147 });148 it('works with options from props', () => {149 expect(bridge.getProps('s', {options: {c: 1, d: 2}}).transform('c')).toBe(1);150 expect(bridge.getProps('s', {options: {c: 1, d: 2}}).transform('d')).toBe(2);151 expect(bridge.getProps('s', {options: {c: 1, d: 2}}).allowedValues[0]).toBe('c');152 expect(bridge.getProps('s', {options: {c: 1, d: 2}}).allowedValues[1]).toBe('d');153 });154 it('works with transform', () => {155 expect(bridge.getProps('p')).toEqual({label: 'P', required: true, transform: noop});156 });157 it('works with transform from props', () => {158 expect(bridge.getProps('p', {transform: () => {}})).toEqual({label: 'P', required: true});159 });160 });161 describe('#getSubfields', () => {162 it('works on top level', () => {163 expect(bridge.getSubfields()).toEqual([164 'a',165 'd',166 'e',167 'f',168 'g',169 'h',170 'i',171 'j',172 'k',173 'l',174 'm',175 'n',176 'o',177 'p',178 'r',179 's',180 't',181 'u',182 'w',183 'x'184 ]);185 });186 it('works with nested schemas', () => {187 expect(bridge.getSubfields('w')).toEqual(['x']);188 });189 it('works with objects', () => {190 expect(bridge.getSubfields('a')).toEqual(['b']);191 expect(bridge.getSubfields('a.b')).toEqual(['c']);192 });193 it('works with primitives', () => {194 expect(bridge.getSubfields('d')).toEqual([]);195 expect(bridge.getSubfields('e')).toEqual([]);196 });197 });198 describe('#getType', () => {199 it('works with any type', () => {200 expect(bridge.getType('a')).toBe(Object);201 expect(bridge.getType('j')).toBe(Array);202 expect(bridge.getType('d')).toBe(String);203 expect(bridge.getType('f')).toBe(Number);204 expect(bridge.getType('i')).toBe(Date);205 expect(bridge.getType('u')).toBe(Number);206 expect(bridge.getType('w')).toBe(Object);207 });208 });209 describe('#getValidator', () => {210 it('calls correct validator', () => {211 expect(() => bridge.getValidator()({})).toThrow();212 expect(() => bridge.getValidator({})({})).toThrow();213 });214 });...
SimpleSchemaBridge.js
Source:SimpleSchemaBridge.js
1import SimpleSchemaBridge from 'uniforms/SimpleSchemaBridge';2jest.mock('meteor/aldeed:simple-schema');3jest.mock('meteor/check');4describe('SimpleSchemaBridge', () => {5 const noop = () => {};6 const schema = {7 getDefinition (name) {8 // Simulate SimpleSchema.9 name = name.replace(/\d+/g, '$');10 const field = {11 'a': {type: Object, label: name},12 'a.b': {type: Object, label: name},13 'a.b.c': {type: String, label: name},14 'd': {type: String, defaultValue: 'D'},15 'e': {type: String, allowedValues: ['E']},16 'f': {type: Number, min: 42},17 'g': {type: Number, max: 42},18 'h': {type: Number},19 'i': {type: Date},20 'j': {type: Array, minCount: 1},21 'j.$': {type: String},22 'k': {type: Array},23 'k.$': {type: String},24 'l': {type: String, uniforms: 'div'},25 'm': {type: String, uniforms: noop},26 'n': {type: String, uniforms: {component: 'div'}},27 'o': {type: Array},28 'o.$': {type: String, allowedValues: ['O']},29 'p': {type: Array},30 'p.$': {type: String, uniforms: {transform: noop}},31 'r': {type: String, uniforms: {options: {a: 1, b: 2}}},32 's': {type: String, uniforms: {options: [{label: 1, value: 'a'}, {label: 2, value: 'b'}]}},33 't': {type: String, uniforms: {options: () => ({a: 1, b: 2})}}34 }[name];35 if (field) {36 return {label: name.split('.').join(' ').toUpperCase(), ...field};37 }38 return undefined;39 },40 messageForError (type, name) {41 return `(${name})`;42 },43 objectKeys (name) {44 return {45 'a': ['b'],46 'a.b': ['c']47 }[name] || [];48 },49 validator () {50 throw 'ValidationError';51 }52 };53 const bridge = new SimpleSchemaBridge(schema);54 describe('#check()', () => {55 it('works correctly with schema', () => {56 expect(SimpleSchemaBridge.check(schema)).toBeTruthy();57 });58 it('works correctly without schema', () => {59 expect(SimpleSchemaBridge.check()).not.toBeTruthy();60 });61 Object.keys(schema).forEach(method => {62 it(`works correctly without '${method}'`, () => {63 expect(SimpleSchemaBridge.check({...schema, [method]: null})).not.toBeTruthy();64 });65 });66 });67 describe('#getError', () => {68 it('works without error', () => {69 expect(bridge.getError('a')).toBe(null);70 });71 it('works with invalid error', () => {72 expect(bridge.getError('a', {})).toBe(null);73 expect(bridge.getError('a', {invalid: true})).toBe(null);74 });75 it('works with correct error', () => {76 expect(bridge.getError('a', {details: [{name: 'a'}]})).toEqual({name: 'a'});77 expect(bridge.getError('a', {details: [{name: 'b'}]})).toBe(null);78 });79 });80 describe('#getErrorMessage', () => {81 it('works without error', () => {82 expect(bridge.getErrorMessage('a')).toBe('');83 });84 it('works with invalid error', () => {85 expect(bridge.getErrorMessage('a', {})).toBe('');86 expect(bridge.getErrorMessage('a', {invalid: true})).toBe('');87 });88 it('works with correct error', () => {89 expect(bridge.getErrorMessage('a', {details: [{name: 'a', details: {value: 1}}]})).toBe('(a)');90 expect(bridge.getErrorMessage('a', {details: [{name: 'b', details: {value: 1}}]})).toBe('');91 });92 });93 describe('#getErrorMessages', () => {94 it('works without error', () => {95 expect(bridge.getErrorMessages()).toEqual([]);96 });97 it('works with other errors', () => {98 expect(bridge.getErrorMessages('correct')).toEqual(['correct']);99 expect(bridge.getErrorMessages(999999999)).toEqual([999999999]);100 });101 it('works with Error', () => {102 expect(bridge.getErrorMessages(new Error('correct'))).toEqual(['correct']);103 });104 it('works with ValidationError', () => {105 expect(bridge.getErrorMessages({details: [{name: 'a', details: {value: 1}}]})).toEqual(['(a)']);106 expect(bridge.getErrorMessages({details: [{name: 'b', details: {value: 1}}]})).toEqual(['(b)']);107 });108 });109 describe('#getField', () => {110 it('return correct definition', () => {111 expect(bridge.getField('a')).toEqual(schema.getDefinition('a'));112 });113 it('throws on not found field', () => {114 expect(() => bridge.getField('x')).toThrow(/Field not found in schema/);115 });116 });117 describe('#getInitialValue', () => {118 it('works with arrays', () => {119 expect(bridge.getInitialValue('j')).toEqual([undefined]);120 expect(bridge.getInitialValue('k')).toEqual([]);121 });122 it('works with objects', () => {123 expect(bridge.getInitialValue('a')).toEqual({});124 });125 });126 describe('#getProps', () => {127 it('works with allowedValues', () => {128 expect(bridge.getProps('o')).toEqual({label: 'O', required: true, allowedValues: ['O']});129 });130 it('works with allowedValues from props', () => {131 expect(bridge.getProps('o', {allowedValues: ['O']})).toEqual({label: 'O', required: true});132 });133 it('works with custom component', () => {134 expect(bridge.getProps('l')).toEqual({label: 'L', required: true, component: 'div'});135 expect(bridge.getProps('m')).toEqual({label: 'M', required: true, component: noop});136 });137 it('works with custom component (field)', () => {138 expect(bridge.getProps('n')).toEqual({label: 'N', required: true, component: 'div'});139 });140 it('works with options (array)', () => {141 expect(bridge.getProps('s').transform('a')).toBe(1);142 expect(bridge.getProps('s').transform('b')).toBe(2);143 expect(bridge.getProps('s').allowedValues[0]).toBe('a');144 expect(bridge.getProps('s').allowedValues[1]).toBe('b');145 });146 it('works with options (function)', () => {147 expect(bridge.getProps('t').transform('a')).toBe(1);148 expect(bridge.getProps('t').transform('b')).toBe(2);149 expect(bridge.getProps('t').allowedValues[0]).toBe('a');150 expect(bridge.getProps('t').allowedValues[1]).toBe('b');151 });152 it('works with options (object)', () => {153 expect(bridge.getProps('r').transform('a')).toBe(1);154 expect(bridge.getProps('r').transform('b')).toBe(2);155 expect(bridge.getProps('r').allowedValues[0]).toBe('a');156 expect(bridge.getProps('r').allowedValues[1]).toBe('b');157 });158 it('works with options from props', () => {159 expect(bridge.getProps('s', {options: {c: 1, d: 2}}).transform('c')).toBe(1);160 expect(bridge.getProps('s', {options: {c: 1, d: 2}}).transform('d')).toBe(2);161 expect(bridge.getProps('s', {options: {c: 1, d: 2}}).allowedValues[0]).toBe('c');162 expect(bridge.getProps('s', {options: {c: 1, d: 2}}).allowedValues[1]).toBe('d');163 });164 it('works with transform', () => {165 expect(bridge.getProps('p')).toEqual({label: 'P', required: true, transform: noop});166 });167 it('works with transform from props', () => {168 expect(bridge.getProps('p', {transform: () => {}})).toEqual({label: 'P', required: true});169 });170 });171 describe('#getSubfields', () => {172 it('works with objects', () => {173 expect(bridge.getSubfields('a')).toEqual(['b']);174 expect(bridge.getSubfields('a.b')).toEqual(['c']);175 });176 it('works with primitives', () => {177 expect(bridge.getSubfields('d')).toEqual([]);178 expect(bridge.getSubfields('e')).toEqual([]);179 });180 });181 describe('#getType', () => {182 it('works with any type', () => {183 expect(bridge.getType('a')).toBe(Object);184 expect(bridge.getType('j')).toBe(Array);185 expect(bridge.getType('d')).toBe(String);186 expect(bridge.getType('f')).toBe(Number);187 expect(bridge.getType('i')).toBe(Date);188 });189 });190 describe('#getValidator', () => {191 it('calls correct validator', () => {192 expect(() => bridge.getValidator()({})).toThrow();193 });194 });...
TotalGradeOverrideCellPropFactory.test.js
Source:TotalGradeOverrideCellPropFactory.test.js
1/*2 * Copyright (C) 2018 - present Instructure, Inc.3 *4 * This file is part of Canvas.5 *6 * Canvas is free software: you can redistribute it and/or modify it under7 * the terms of the GNU Affero General Public License as published by the Free8 * Software Foundation, version 3 of the License.9 *10 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR12 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more13 * details.14 *15 * You should have received a copy of the GNU Affero General Public License along16 * with this program. If not, see <http://www.gnu.org/licenses/>.17 */18import sinon from 'sinon'19import GradeOverrideEntry from '../../../../../../grading/GradeEntry/GradeOverrideEntry'20import GradeOverrideInfo from '../../../../../../grading/GradeEntry/GradeOverrideInfo'21import FinalGradeOverrides from '../../../../FinalGradeOverrides'22import TotalGradeOverrideCellPropFactory from '../TotalGradeOverrideCellPropFactory'23describe('GradebookGrid TotalGradeOverrideCellPropFactory', () => {24 let gradebook25 let gradingScheme26 describe('#getProps()', () => {27 let editorOptions28 beforeEach(() => {29 gradingScheme = {30 data: [['A', 0.9], ['B', 0.8], ['C', 0.7], ['D', 0.6], ['F', 0.5]],31 id: '2801',32 title: 'Default Grading Scheme'33 }34 // `gradebook` is a double because CoffeeScript and AMD cannot be imported35 // into Jest specs36 gradebook = {37 getCourseGradingScheme() {38 return gradingScheme39 },40 gradebookGrid: {41 updateRowCell: sinon.stub()42 },43 isFilteringColumnsByGradingPeriod: sinon.stub().returns(false),44 studentCanReceiveGradeOverride(id) {45 return {1101: true, 1102: false}[id]46 }47 }48 gradebook.finalGradeOverrides = new FinalGradeOverrides(gradebook)49 gradebook.finalGradeOverrides.setGrades({50 1101: {51 courseGrade: {52 percentage: 88.153 }54 }55 })56 editorOptions = {57 item: {id: '1101'}58 }59 })60 function getProps() {61 const factory = new TotalGradeOverrideCellPropFactory(gradebook)62 return factory.getProps(editorOptions)63 }64 it('sets .gradeEntry to a GradeOverrideEntry instance', () => {65 expect(getProps().gradeEntry).toBeInstanceOf(GradeOverrideEntry)66 })67 it('uses the grading scheme from the Gradebook to create the GradeEntry', () => {68 expect(getProps().gradeEntry.gradingScheme).toBe(gradingScheme)69 })70 it('sets .gradeInfo to a GradeOverrideInfo instance', () => {71 expect(getProps().gradeInfo).toBeInstanceOf(GradeOverrideInfo)72 })73 it('derives the grade override info from the user grade', () => {74 expect(getProps().gradeInfo.grade.percentage).toEqual(88.1)75 })76 it('sets .gradeIsUpdating to false when the user does not have a pending grade', () => {77 expect(getProps().gradeIsUpdating).toBe(false)78 })79 it('sets .gradeIsUpdating to true when the user has a valid pending grade', () => {80 const {gradeEntry} = getProps()81 const gradeInfo = gradeEntry.parseValue('A')82 gradebook.finalGradeOverrides._datastore.addPendingGradeInfo('1101', null, gradeInfo)83 expect(getProps().gradeIsUpdating).toBe(true)84 })85 it('sets .gradeIsUpdating to false when the user has an invalid pending grade', () => {86 const {gradeEntry} = getProps()87 const gradeInfo = gradeEntry.parseValue('invalid')88 gradebook.finalGradeOverrides._datastore.addPendingGradeInfo('1101', null, gradeInfo)89 expect(getProps().gradeIsUpdating).toBe(false)90 })91 describe('.onGradeUpdate', () => {92 let props93 beforeEach(() => {94 sinon.stub(gradebook.finalGradeOverrides, 'updateGrade')95 props = getProps()96 })97 it('updates a final grade override when called', () => {98 const gradeInfo = props.gradeEntry.parseValue('A')99 props.onGradeUpdate(gradeInfo)100 expect(gradebook.finalGradeOverrides.updateGrade.callCount).toEqual(1)101 })102 it('includes the user id for the row when updating the final grade override', () => {103 const gradeInfo = props.gradeEntry.parseValue('A')104 props.onGradeUpdate(gradeInfo)105 const [userId] = gradebook.finalGradeOverrides.updateGrade.lastCall.args106 expect(userId).toEqual('1101')107 })108 it('includes the given grade override info when updating the final grade override', () => {109 const gradeInfo = props.gradeEntry.parseValue('A')110 props.onGradeUpdate(gradeInfo)111 const [, gradeOverrideInfo] = gradebook.finalGradeOverrides.updateGrade.lastCall.args112 expect(gradeOverrideInfo).toBe(gradeInfo)113 })114 })115 it('sets .pendingGradeInfo to the pending grade for the related user', () => {116 const {gradeEntry} = getProps()117 const gradeInfo = gradeEntry.parseValue('A')118 gradebook.finalGradeOverrides._datastore.addPendingGradeInfo('1101', null, gradeInfo)119 expect(getProps().pendingGradeInfo).toBe(gradeInfo)120 })121 it('sets .studentIsGradeable to true when the student is gradeable', () => {122 expect(getProps().studentIsGradeable).toBe(true)123 })124 it('sets .studentIsGradeable to false when the student is not gradeable', () => {125 editorOptions.item.id = '1102'126 expect(getProps().studentIsGradeable).toBe(false)127 })128 })...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!