@@ -14,9 +14,21 @@ define [
1414 ' helpers/fakeENV'
1515 ' jsx/shared/rce/RichContentEditor'
1616 ' helpers/jquery.simulate'
17- ], ($, _, SectionCollection, Assignment, DueDateList, Section, DiscussionTopic,
18- Announcement, DueDateOverrideView, EditView, AssignmentGroupCollection,
19- GroupCategorySelector, fakeENV, RichContentEditor) ->
17+ ], (
18+ $,
19+ _,
20+ SectionCollection,
21+ Assignment,
22+ DueDateList,
23+ Section,
24+ DiscussionTopic,
25+ Announcement,
26+ DueDateOverrideView,
27+ EditView,
28+ AssignmentGroupCollection,
29+ GroupCategorySelector,
30+ fakeENV,
31+ RichContentEditor) ->
2032
2133 editView = (opts = {}, discussOpts = {}) ->
2234 modelClass = if opts .isAnnouncement then Announcement else DiscussionTopic
@@ -42,6 +54,16 @@ GroupCategorySelector, fakeENV, RichContentEditor) ->
4254 (app .assignmentGroupCollection = new AssignmentGroupCollection ).contextAssetString = ENV .context_asset_string
4355 app .render ()
4456
57+ nameLengthHelper = (view , length , maxNameLengthRequiredForAccount , maxNameLength , postToSis ) ->
58+ ENV .MAX_NAME_LENGTH_REQUIRED_FOR_ACCOUNT = maxNameLengthRequiredForAccount
59+ ENV .MAX_NAME_LENGTH = maxNameLength
60+ ENV .IS_LARGE_ROSTER = true
61+ ENV .CONDITIONAL_RELEASE_SERVICE_ENABLED = false
62+ title = ' a' .repeat (length)
63+ assignment = view .assignment
64+ assignment .attributes .post_to_sis = postToSis
65+ return view .validateBeforeSave ({title : title, set_assignment : ' 1' , assignment : assignment}, [])
66+
4567 QUnit .module ' EditView' ,
4668 setup : ->
4769 fakeENV .setup ()
@@ -169,86 +191,29 @@ GroupCategorySelector, fakeENV, RichContentEditor) ->
169191 view .loadConditionalRelease ()
170192 equal 1 , view .$conditionalReleaseTarget .children ().size ()
171193
172- test " has an error when a title > 255 chars" , ->
173- view = @ editView ({ withAssignment : true })
174- assignment = view .assignment
175- l1 = ' aaaaaaaaaa'
176- l2 = l1 + l1 + l1 + l1 + l1 + l1
177- l3 = l2 + l2 + l2 + l2 + l2 + l2
178-
179- ENV .IS_LARGE_ROSTER = true
180- ENV .CONDITIONAL_RELEASE_SERVICE_ENABLED = false
181- errors = view .validateBeforeSave ({title : l3, set_assignment : ' 1' , assignment : assignment}, [])
182-
183- equal errors[" title" ][0 ][" message" ], " Title is too long, must be under 256 characters"
184-
185- test " allows dicussion to save when a title < 255 chars, MAX_NAME_LENGTH is not required and post_to_sis is true" , ->
194+ test " has an error when a title is 257 chars" , ->
186195 view = @ editView ({ withAssignment : true })
187- assignment = view .assignment
188- assignment .attributes .post_to_sis = ' 1'
189- l1 = ' aaaaaaaaaa'
196+ errors = nameLengthHelper (view, 257 , false , 30 , ' 0' )
197+ equal errors[" title" ][0 ][" message" ], " Title is too long, must be under 257 characters"
190198
191- ENV .MAX_NAME_LENGTH_REQUIRED_FOR_ACCOUNT = false
192- ENV .IS_LARGE_ROSTER = true
193- ENV .CONDITIONAL_RELEASE_SERVICE_ENABLED = false
194- errors = view .validateBeforeSave ({title : l1, set_assignment : ' 1' , assignment : assignment}, [])
195- equal errors .length , 0
196-
197- test " allows dicussion to save when a title < 255 chars, MAX_NAME_LENGTH is not required and post_to_sis is false" , ->
199+ test " allows dicussion to save when a title is 256 chars, MAX_NAME_LENGTH is not required and post_to_sis is true" , ->
198200 view = @ editView ({ withAssignment : true })
199- assignment = view .assignment
200- assignment .attributes .post_to_sis = ' 1'
201- l1 = ' aaaaaaaaaa'
202-
203- ENV .MAX_NAME_LENGTH_REQUIRED_FOR_ACCOUNT = false
204- ENV .IS_LARGE_ROSTER = true
205- ENV .CONDITIONAL_RELEASE_SERVICE_ENABLED = false
206- errors = view .validateBeforeSave ({title : l1, set_assignment : ' 1' , assignment : assignment}, [])
201+ errors = nameLengthHelper (view, 256 , false , 30 , ' 1' )
207202 equal errors .length , 0
208203
209204 test " has an error when a title > MAX_NAME_LENGTH chars if MAX_NAME_LENGTH is custom, required and post_to_sis is true" , ->
210205 view = @ editView ({ withAssignment : true })
211- assignment = view .assignment
212- assignment .attributes .post_to_sis = ' 1'
213- l1 = ' aaaaaaaaaa'
214-
215- ENV .MAX_NAME_LENGTH = 5
216- ENV .MAX_NAME_LENGTH_REQUIRED_FOR_ACCOUNT = true
217- ENV .IS_LARGE_ROSTER = true
218- ENV .CONDITIONAL_RELEASE_SERVICE_ENABLED = false
219- errors = view .validateBeforeSave ({title : l1, set_assignment : ' 1' , assignment : assignment}, [])
220-
221- equal errors[" title" ][0 ][" message" ], " Title is too long, must be under #{ ENV .MAX_NAME_LENGTH + 1 } characters"
206+ errors = nameLengthHelper (view, 40 , true , 30 , ' 1' )
207+ equal errors[" title" ][0 ][" message" ], " Title is too long, must be under 31 characters"
222208
223209 test " allows discussion to save when title > MAX_NAME_LENGTH chars if MAX_NAME_LENGTH is custom, required and post_to_sis is false" , ->
224210 view = @ editView ({ withAssignment : true })
225- assignment = view .assignment
226- assignment .attributes .post_to_sis = ' 0'
227- l1 = ' aaaaaaaaaa'
228- l2 = l1 + l1 + l1 + l1 + l1 + l1
229- l3 = l2 + l2 + l2 + l2 + l2 + l2
230-
231- ENV .MAX_NAME_LENGTH = 5
232- ENV .MAX_NAME_LENGTH_REQUIRED_FOR_ACCOUNT = true
233- ENV .IS_LARGE_ROSTER = true
234- ENV .CONDITIONAL_RELEASE_SERVICE_ENABLED = false
235- errors = view .validateBeforeSave ({title : l3, set_assignment : ' 1' , assignment : assignment}, [])
236-
211+ errors = nameLengthHelper (view, 40 , true , 30 , ' 0' )
237212 equal errors .length , 0
238213
239-
240214 test " allows discussion to save when title < MAX_NAME_LENGTH chars if MAX_NAME_LENGTH is custom, required and post_to_sis is true" , ->
241215 view = @ editView ({ withAssignment : true })
242- assignment = view .assignment
243- assignment .attributes .post_to_sis = ' 1'
244- l1 = ' aaaaaaaaaa'
245-
246- ENV .MAX_NAME_LENGTH = 20
247- ENV .MAX_NAME_LENGTH_REQUIRED_FOR_ACCOUNT = true
248- ENV .IS_LARGE_ROSTER = true
249- ENV .CONDITIONAL_RELEASE_SERVICE_ENABLED = false
250- errors = view .validateBeforeSave ({title : l1, set_assignment : ' 1' , assignment : assignment}, [])
251-
216+ errors = nameLengthHelper (view, 30 , true , 40 , ' 1' )
252217 equal errors .length , 0
253218
254219 test ' conditional release editor is updated on tab change' , ->
0 commit comments