   names: ['ChallengeTest', 'challenge']
   description: "Tests the 'Challenge a player process"
   numTests: 17
+
   testBody: (test) =>
   # Be sure not to use the 'createGame' shortcut.
     SHINDOU_EMAIL = 'shindou@ki-in.jp'

      @assertNumGames test, 1, 0

    # select the most recent game
    casper.thenClick (@lastGameSelector true), ->
      # on the game page is a game chat.
      test.assertExists '.game-chat', 'The game chat does exist.'
      form_values = 'input[name="comment"]' : MY_CHAT[0]
      # The final 'true' argument means that the form is submitted.
      @fillSelectors 'form#chat-form', form_values, true
      comments_selector = '.game-chat .chat-comments .chat-comment-black'
      casper.waitForSelector comments_selector

    createLoginSession TWO_EMAIL
    casper.thenOpen serverUrl, =>
      @assertNumGames test, 0, 1

    casper.thenClick (@lastGameSelector false), ->
      # on the game page is a game chat.
      test.assertExists '.game-chat', 'The game chat does exist.'
      comments_selector = '.game-chat .chat-comments .chat-comment-black'
      test.assertSelectorHasText comments_selector, MY_CHAT[0],
                 "Player one's comment has appeared in the chat area."

      form_values = 'input[name="comment"]' : MY_CHAT[1]
      # The final 'true' argument means that the form is submitted.
      @fillSelectors 'form#chat-form', form_values, true


registerTest new BasicChatTest


class BasicChatTest extends BrowserTest
  names: ['BasicChatTest', 'chat']
  description: "Very basic chat functionality test"
  numTests: 27

  testBody: (test) =>
    addComment = (comment) ->
      form_values = 'input[name="comment"]' : comment
      # The final 'true' argument means that the form is submitted.
      casper.fillSelectors 'form#chat-form', form_values, true

    checkComment = (color, comment, testMessage) ->
      casper.waitForText comment, ->
        comments_selector = ".game-chat .chat-comments .chat-comment-#{color}"
        test.assertSelectorHasText comments_selector, comment, testMessage

    ONE_EMAIL = 'player@one.com'
    TWO_EMAIL = 'playa@dos.es'

    ONE_CHAT = ['Are you dancing?', "I'm asking"]
    TWO_CHAT =  ['Are you asking?', "I'm dancing"]

    clearGamesForPlayer ONE_EMAIL
    clearGamesForPlayer TWO_EMAIL
