 # Create a mock window.location, with
 # sensible MeFi defaults.
 makeLocation = (location) ->
-  location ||= {}
+  location ?= {}
 
   # Abort if we accidentally used a camelcase name.
   ['hostName', 'pathName'].forEach (key) ->
     if location.hasOwnProperty(key) 
       throw new Error("makeLocation: Invalid location key: #{key}")
 
-  location['protocol'] ||= "https:"
-  location['hostname'] ||= "www.metafilter.com"
-  location['pathname'] ||= "/"
+  location['protocol'] ?= "https:"
+  location['hostname'] ?= "www.metafilter.com"
+  location['pathname'] ?= "/"
   if !/^\//.test(location['pathname'])
     throw new Error("makeLocation: pathname needs to start with a slash: " +
       location['pathname'])
   if /#/.test(location['pathname'])
     throw new Error("makeLocation: Get that hash out of the pathname")
 
-  location['hash']     ||= ''
+  location['hash']     ?= ''
   if !/(^$)|^#/.test(location['hash'])
     throw new Error("makeLocation: Hash needs to be empty string or start with #: " +
       location['hash'])
 
-  location['href']     ||= location.protocol + location.hostname + location.pathname
+  location['href']     ?= location.protocol + location.hostname + location.pathname
   return location
 
 exports['test sessionStorage mock'] = (test) ->

    newPost: 'https://ask.metafilter.com/contribute/post.cfm'
    postPreview: 'post_preview.cfm'
    commentPreview: '/contribute/post_comment_preview.mefi#commentpreview'




#doTestCase = require('../lib/test-utils').doTestCase



# Simulate previewing a comment on the server side
exports['simulate server-side preview of a comment'] = (test) ->
  sessionStorage = makeSessionStorage()

  mdCommentText = "I really liked this show and/or movie!"
  simulateSave
    sessionStorage: sessionStorage
    site: 'fanFare'
    type: 'comment'
    mdCommentText: mdCommentText

  test.strictEqual(sessionStorage.length, 1, "Comment was saved")

  loadResults = simulateLoad
    sessionStorage: sessionStorage
    site: 'fanFare'
    type: 'comment'
  savedDataJson = loadResults.savedDataJson
  sr            = loadResults.sr
  storageKey    = loadResults.storageKey

  test.strictEqual(mdCommentText, savedDataJson.comment, "comment was restored correctly")
  test.strictEqual(null,          savedDataJson.extended, "extended was restored correctly")

  storedItem = sessionStorage.getItem(storageKey)
  test.strictEqual(storedItem, null, "Data was removed from session storage")
  test.strictEqual(sessionStorage.length, 0, "Nothing left in session storage")  

  test.done()

