make on-the-hour time formats the same in js <-> ruby

fixes SD-1051

some places in JS (handlebars) were already consistent w/ ruby, others
were not. now if the time is on the hour, we omit the minutes everywere
(e.g. 1pm, not 1:00pm)

also fix most (all?) brittle specs that fail on the minute, hour, at
midnight, around DST, and at/near the new year ... 30+ are fixed by virtue
of this change alone, others required a little more TLC.

problematic specs were uncovered by freezing and/or traveling time to
interesting timestamps (see earlier patchset builds w/ timecop and
timecop.js).

note that some spec changes weren't technically necessary (many of the
format_date_for_view), but they are being tweaked regardless so we can
add a linter to discourage strftime calls in specs.

test plan:
n/a, see specs

Change-Id: I9edd65226ff37f9a3d94e2e03e1a01ab36aad639
Reviewed-on: https://gerrit.instructure.com/77295
Tested-by: Jenkins
Reviewed-by: Landon Wilkins <lwilkins@instructure.com>
Product-Review: Jon Jensen <jon@instructure.com>
QA-Review: Jon Jensen <jon@instructure.com>
This commit is contained in:
Jon Jensen 2016-04-18 15:24:21 -06:00
parent a12e2d1498
commit 393bc22317
34 changed files with 206 additions and 200 deletions

View File

@ -79,10 +79,17 @@ define([
$.timeString = function(date, options) {
if (date == null) return "";
var timezone = options && options.timezone;
// match ruby-side short format on the hour, e.g. `1pm`
// can't just check getMinutes, cuz not all timezone offsets are on the hour
var format = tz.format(date, '%M') === '00' ?
'time.formats.tiny_on_the_hour' :
'time.formats.tiny';
if (typeof timezone == 'string' || timezone instanceof String) {
return tz.format(date, 'time.formats.tiny', timezone) || '';
return tz.format(date, format, timezone) || '';
} else {
return tz.format(date, 'time.formats.tiny') || '';
return tz.format(date, format) || '';
}
};
$.datetimeString = function(datetime, options) {

View File

@ -27,6 +27,7 @@ define [
@contexts = [{"asset_string":"user_1"}, {"asset_string":"course_2"}, {"asset_string":"group_3"}]
@contextCodes = ["user_1", "course_2", "group_3"]
@startDate = fcUtil.now()
@startDate.minute(1)
@startDate.year(2001)
@dataSource = new EventDataSource(@contexts)
@server = sinon.fakeServer.create()

View File

@ -93,19 +93,19 @@ define [
test 'can take an ISO string', ->
contains helpers.friendlyDatetime('1970-01-01 00:00:00Z', hash: {pubDate: false}).string,
"Dec 31, 1969 at 7:00pm"
"Dec 31, 1969 at 7pm"
test 'can take a date object', ->
contains helpers.friendlyDatetime(new Date(0), hash: {pubDate: false}).string,
"Dec 31, 1969 at 7:00pm"
"Dec 31, 1969 at 7pm"
test 'should parse non-qualified string relative to profile timezone', ->
contains helpers.friendlyDatetime('1970-01-01 00:00:00', hash: {pubDate: false}).string,
"Jan 1, 1970 at 12:00am"
"Jan 1, 1970 at 12am"
test 'includes a screenreader accessible version', ->
contains helpers.friendlyDatetime(new Date(0), hash: {pubDate: false}).string,
"<span class='screenreader-only'>Dec 31, 1969 at 7:00pm</span>"
"<span class='screenreader-only'>Dec 31, 1969 at 7pm</span>"
test 'includes a visible version', ->
contains helpers.friendlyDatetime(new Date(0), hash: {pubDate: false}).string,
@ -125,18 +125,18 @@ define [
test 'displays both zones data from an ISO string', ->
timeTag = helpers.friendlyDatetime('1970-01-01 00:00:00Z', hash: {pubDate: false, contextSensitive: true}).string
contains timeTag, "Local: Dec 31, 1969 at 7:00pm"
contains timeTag, "Course: Dec 31, 1969 at 6:00pm"
contains timeTag, "Local: Dec 31, 1969 at 7pm"
contains timeTag, "Course: Dec 31, 1969 at 6pm"
test 'displays both zones data from a date object', ->
timeTag = helpers.friendlyDatetime(new Date(0), hash: {pubDate: false, contextSensitive: true}).string
contains timeTag, "Local: Dec 31, 1969 at 7:00pm"
contains timeTag, "Course: Dec 31, 1969 at 6:00pm"
contains timeTag, "Local: Dec 31, 1969 at 7pm"
contains timeTag, "Course: Dec 31, 1969 at 6pm"
test 'should parse non-qualified string relative to both timezones', ->
timeTag = helpers.friendlyDatetime('1970-01-01 00:00:00', hash: {pubDate: false, contextSensitive: true}).string
contains timeTag, "Local: Jan 1, 1970 at 12:00am"
contains timeTag, "Course: Dec 31, 1969 at 11:00pm"
contains timeTag, "Local: Jan 1, 1970 at 12am"
contains timeTag, "Course: Dec 31, 1969 at 11pm"
test 'reverts to friendly display when there is no contextual timezone', ->
ENV.CONTEXT_TIMEZONE = null
@ -159,11 +159,11 @@ define [
test 'just passes through to datetime string if there is no contextual timezone', ->
ENV.CONTEXT_TIMEZONE = null
titleText = helpers.contextSensitiveDatetimeTitle('1970-01-01 00:00:00Z', hash: {justText: true})
equal titleText, "Dec 31, 1969 at 7:00pm"
equal titleText, "Dec 31, 1969 at 7pm"
test 'splits title text to both zones', ->
titleText = helpers.contextSensitiveDatetimeTitle('1970-01-01 00:00:00Z', hash: {justText: true})
equal titleText, "Local: Dec 31, 1969 at 7:00pm<br>Course: Dec 31, 1969 at 6:00pm"
equal titleText, "Local: Dec 31, 1969 at 7pm<br>Course: Dec 31, 1969 at 6pm"
test "properly spans day boundaries", ->
ENV.TIMEZONE = 'America/Chicago'
@ -176,18 +176,18 @@ define [
ENV.TIMEZONE = 'America/Detroit'
ENV.CONTEXT_TIMEZONE = 'America/Detroit'
titleText = helpers.contextSensitiveDatetimeTitle('1970-01-01 00:00:00Z', hash: {justText: true})
equal titleText, "Dec 31, 1969 at 7:00pm"
equal titleText, "Dec 31, 1969 at 7pm"
test 'stays as one title when the time is no different even if timezone names differ', ->
ENV.TIMEZONE = 'America/Detroit'
ENV.CONTEXT_TIMEZONE = 'America/New_York'
titleText = helpers.contextSensitiveDatetimeTitle('1970-01-01 00:00:00Z', hash: {justText: true})
equal titleText, "Dec 31, 1969 at 7:00pm"
equal titleText, "Dec 31, 1969 at 7pm"
test "produces the html attributes if you dont specify just_text", ->
ENV.CONTEXT_TIMEZONE = null
titleText = helpers.contextSensitiveDatetimeTitle('1970-01-01 00:00:00Z', hash: {justText: undefined})
equal titleText, "data-tooltip data-html-tooltip-title=\"Dec 31, 1969 at 7:00pm\""
equal titleText, "data-tooltip data-html-tooltip-title=\"Dec 31, 1969 at 7pm\""
module 'datetimeFormatted',
setup: -> @snapshot = tz.snapshot()
@ -196,7 +196,7 @@ define [
test 'should parse and format relative to profile timezone', ->
tz.changeZone(detroit, 'America/Detroit')
equal helpers.datetimeFormatted('1970-01-01 00:00:00'),
"Jan 1, 1970 at 12:00am"
"Jan 1, 1970 at 12am"
module 'ifSettingIs'

View File

@ -179,12 +179,17 @@ define [
test 'should format in profile timezone', ->
I18nStubber.stub 'en', 'time.formats.tiny': "%l:%M%P"
tz.changeZone(detroit, 'America/Detroit')
equal $.timeString(new Date(0)), '7:00pm'
equal $.timeString(new Date(60000)), '7:01pm'
test 'should format according to profile locale', ->
I18nStubber.setLocale 'en-GB'
I18nStubber.stub 'en-GB', 'time.formats.tiny': "%k:%M"
equal $.timeString(new Date(46800000)), '13:00'
equal $.timeString(new Date(46860000)), '13:01'
test 'should use the tiny_on_the_hour format on the hour', ->
I18nStubber.stub 'en', 'time.formats.tiny_on_the_hour': "%l%P"
tz.changeZone(detroit, 'America/Detroit')
equal $.timeString(new Date(0)), '7pm'
module 'datetimeString',
setup: ->
@ -201,7 +206,7 @@ define [
'date.formats.medium': "%b %-d, %Y"
'time.formats.tiny': "%l:%M%P"
'time.event': "%{date} at %{time}"
equal $.datetimeString(new Date(0)), 'Dec 31, 1969 at 7:00pm'
equal $.datetimeString(new Date(60000)), 'Dec 31, 1969 at 7:01pm'
test 'should translate into the profile locale', ->
tz.changeLocale(portuguese, 'pt_PT', 'pt')
@ -210,7 +215,7 @@ define [
'date.formats.medium': "%-d %b %Y"
'time.formats.tiny': "%k:%M"
'time.event': "%{date} em %{time}"
equal $.datetimeString('1970-01-01 15:00:00Z'), "1 Jan 1970 em 15:00"
equal $.datetimeString('1970-01-01 15:01:00Z'), "1 Jan 1970 em 15:01"
module '$.datepicker.parseDate',
setup: ->

View File

@ -19,7 +19,7 @@ define [
@clock = sinon.useFakeTimers()
props =
handleUpdate: ->
dateValue: new Date(Date.UTC(2012, 1, 1, 7, 0, 0))
dateValue: new Date(Date.UTC(2012, 1, 1, 7, 1, 0))
dateType: "unlock_at"
rowKey: "nullnullnull"
labelledBy: "foo"
@ -36,7 +36,7 @@ define [
ok @dueDateCalendarPicker.isMounted()
test 'formattedDate returns a nicely formatted Date', ->
equal "Feb 1, 2012 at 7:00am", @dueDateCalendarPicker.formattedDate()
equal "Feb 1, 2012 at 7:01am", @dueDateCalendarPicker.formattedDate()
test 'formattedDate returns a localized Date', ->
snapshot = tz.snapshot()
@ -47,7 +47,7 @@ define [
'date.formats.medium': "%-d %b %Y"
'time.formats.tiny': "%-k:%M"
'time.event': "%{date} à %{time}"
equal "1 févr. 2012 à 7:00", @dueDateCalendarPicker.formattedDate()
equal "1 févr. 2012 à 7:01", @dueDateCalendarPicker.formattedDate()
I18nStubber.popFrame()
tz.restore(snapshot)

View File

@ -48,7 +48,7 @@ define [
test 'should display a non clickable restricted dates icon', ->
equal @publishCloud.refs.publishCloud.props.onClick, undefined, 'does not have a click event'
equal @publishCloud.refs.publishCloud.props.title, "Available after Jan 1, 2014 at 12:00am until Feb 1, 2014 at 12:00am", "has a available from hoverover"
equal @publishCloud.refs.publishCloud.props.title, "Available after Jan 1, 2014 at 12am until Feb 1, 2014 at 12am", "has a available from hoverover"
# Unit Tests

View File

@ -9,10 +9,10 @@ define ['compiled/util/semanticDateRange'], (semanticDateRange) ->
"""
<span class="date-range">
<time datetime='1970-01-01T00:00:00.000Z'>
Jan 1, 1970 at 12:00am
Jan 1, 1970 at 12am
</time> -
<time datetime='1970-01-02T00:00:00.000Z'>
Jan 2, 1970 at 12:00am
Jan 2, 1970 at 12am
</time>
</span>
"""
@ -24,10 +24,10 @@ define ['compiled/util/semanticDateRange'], (semanticDateRange) ->
"""
<span class="date-range">
<time datetime='1970-01-01T00:00:00.000Z'>
Jan 1, 1970, 12:00am
Jan 1, 1970, 12am
</time> -
<time datetime='1970-01-01T01:00:00.000Z'>
1:00am
1am
</time>
</span>
"""
@ -38,7 +38,7 @@ define ['compiled/util/semanticDateRange'], (semanticDateRange) ->
"""
<span class="date-range">
<time datetime='1970-01-01T00:00:00.000Z'>
Jan 1, 1970 at 12:00am
Jan 1, 1970 at 12am
</time>
</span>
"""
@ -57,7 +57,7 @@ define ['compiled/util/semanticDateRange'], (semanticDateRange) ->
"""
<span class="date-range">
<time datetime='1970-01-01T00:00:00.000Z'>
Jan 1, 1970 at 12:00am
Jan 1, 1970 at 12am
</time>
</span>
"""

View File

@ -202,11 +202,11 @@ define [
# context-sensitive datetime titles
assignment_ts = $('.events_2012_01_01 .related-assignment_1 .dates > span:nth-child(1)')
equal assignment_ts.text(), "10am", "assignment - local time in table"
equal assignment_ts.data('html-tooltip-title'), "Local: Jan 1 at 10:00am<br>Course: Jan 1 at 12:00pm", 'assignment - correct local and course times given'
equal assignment_ts.data('html-tooltip-title'), "Local: Jan 1 at 10am<br>Course: Jan 1 at 12pm", 'assignment - correct local and course times given'
event_ts = $('.events_2012_01_01 .related-appointment_group_1 .dates > span:nth-child(1)')
equal event_ts.text(), " 8am", "event - local time in table"
equal event_ts.data('html-tooltip-title'), "Local: Jan 1 at 8:00am<br>Course: Jan 1 at 10:00am", 'event - correct local and course times given'
equal event_ts.data('html-tooltip-title'), "Local: Jan 1 at 8am<br>Course: Jan 1 at 10am", 'event - correct local and course times given'
test 'render (user public course)', ->
@view.can_read = true # public course -- can read

View File

@ -145,14 +145,14 @@ describe "admin_tools" do
set_value f('#commMessagesSearchForm .dateEndSearchField'), 'Mar 9, 2001'
f('#commMessagesSearchForm .userDateRangeSearchBtn').click
wait_for_ajaximations
expect(f('#commMessagesSearchOverview').text).to include("Notifications sent to #{@student.name} from Mar 3, 2001 at 12:00am to Mar 9, 2001 at 12:00am.")
expect(f('#commMessagesSearchOverview').text).to include("Notifications sent to #{@student.name} from Mar 3, 2001 at 12am to Mar 9, 2001 at 12am.")
# Search with begin date/time and end date/time - should use and show given time
perform_user_search("#commMessagesSearchForm", @student.id)
set_value f('#commMessagesSearchForm .dateStartSearchField'), 'Mar 3, 2001 1:05p'
set_value f('#commMessagesSearchForm .dateEndSearchField'), 'Mar 9, 2001 3p'
f('#commMessagesSearchForm .userDateRangeSearchBtn').click
wait_for_ajaximations
expect(f('#commMessagesSearchOverview').text).to include("Notifications sent to #{@student.name} from Mar 3, 2001 at 1:05pm to Mar 9, 2001 at 3:00pm.")
expect(f('#commMessagesSearchOverview').text).to include("Notifications sent to #{@student.name} from Mar 3, 2001 at 1:05pm to Mar 9, 2001 at 3pm.")
end
it "should display search params used when given invalid input data" do

View File

@ -232,7 +232,7 @@ describe "assignment groups" do
ag = @course.assignment_groups.first
time = DateTime.new(Time.now.year,2,7,4,15)
Timecop.freeze(time) do
current_time = time.strftime('%b %-d at %-l:%M') << time.strftime('%p').downcase
current_time = format_time_for_view(time)
assignment_name, assignment_points = ["Do this", "13"]
# Navigates to assignments index page.

View File

@ -32,11 +32,11 @@ describe "assignment groups" do
visit_assignment_edit_page(assignment)
expect(first_due_at_element.attribute(:value)).
to match due_at.strftime('%b %-d')
to match format_date_for_view(due_at)
expect(first_unlock_at_element.attribute(:value)).
to match unlock_at.strftime('%b %-d')
to match format_date_for_view(unlock_at)
expect(first_lock_at_element.attribute(:value)).
to match lock_at.strftime('%b %-d')
to match format_date_for_view(lock_at)
end
it "should edit a due date", priority: "2", test_id: 216346 do
@ -45,11 +45,11 @@ describe "assignment groups" do
# set due_at, lock_at, unlock_at
first_due_at_element.clear
first_due_at_element.send_keys(due_at.strftime('%b %-d, %y'))
first_due_at_element.send_keys(format_date_for_view(due_at, :medium))
update_assignment!
expect(assignment.reload.due_at.strftime('%b %-d, %y')).
to eq due_at.to_date.strftime('%b %-d, %y')
expect(assignment.reload.due_at.to_date).
to eq due_at.to_date
end
it "should clear a due date", priority: "2", test_id: 216348 do
@ -76,24 +76,24 @@ describe "assignment groups" do
first_due_at_element.clear
first_due_at_element.
send_keys(default_section_due.strftime('%b %-d, %y'))
send_keys(format_date_for_view(default_section_due, :medium))
add_override
wait_for_ajaximations
select_last_override_section(other_section.name)
last_due_at_element.
send_keys(other_section_due.strftime('%b %-d, %y'))
send_keys(format_date_for_view(other_section_due, :medium))
update_assignment!
overrides = assign.reload.assignment_overrides
expect(overrides.count).to eq 2
default_override = overrides.detect{ |o| o.set_id == default_section.id }
expect(default_override.due_at.strftime('%b %-d, %y')).
to eq default_section_due.to_date.strftime('%b %-d, %y')
expect(default_override.due_at.to_date).
to eq default_section_due.to_date
other_override = overrides.detect{ |o| o.set_id == other_section.id }
expect(other_override.due_at.strftime('%b %-d, %y')).
to eq other_section_due.to_date.strftime('%b %-d, %y')
expect(other_override.due_at.to_date).
to eq other_section_due.to_date
end
it "should not show inactive students when setting overrides" do
@ -134,13 +134,13 @@ describe "assignment groups" do
first_unlock_at_element.clear
first_lock_at_element.clear
last_due_at_element.
send_keys(due_date.strftime('%b %-d, %y'))
send_keys(format_date_for_view(due_date, :medium))
submit_form('#edit_assignment_form')
wait_for_ajaximations
overrides = assign.reload.assignment_overrides
section_override = overrides.detect{ |o| o.set_id == section1.id }
expect(section_override.due_at.strftime('%b %-d, %y'))
.to eq due_date.strftime('%b %-d, %y')
expect(section_override.due_at.to_date)
.to eq due_date.to_date
end
it "properly validates identical calendar dates when saving and editing", priority: "2", test_id: 216351 do

View File

@ -131,7 +131,7 @@ describe "assignments" do
# freeze for a certain time, so we don't get unexpected ui complications
time = DateTime.new(Time.now.year,1,7,2,13)
Timecop.freeze(time) do
due_at = time.strftime('%b %-d at %-l:%M') << time.strftime('%p').downcase
due_at = format_time_for_view(time)
get "/courses/#{@course.id}/assignments"
wait_for_ajaximations
@ -195,7 +195,7 @@ describe "assignments" do
# freeze time to avoid ui complications
time = DateTime.new(2015,1,7,2,13)
Timecop.freeze(time) do
due_at = time.strftime('%b %-d at %-l:%M') << time.strftime('%p').downcase
due_at = format_time_for_view(time)
points = '25'
get "/courses/#{@course.id}/assignments"

View File

@ -92,7 +92,7 @@ describe "assignments" do
locked_assignment = @course.assignments.create!(:name => assignment_name, :unlock_at => unlock_time)
get "/courses/#{@course.id}/assignments/#{locked_assignment.id}"
expect(f('#content')).to include_text(unlock_time.strftime("%b %-d"))
expect(f('#content')).to include_text(format_date_for_view(unlock_time))
locked_assignment.update_attributes(:unlock_at => Time.now)
refresh_page # to show the updated assignment
expect(f('#content')).not_to include_text('This assignment is locked until')
@ -377,4 +377,4 @@ describe "assignments" do
end
end
end
end
end

View File

@ -104,8 +104,8 @@ describe "calendar2" do
tomorrow = 1.day.from_now
event = make_event(start: tomorrow)
load_agenda_view
expect(f('.navigation_title')).to include_text(Time.now.utc.strftime("%b %-d, %Y"))
expect(f('.navigation_title')).to include_text(tomorrow.utc.strftime("%b %-d, %Y"))
expect(f('.navigation_title')).to include_text(format_date_for_view(Time.zone.now, :medium))
expect(f('.navigation_title')).to include_text(format_date_for_view(tomorrow, :medium))
end
it "should not display a date range if no events are found" do
@ -179,7 +179,7 @@ describe "calendar2" do
change_calendar
#Get the current date and make sure it is not in the header
date = Time.now.strftime("%b %-d, %Y")
date = format_date_for_view(Time.zone.now, :medium)
expect(f('.navigation_title').text).not_to include(date)
#Go the agenda view and click the today button
@ -236,17 +236,17 @@ describe "calendar2" do
@override = create_section_override_for_assignment(assignment, course_section: s2, due_at: s2_date)
load_agenda_view
keep_trying_until { expect(ffj('.ig-row').length).to eq 3 }
keep_trying_until { expect(ff('.ig-row').length).to eq 3 }
# Verify Titles include section name
agenda_array = ffj('.ig-row')
expect(fj('.ig-title', agenda_array[1]).text).to include_text('Section1')
expect(fj('.ig-title', agenda_array[2]).text).to include_text('Section2')
agenda_array = ff('.ig-row')
expect(f('.ig-title', agenda_array[1]).text).to include_text('Section1')
expect(f('.ig-title', agenda_array[2]).text).to include_text('Section2')
# Verify Dates
date_array = ffj('.agenda-day')
expect(fj('.agenda-date', date_array[1]).text).to include_text(s1_date.strftime('%a, %b %-d'))
expect(fj('.agenda-date', date_array[2]).text).to include_text(s2_date.strftime('%a, %b %-d'))
date_array = ff('.agenda-day')
expect(f('.agenda-date', date_array[1]).text).to include_text(format_date_for_view(s1_date, :short_with_weekday))
expect(f('.agenda-date', date_array[2]).text).to include_text(format_date_for_view(s2_date, :short_with_weekday))
end
context "with a graded discussion created" do
@ -285,12 +285,12 @@ describe "calendar2" do
# Verify edits
expect(f('.ig-title')).to include_text(test_name)
expect(f('.agenda-date')).to include_text(test_date.strftime('%a, %b %-d'))
expect(f('.agenda-date')).to include_text(date_string(test_date, :short_with_weekday))
end
it "should allow editing via More Options", priority: "1", test_id: 420724 do
skip('final load_agenda_view is fragile, needs analysis')
test_date = 2.days.from_now
test_date = 2.days.from_now.change(hours: 13, min: 59, sec: 0, usec: 0)
test_title = 'Test Title'
test_description = 'New Description'
load_agenda_view
@ -304,10 +304,10 @@ describe "calendar2" do
wait_for_ajaximations
# Edit title, description, and date
replace_content(fj('#discussion-title.input-block-level'), test_title + '1')
replace_content(f('#discussion-title.input-block-level'), test_title + '1')
driver.execute_script "tinyMCE.activeEditor.setContent('#{test_description}')"
replace_content(fj('.DueDateInput'),(test_date).strftime('%b %-d, %Y at 1:59pm'))
fj('.form-actions.flush .btn.btn-primary').click
replace_content(f('.DueDateInput'), format_time_for_view(test_date))
f('.form-actions.flush .btn.btn-primary').click
wait_for_ajaximations
# Verify edited title, description, and date
@ -317,7 +317,7 @@ describe "calendar2" do
wait_for_ajaximations
expect(f('.view_event_link')).to include_text(test_title)
expect(f('.event-detail-overflow')).to include_text(test_description)
expect(f('.event-details-timestring')).to include_text((test_date).strftime('%b %-d at 1:59pm'))
expect(f('.event-details-timestring')).to include_text(format_time_for_view(test_date))
end
end
end

View File

@ -202,8 +202,8 @@ describe "calendar2" do
drag_and_drop_element(f('.fc-content-skeleton .fc-event-container .fc-resizer'), next_day)
fj('.fc-event:visible').click
# observe the event details show date range from event start to date to end date
original_day_text = date_of_middle_day.to_datetime.strftime('%b %-d at %-l:%M%P')
extended_day_text = (date_of_next_day.to_datetime + 1.day).strftime('%b %-d at %-l:%M%P')
original_day_text = format_time_for_view(date_of_middle_day.to_datetime)
extended_day_text = format_time_for_view(date_of_next_day.to_datetime + 1.day)
expect(f('.event-details-timestring .date-range').text).to eq("#{original_day_text} - #{extended_day_text}")
end
end

View File

@ -53,7 +53,7 @@ describe "calendar2" do
event_dialog.find('#assignment_title').send_keys('saturday assignment')
event_dialog.find('.datetime_field').clear
# take next week's monday and advance to saturday from the current date
due_date = "Dec 26, 2015 at 8:00pm"
due_date = "Dec 26, 2015 at 8pm"
event_dialog.find('.datetime_field').send_keys(due_date)
assignment_form = event_dialog.find('#edit_assignment_form')
submit_form(assignment_form)

View File

@ -45,7 +45,7 @@ describe "context modules" do
@observer_enrollment = @course.enroll_user(@observer, 'ObserverEnrollment', :enrollment_state => 'active', :section => section2)
get "/courses/#{@course.id}/modules"
expect(f(".due_date_display").text).not_to be_blank
expect(f(".due_date_display").text).to eq @due_at.strftime('%b %-d, %Y')
expect(f(".due_date_display").text).to eq format_date_for_view(@due_at)
end
it "when not associated, and in multiple sections, it should show the latest due date" do
@ -59,13 +59,13 @@ describe "context modules" do
@observer_enrollment = @course.enroll_user(@observer, 'ObserverEnrollment', :enrollment_state => 'active', :allow_multiple_enrollments => true, :section => section2)
get "/courses/#{@course.id}/modules"
expect(f(".due_date_display").text).not_to be_blank
expect(f(".due_date_display").text).to eq @due_at.strftime('%b %-d, %Y')
expect(f(".due_date_display").text).to eq format_date_for_view(@due_at)
end
it "when associated with a student, it should show the student's overridden due date" do
@observer_enrollment = @course.enroll_user(@observer, 'ObserverEnrollment', :enrollment_state => 'active', :associated_user_id => @student.id)
get "/courses/#{@course.id}/modules"
expect(f(".due_date_display").text).to eq @due_at.strftime('%b %-d, %Y')
expect(f(".due_date_display").text).to eq format_date_for_view(@due_at)
expect(f(".due_date_display").text).not_to be_blank
expect(f(".due_date_display").text).not_to eq "Multiple Due Dates"
end
@ -82,4 +82,4 @@ describe "context modules" do
expect(f(".due_date_display").text).to eq "Multiple Due Dates"
end
end
end
end

View File

@ -46,7 +46,7 @@ describe "conversations new" do
user_session(@teacher)
conversations
compose course: @course, subject: 'Christmas', to: [@s1], body: 'The Fat Man cometh.', journal: true, send: true
time = format_time_for_view(Time.zone.now)
time = format_time_for_view(UserNote.last.updated_at)
remove_user_session
get student_user_notes_url
expect(f('.subject').text).to include_text('Christmas')
@ -76,7 +76,7 @@ describe "conversations new" do
replace_content(f('textarea'),'FJ Body text 2')
wait_for_ajaximations
f('.send_button').click
time = format_time_for_view(Time.zone.now)
time = format_time_for_view(UserNote.last.updated_at)
get student_user_notes_url
expect(f('.subject').text).to eq 'FJ Title 2'
expect(f('.user_content').text).to eq 'FJ Body text 2'
@ -207,4 +207,4 @@ describe "conversations new" do
expect(flash_message_present?(:success, /Message sent!/)).to be_truthy
end
end
end
end

View File

@ -33,7 +33,7 @@ describe "discussion availability" do
title: 'assignment topic title due date set',
message: 'assignment topic message',
assignment: assignment)
unlock_at_time = @discussion_topic1.delayed_post_at.strftime('%b %-d')
unlock_at_time = format_date_for_view(@discussion_topic1.delayed_post_at)
due_at_time = format_time_for_view(assignment.due_at)
get "/courses/#{@course.id}/discussion_topics"
expect(f(" .collectionViewItems .discussion[data-id = '#{@discussion_topic1.id}'] .discussion-date-available")).
@ -51,15 +51,12 @@ describe "discussion availability" do
student2 = user_with_pseudonym(username: 'student2@example.com', active_all: 1)
student_in_course(user: student2).accept!
user_session(student2)
unlock_at_time = @discussion_topic1.delayed_post_at.strftime('%b %-d')
unlock_at_time = format_date_for_view(@discussion_topic1.delayed_post_at)
get "/courses/#{@course.id}/discussion_topics"
expect(f(" .collectionViewItems .discussion[data-id = '#{@discussion_topic1.id}'] .discussion-date-available")).
to include_text("Not available until #{unlock_at_time}")
fln('assignment topic title not available').click
expect(f('.discussion-reply-action')).not_to be_present
sleep(15.seconds)
refresh_page
expect(f('.discussion-reply-action')).to be_present
end
it "should show delayed discussion created by student under 'discussions' section", priority: "1", test_id: 150510 do

View File

@ -85,17 +85,17 @@ describe "discussions" do
lock_at = Time.zone.now + 4.days
# set due_at, lock_at, unlock_at
ffj(".date_field[data-date-type='due_at']")[0].send_keys(due_at.strftime('%b %-d, %y'))
ffj(".date_field[data-date-type='unlock_at']")[0].send_keys(unlock_at.strftime('%b %-d, %y'))
ffj(".date_field[data-date-type='lock_at']")[0].send_keys(lock_at.strftime('%b %-d, %y'))
f(".date_field[data-date-type='due_at']").send_keys(format_date_for_view(due_at))
f(".date_field[data-date-type='unlock_at']").send_keys(format_date_for_view(unlock_at))
f(".date_field[data-date-type='lock_at']").send_keys(format_date_for_view(lock_at))
wait_for_ajaximations
expect_new_page_load { f('.form-actions button[type=submit]').click }
a = DiscussionTopic.last.assignment
expect(a.due_at.strftime('%b %-d, %y')).to eq due_at.to_date.strftime('%b %-d, %y')
expect(a.unlock_at.strftime('%b %-d, %y')).to eq unlock_at.to_date.strftime('%b %-d, %y')
expect(a.lock_at.strftime('%b %-d, %y')).to eq lock_at.to_date.strftime('%b %-d, %y')
expect(a.due_at.to_date).to eq due_at.to_date
expect(a.unlock_at.to_date).to eq unlock_at.to_date
expect(a.lock_at.to_date).to eq lock_at.to_date
end
it "should add an attachment to a graded topic", priority: "1", test_id: 270918 do
@ -243,17 +243,16 @@ describe "discussions" do
delayed_post_at = Time.zone.now - 10.days
lock_at = Time.zone.now - 5.days
date_format = '%b %-d, %Y'
f('input[type=text][name="delayed_post_at"]').send_keys(delayed_post_at.strftime(date_format))
f('input[type=text][name="lock_at"]').send_keys(lock_at.strftime(date_format))
f('input[type=text][name="delayed_post_at"]').send_keys(format_date_for_view(delayed_post_at))
f('input[type=text][name="lock_at"]').send_keys(format_date_for_view(lock_at))
expect_new_page_load { f('.form-actions button[type=submit]').click }
wait_for_ajaximations
topic.reload
expect(topic.delayed_post_at.strftime(date_format)).to eq delayed_post_at.strftime(date_format)
expect(topic.lock_at.strftime(date_format)).to eq lock_at.strftime(date_format)
expect(topic.delayed_post_at.to_date).to eq delayed_post_at.to_date
expect(topic.lock_at.to_date).to eq lock_at.to_date
expect(topic.locked?).to be_truthy
end
@ -267,16 +266,15 @@ describe "discussions" do
get url
delayed_post_at = Time.zone.now - 5.days
date_format = '%b %-d, %Y'
f('input[type=text][name="delayed_post_at"]').clear
f('input[type=text][name="delayed_post_at"]').send_keys(delayed_post_at.strftime(date_format))
f('input[type=text][name="delayed_post_at"]').send_keys(format_date_for_view(delayed_post_at))
expect_new_page_load { f('.form-actions button[type=submit]').click }
wait_for_ajaximations
topic.reload
expect(topic.delayed_post_at.strftime(date_format)).to eq delayed_post_at.strftime(date_format)
expect(topic.delayed_post_at.to_date).to eq delayed_post_at.to_date
expect(topic.active?).to be_truthy
expect(topic.locked?).to be_falsey
end

View File

@ -68,7 +68,7 @@ describe "discussions" do
wait_for_ajaximations
fj(".ic-tokeninput-option:visible:first").click
wait_for_ajaximations
fj(".datePickerDateField[data-date-type='due_at']:first").send_keys(due_at1.strftime('%b %-d, %y'))
fj(".datePickerDateField[data-date-type='due_at']:first").send_keys(format_date_for_view(due_at1))
f('#add_due_date').click
wait_for_ajaximations
@ -77,7 +77,7 @@ describe "discussions" do
wait_for_ajaximations
fj(".ic-tokeninput-option:visible:first").click
wait_for_ajaximations
fj(".datePickerDateField[data-date-type='due_at']:last").send_keys(due_at2.strftime('%b %-d, %y'))
fj(".datePickerDateField[data-date-type='due_at']:last").send_keys(format_date_for_view(due_at2))
expect_new_page_load { f('.form-actions button[type=submit]').click }
topic = DiscussionTopic.last
@ -85,9 +85,9 @@ describe "discussions" do
overrides = topic.assignment.assignment_overrides
expect(overrides.count).to eq 2
default_override = overrides.detect { |o| o.set_id == default_section.id }
expect(default_override.due_at.strftime('%b %-d, %y')).to eq due_at1.to_date.strftime('%b %-d, %y')
expect(default_override.due_at.to_date).to eq due_at1.to_date
other_override = overrides.detect { |o| o.set_id == new_section.id }
expect(other_override.due_at.strftime('%b %-d, %y')).to eq due_at2.to_date.strftime('%b %-d, %y')
expect(other_override.due_at.to_date).to eq due_at2.to_date
end
it "should validate that a group category is selected", priority: "1", test_id: 150469 do
@ -146,7 +146,7 @@ describe "discussions" do
type_in_tiny('textarea[name=message]', 'This is the discussion description.')
target_time = 1.day.from_now
unlock_text = format_time_for_view(target_time)
unlock_text_index_page = target_time.strftime('%b %-d')
unlock_text_index_page = format_date_for_view(target_time, :short)
f('#delayed_post_at').send_keys(unlock_text)
expect_new_page_load {submit_form('.form-actions')}
expect(f('.entry-content').text).to include("This topic is locked until #{unlock_text}")

View File

@ -85,8 +85,8 @@ describe "discussions overrides" do
context "outside discussions page" do
before do
@default_due = Time.zone.now.advance(days:1).strftime('%b %-d')
@override_due = Time.zone.now.advance(days:2).strftime('%b %-d')
@default_due = format_date_for_view(Time.zone.now.advance(days:1))
@override_due = format_date_for_view(Time.zone.now.advance(days:2))
end
it "should show due dates in mouse hover in the assignments index page", priority: "2", test_id: 114318 do

View File

@ -134,14 +134,14 @@ describe "threaded discussions" do
edit_entry(reply, "Reply edited")
reply.reload
edited_at = reply[:updated_at].to_time.utc.strftime('%b %-d at %-l:%M%P')
edited_at = format_time_for_view(reply.updated_at)
displayed_edited_at = f('.discussion-fyi').text
# Verify displayed edit time includes object update time
expect(displayed_edited_at).to include(edited_at)
# Verify edit time is later than reply time
expect(replied_at).to be < (edited_at)
# Verify edit time is different than reply time
expect(replied_at).not_to eql(edited_at)
end
it "should delete a reply", priority: "1", test_id: 150515 do

View File

@ -28,7 +28,7 @@ describe "discussions" do
user_session(@student1)
find_vdd_time(@assignment)
get "/courses/#{@course.id}/discussion_topics"
expect(f("#open-discussions .discussion-date-available").text).to include("Available until #{format_date_for_view(@assignment.lock_at)}")
expect(f("#open-discussions .discussion-date-available").text).to include("Available until #{format_date_for_view(@assignment.lock_at, :short)}")
expect(f("#open-discussions .discussion-due-date").text).to include("Due #{@due_at_time}")
expect_new_page_load{f('#open-discussions .discussion-title').click}
expect(f('.discussion-reply-action')).to be_present
@ -42,7 +42,7 @@ describe "discussions" do
get "/courses/#{@course.id}/discussion_topics"
keep_trying_until do
expect(f("#open-discussions .discussion-date-available").text).
to include("Not available until #{format_date_for_view(@override.unlock_at)}")
to include("Not available until #{format_date_for_view(@override.unlock_at, :short)}")
expect(f("#open-discussions .discussion-due-date").text).to include("Due #{@due_at_time}")
end
expect_new_page_load{f('#open-discussions .discussion-title').click}
@ -87,8 +87,8 @@ describe "discussions" do
:allow_multiple_enrollments => true, :associated_user_id => student1.id)
@course.enroll_user(observer, 'ObserverEnrollment', :enrollment_state => 'active',
:associated_user_id => student2.id)
lock_at_time = @quiz.lock_at.strftime('%b %-d')
unlock_at_time = @override.unlock_at.strftime('%b %-d')
lock_at_time = format_date_for_view(@quiz.lock_at)
unlock_at_time = format_date_for_view(@override.unlock_at)
user_session(observer)
get "/courses/#{@course.id}/discussion_topics"
driver.mouse.move_to fln('Multiple Dates')

View File

@ -64,10 +64,10 @@ describe "post grades to sis" do
due_at = Time.zone.now + 3.days
get_post_grades_dialog
expect(f('#assignment-errors').text).to include("1 Assignment with Errors")
fj(".assignment-due-at").send_keys(due_at.strftime('%b %-d, %y'))
f(".assignment-due-at").send_keys(format_date_for_view(due_at))
f(' .form-dialog-content').click
proceed_form('.form-controls')
expect(f('.assignments-to-post-count').text).to include("You are ready to post 1 assignment")
end
end
end
end

View File

@ -91,23 +91,14 @@ describe "eportfolios" do
it "should validate time stamp on ePortfolio", priority: "2" do
# Freezes time to 2 days from today.
old_time = 2.days.from_now.utc.beginning_of_hour
Timecop.freeze(old_time) do
current_time = old_time.strftime('%b %-d at %-l') << old_time.strftime('%p').downcase
new_time = 2.days.from_now.utc.beginning_of_hour
Timecop.freeze(new_time) do
current_time = format_time_for_view(new_time)
# Saves an entry to initiate an update.
@eportfolio_entry.save!
# Checks for correct time.
get "/dashboard/eportfolios"
expect(f(".updated_at")).to include_text(current_time)
# Freezes time to 3 days from previous date.
new_time = Timecop.freeze(Date.today + 3).utc
current_time = new_time.strftime('%b %-d at %-l') << new_time.strftime('%p').downcase
# Saves to initiate an update.
@eportfolio_entry.save!
# Checks for correct time, then unfreezes time.
get "/dashboard/eportfolios"
expect(f(".updated_at")).to include_text(current_time)
end
end

View File

@ -4,9 +4,8 @@ describe 'Account Grading Periods' do
include_examples "in-process server selenium tests"
let(:title) {'hi'}
let(:start_date) { 3.months.from_now.strftime('%b %-d') }
let(:end_date) { (4.months.from_now - 1.day).strftime('%b %-d') }
let(:date_time_format) {'%b %-d, %Y at %-l:%M%P'} # e.g. May 28, 2015 at 8:58pm
let(:start_date) { format_date_for_view(3.months.from_now) }
let(:end_date) { format_date_for_view(4.months.from_now - 1.day) }
before(:each) do
course_with_admin_logged_in
@ -46,10 +45,11 @@ describe 'Account Grading Periods' do
f('#update-button').click
refresh_page
expect(ff('.grading-period').length).to eq(1)
id = GradingPeriod.where(title: title).first.id
new_grading_period = GradingPeriod.where(title: title).first
id = new_grading_period.id
expect(f("#period_title_#{id}")).to have_value(title)
expect(f("#period_start_date_#{id}")).to have_value("#{start_date}, #{Time.zone.now.year} at 12:00am")
expect(f("#period_end_date_#{id}")).to have_value("#{end_date}, #{Time.zone.now.year} at 11:59pm")
expect(f("#period_start_date_#{id}")).to have_value(format_time_for_view(new_grading_period.start_date, :medium))
expect(f("#period_end_date_#{id}")).to have_value(format_time_for_view(new_grading_period.end_date, :medium))
end
it 'flashes error if missing info', priority: "1", test_id: 202310 do
@ -101,14 +101,14 @@ describe 'Account Grading Periods' do
f('#update-button').click
wait_for_ajax_requests
# check UI
expect(f("#period_title_#{id}")).to have_value(title)
expect(f("#period_start_date_#{id}")).to have_value("#{start_date}, #{Time.zone.now.year} at 12:00am")
expect(f("#period_end_date_#{id}")).to have_value("#{end_date}, #{Time.zone.now.year} at 11:59pm")
# check underlying object
account_grading_period.reload
expect(account_grading_period.title).to eq(title)
# check UI
expect(f("#period_title_#{id}")).to have_value(title)
expect(f("#period_start_date_#{id}")).to have_value(format_time_for_view(account_grading_period.start_date, :medium))
expect(f("#period_end_date_#{id}")).to have_value(format_time_for_view(account_grading_period.end_date, :medium))
end
it 'verifies with alert modal before deletion', priority: "1", test_id: 202313 do
@ -148,8 +148,8 @@ describe 'Account Grading Periods' do
get "/accounts/#{sub_account.id}/grading_standards"
expect(ff('.grading-period').length).to eq(1)
expect(f("#period_title_#{@id}")).to have_value(@account_grading_period.title)
expect(f("#period_start_date_#{@id}")).to have_value(@account_grading_period.start_date.strftime(date_time_format))
expect(f("#period_end_date_#{@id}")).to have_value(@account_grading_period.end_date.strftime(date_time_format))
expect(f("#period_start_date_#{@id}")).to have_value(format_time_for_view(@account_grading_period.start_date, :medium))
expect(f("#period_end_date_#{@id}")).to have_value(format_time_for_view(@account_grading_period.end_date, :medium))
end
it 'is inherited by sub-account, editing from sub-account page creates a copy', priority: "1", test_id: 250248 do
@ -175,8 +175,8 @@ describe 'Account Grading Periods' do
# check UI
expect(f("#period_title_#{new_id}")).to have_value(title)
expect(f("#period_start_date_#{new_id}")).to have_value("#{start_date}, #{Time.zone.now.year} at 12:00am")
expect(f("#period_end_date_#{new_id}")).to have_value("#{end_date}, #{Time.zone.now.year} at 11:59pm")
expect(f("#period_start_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.start_date, :medium))
expect(f("#period_end_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.end_date, :medium))
end
it 'is inherited by course, reads account grading period', priority: "1", test_id: 250249 do
@ -209,8 +209,8 @@ describe 'Account Grading Periods' do
# check UI
expect(f("#period_title_#{new_id}")).to have_value(title)
expect(f("#period_start_date_#{new_id}")).to have_value("#{start_date}, #{Time.zone.now.year} at 12:00am")
expect(f("#period_end_date_#{new_id}")).to have_value("#{end_date}, #{Time.zone.now.year} at 11:59pm")
expect(f("#period_start_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.start_date, :medium))
expect(f("#period_end_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.end_date, :medium))
end
end # as admin
@ -250,8 +250,8 @@ describe 'Account Grading Periods' do
# check UI
expect(f("#period_title_#{new_id}")).to have_value(title)
expect(f("#period_start_date_#{new_id}")).to have_value("#{start_date}, #{Time.zone.now.year} at 12:00am")
expect(f("#period_end_date_#{new_id}")).to have_value("#{end_date}, #{Time.zone.now.year} at 11:59pm")
expect(f("#period_start_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.start_date, :medium))
expect(f("#period_end_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.end_date, :medium))
end
it 'is inherited by sub-account, deleting as sub-admin reverts to account grading period', priority: "1", test_id: 250257 do
@ -303,8 +303,8 @@ describe 'Account Grading Periods' do
# check UI
expect(f("#period_title_#{new_id}")).to have_value(title)
expect(f("#period_start_date_#{new_id}")).to have_value("#{start_date}, #{Time.zone.now.year} at 12:00am")
expect(f("#period_end_date_#{new_id}")).to have_value("#{end_date}, #{Time.zone.now.year} at 11:59pm")
expect(f("#period_start_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.start_date, :medium))
expect(f("#period_end_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.end_date, :medium))
end
it 'is inherited by course, deleting reverts to account grading period', priority: "1", test_id: 250259 do

View File

@ -143,9 +143,8 @@ describe 'Course Grading Periods Inheritance' do
include_examples 'in-process server selenium tests'
let(:title) {'hi'}
let(:start_date) { 3.months.from_now.strftime('%b %-d') }
let(:end_date) { (4.months.from_now - 1.day).strftime('%b %-d') }
let(:date_time_format) {'%b %-d, %Y at %-l:%M%P'} # e.g. May 28, 2015 at 8:58pm
let(:start_date) { format_date_for_view(3.months.from_now) }
let(:end_date) { format_date_for_view(4.months.from_now - 1.day) }
before(:each) do
course_with_admin_logged_in
@ -210,8 +209,8 @@ describe 'Course Grading Periods Inheritance' do
# check UI
expect(f("#period_title_#{new_id}")).to have_value(title)
expect(f("#period_start_date_#{new_id}")).to have_value("#{start_date}, #{Time.zone.now.year} at 12:00am")
expect(f("#period_end_date_#{new_id}")).to have_value("#{end_date}, #{Time.zone.now.year} at 11:59pm")
expect(f("#period_start_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.start_date, :medium))
expect(f("#period_end_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.end_date, :medium))
end
end # as admin
@ -243,8 +242,8 @@ describe 'Course Grading Periods Inheritance' do
# check UI
expect(f("#period_title_#{new_id}")).to have_value(title)
expect(f("#period_start_date_#{new_id}")).to have_value("#{start_date}, #{Time.zone.now.year} at 12:00am")
expect(f("#period_end_date_#{new_id}")).to have_value("#{end_date}, #{Time.zone.now.year} at 11:59pm")
expect(f("#period_start_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.start_date, :medium))
expect(f("#period_end_date_#{new_id}")).to have_value(format_time_for_view(new_grading_period.end_date, :medium))
end
end # as sub-admin

View File

@ -8,12 +8,12 @@ module AssignmentOverridesSeleniumHelper
end
def fill_assignment_overrides
fj(".datePickerDateField[data-date-type='due_at']")
.send_keys(due_at.strftime('%b %-d, %y'))
fj(".datePickerDateField[data-date-type='unlock_at']")
.send_keys(unlock_at.strftime('%b %-d, %y'))
fj(".datePickerDateField[data-date-type='lock_at']")
.send_keys(lock_at.strftime('%b %-d, %y'))
f(".datePickerDateField[data-date-type='due_at']")
.send_keys(format_date_for_view(due_at))
f(".datePickerDateField[data-date-type='unlock_at']")
.send_keys(format_date_for_view(unlock_at))
f(".datePickerDateField[data-date-type='lock_at']")
.send_keys(format_date_for_view(lock_at))
end
def update_assignment!
@ -33,12 +33,9 @@ module AssignmentOverridesSeleniumHelper
end
def compare_assignment_times(a)
expect(a.due_at.strftime('%b %-d, %y')).to eq due_at.to_date
.strftime('%b %-d, %y')
expect(a.unlock_at.strftime('%b %-d, %y')).to eq unlock_at.to_date
.strftime('%b %-d, %y')
expect(a.lock_at.strftime('%b %-d, %y')).to eq lock_at.to_date
.strftime('%b %-d, %y')
expect(a.due_at.to_date).to eq due_at.to_date
expect(a.unlock_at.to_date).to eq unlock_at.to_date
expect(a.lock_at.to_date).to eq lock_at.to_date
end
def create_assignment!
@ -245,28 +242,30 @@ module AssignmentOverridesSeleniumHelper
def set_quiz_dates_for_section_a
now = Time.zone.now
@due_at_a = now.advance(days: 2)
@unlock_at_a = now
@lock_at_a = now.advance(days: 3)
@quiz.update_attribute(:due_at, @due_at_a)
@quiz.update_attribute(:unlock_at, @unlock_at_a)
@quiz.update_attribute(:lock_at, @lock_at_a)
@quiz.update_attribute(:due_at, now.advance(days: 2))
@quiz.update_attribute(:unlock_at, now)
@quiz.update_attribute(:lock_at, now.advance(days: 3))
@due_at_a = @quiz.due_at
@unlock_at_a = @quiz.unlock_at
@lock_at_a = @quiz.lock_at
end
def set_quiz_dates_for_section_b
now = Time.zone.now
@due_at_b = now.advance(days: 4)
@unlock_at_b = now.advance(days: 1)
@lock_at_b = now.advance(days: 4)
add_user_specific_due_date_override(
@quiz,
section: @section_b,
due_at: @due_at_b,
unlock_at: @unlock_at_b,
lock_at: @lock_at_b
due_at: now.advance(days: 4),
unlock_at: now.advance(days: 1),
lock_at: now.advance(days: 4)
)
@due_at_b = @override.due_at
@unlock_at_b = @override.unlock_at
@lock_at_b = @override.lock_at
end
def obtain_due_date(section)

View File

@ -127,7 +127,7 @@ module Calendar2Common
def quick_jump_to_date(text)
f('.navigation_title').click
date_input = keep_trying_until { f('.date_field') }
date_input = f('.date_field')
date_input.send_keys(text + "\n")
wait_for_ajaximations
end
@ -249,7 +249,7 @@ module Calendar2Common
def assert_edit_modal_date(due_at)
move_to_click('.fc-event')
wait_for_ajaximations
expect(f('.event-details-timestring')).to include_text("#{due_at.utc.strftime('%b %-d')}")
expect(f('.event-details-timestring')).to include_text(format_date_for_view(due_at))
end
def assert_title(title,agenda_view)
@ -264,7 +264,7 @@ module Calendar2Common
def assert_agenda_view(title,due)
load_agenda_view
assert_title(title,true)
expect(f('.navigation_title')).to include_text(due.utc.strftime("%b %-d, %Y"))
expect(f('.navigation_title')).to include_text(format_date_for_view(due))
end
def assert_week_view(title,due)

View File

@ -162,13 +162,13 @@ describe 'editing a quiz' do
select_first_override_section(default_section.name)
first_due_at_element.clear
first_due_at_element.
send_keys(default_section_due.strftime('%b %-d, %y'))
send_keys(format_date_for_view(default_section_due))
add_override
select_last_override_section(other_section.name)
last_due_at_element.
send_keys(other_section_due.strftime('%b %-d, %y'))
send_keys(format_date_for_view(other_section_due))
expect_new_page_load do
click_save_settings_button
wait_for_ajax_requests
@ -176,11 +176,11 @@ describe 'editing a quiz' do
overrides = @quiz.reload.assignment_overrides
expect(overrides.size).to eq 2
default_override = overrides.detect { |o| o.set_id == default_section.id }
expect(default_override.due_at.strftime('%b %-d, %y')).
to eq default_section_due.to_date.strftime('%b %-d, %y')
expect(default_override.due_at.to_date).
to eq default_section_due.to_date
other_override = overrides.detect { |o| o.set_id == other_section.id }
expect(other_override.due_at.strftime('%b %-d, %y')).
to eq other_section_due.to_date.strftime('%b %-d, %y')
expect(other_override.due_at.to_date).
to eq other_section_due.to_date
end
context 'when the quiz has a submission' do

View File

@ -21,7 +21,7 @@ describe 'viewing a quiz with variable due dates on the quizzes index page' do
it 'shows the availability dates for Section A', priority: "1", test_id: 282389 do
expect(f('.date-available')).to include_text("Available until "\
"#{format_date_for_view(@lock_at_a)}")
"#{format_date_for_view(@lock_at_a, :short)}")
end
end
@ -39,7 +39,7 @@ describe 'viewing a quiz with variable due dates on the quizzes index page' do
it 'shows the availability dates for Section B', priority: "1", test_id: 282391 do
expect(f('.date-available')).to include_text("Not available until "\
"#{format_date_for_view(@unlock_at_b)}")
"#{format_date_for_view(@unlock_at_b, :short)}")
end
end
end

View File

@ -18,28 +18,28 @@ describe 'viewing a quiz with variable due dates on the quizzes index page' do
it 'shows the due dates for Section A', priority: "1", test_id: 282167 do
validate_vdd_quiz_tooltip_dates(
'.date-due',
"Everyone else\n#{format_date_for_view(@due_at_a)}"
"Everyone else\n#{format_date_for_view(@due_at_a, :short)}"
)
end
it 'shows the due dates for Section B', priority: "1", test_id: 315661 do
validate_vdd_quiz_tooltip_dates(
'.date-due',
"#{@section_b.name}\n#{format_date_for_view(@due_at_b)}"
"#{@section_b.name}\n#{format_date_for_view(@due_at_b, :short)}"
)
end
it 'shows the availability dates for Section A', priority: "1", test_id: 282393 do
validate_vdd_quiz_tooltip_dates(
'.date-available',
"Everyone else\nAvailable until #{format_date_for_view(@lock_at_a)}"
"Everyone else\nAvailable until #{format_date_for_view(@lock_at_a, :short)}"
)
end
it 'shows the availability dates for Section B', priority: "1", test_id: 315663 do
validate_vdd_quiz_tooltip_dates(
'.date-available',
"#{@section_b.name}\nNot available until #{format_date_for_view(@unlock_at_b)}"
"#{@section_b.name}\nNot available until #{format_date_for_view(@unlock_at_b, :short)}"
)
end
end

View File

@ -2,12 +2,21 @@ module CustomDateHelpers
include TextHelper
# Formatted output: Mmm d, e.g. 'Jan 1'
def format_date_for_view(date, format = :short)
I18n.l(date.to_date, format: format)
def format_date_for_view(date, format = nil)
if format
I18n.l(date.to_date, format: format)
else
date_string(date, :no_words)
end
end
# Formatted output: Mmm d at h:mm, e.g. 'Jan 1 at 1:01pm'
def format_time_for_view(time)
datetime_string(time, :no_words).gsub(/ +/, ' ')
def format_time_for_view(time, date_format = nil)
if date_format
date = format_date_for_view(time.to_date, date_format)
"#{date} at #{time_string(time)}"
else
datetime_string(time, :no_words).gsub(/ +/, ' ')
end
end
end