 
           it 'should show the visit dates', ->
             modelingTablesFinder.then (tables) ->
-              # The expected visit dates are the first column of the first
-              # table.
-              referenceTable = _.first(tables)
-              expect(referenceTable, 'The reference modeling Table 1 is' +
-                                     ' missing')
-                .to.exist
-              expected = null
-              referenceTable.body().then (rows) ->
-                expected = (_.first(columns) for columns in rows)
+              expect(tables.length, 'The reference modeling table count' +
+                                     ' is incorrect')
+                .to.equal(3)
+              allRows = (table.body() for table in tables)
+              # The 2D table x visit date array.
+              allDateCols = (_.first(col) for col in rows for rows in allRows)
+              dateFinders = (col.text() for col in rows for rows in allDateCols)
+              webdriver.promise.all(dateFinders).then (allDates) ->
+                # The expected visit dates are the first column of the first
+                # table.
+                expected = _.first(allDates)
                 for date, rowNdx in expected
                   expect(date, "The table 1 row #{ rowNdx + 1 } visit" +
                                " date is missing")
                     .to.exist.and.not.be.empty
                 # The date values for every remaining table should be
                 # consistent with those of the first table.
-                for table, tblNdx in _.tail(tables)
-                  table.body().then (rows) ->
-                    for columns, rowNdx in rows
-                      date = _.first(columns)
-                      expect(date, "The table #{ tblNdx + 2 } row" +
-                                   " #{ rowNdx + 1 } visit date is missing")
-                        .to.exist
-                      expect(date, "The table #{ tblNdx + 2 } row" +
-                                   " #{ rowNdx + 1 } visit date is incorrect")
-                        .to.equal(expected[rowNdx])
-
-          it 'should have seven Ktrans table columns', ->
+                for dates, tblNdx in _.tail(allDates)
+                  for date, rowNdx in dates
+                    expect(date, "The table #{ tblNdx + 2 } row" +
+                                 " #{ rowNdx + 1 } visit date is missing")
+                      .to.exist
+                    expect(date, "The table #{ tblNdx + 2 } row" +
+                                 " #{ rowNdx + 1 } visit date is incorrect")
+                      .to.equal(expected[rowNdx])
+
+          it 'should have seven Ktrans table row', ->
             modelingTablesFinder.then (tables) ->
               # The KTrans table is the first table.
               table = _.first(tables)
               table.body().then (rows) ->
                 for row, rowNdx in rows
                   expect(row.length, "The Ktrans table row #{ rowNdx + 1 }" +
-                                     " column count is incorrect").to.equal(7)
-
-          it 'should have three non-Ktrans table columns', ->
+                                     " column count is incorrect")
+                    .to.equal(7)
+
+          it 'should have three non-Ktrans table row', ->
             modelingTablesFinder.then (tables) ->
               # The KTrans table is the first table.
               tables = _.tail(tables)

                  for row, rowNdx in rows
                    expect(row.length,
                           "The table #{ tblNdx + 2 } row #{ rowNdx + 1 }" +
                           " column count is incorrect").to.equal(3)

          it 'should not have a blank non-percent change value', ->
            modelingTablesFinder.then (tables) ->
              for table, tblNdx in tables
                table.body().then (rows) ->
                  for columns, rowNdx in rows
                    # The odd columns hold non-percent change values.
                    for colNdx in _.range(1, columns.length, 2)
                      value = columns[colNdx]
                      expect(value, "Imaging Profile table #{ tblNdx + 1 } body" +
                                    " row #{ rowNdx + 1 } percent change column" +
                                    " #{ colNdx + 1 } is not blank")
                        .to.not.be.empty

          it 'should have blank percent values in the first row', ->
            modelingTablesFinder.then (tables) ->
              for table, tblNdx in tables
                table.body().then (rows) ->
                  columns = _.first(rows)
                  expect(columns, "Imaging Profile table #{ tblNdx + 1 } body" +
                                  " row 0 has no columns")
                    .to.exist.and.not.be.empty
                  # The percent change is in the third, fifth and seventh column.
                  # The percent changes of the first row are blank.
                  # The odd columns hold non-percent change values.
                  for colNdx in _.range(2, columns.length, 2)
                    value = columns[colNdx]
                    expect(value, "Imaging Profile table #{ tblNdx + 1 } body" +
                                  " row 0 percent change column #{ colNdx + 1 }" +
                                  " is not blank").to.be.empty

          it 'should not have a blank percent value in the remaining rows', ->
            modelingTablesFinder.then (tables) ->
              for table, tblNdx in tables
                table.body().then (rows) ->
                  for columns, rowNdx in _.tail(rows)
                    for colNdx in _.range(2, columns.length, 2)
                      value = columns[colNdx]
                      expect(value, "Imaging Profile table #{ tblNdx + 1 } body" +
                                    " row #{ rowNdx + 2 } percent change column" +
                                    " #{ colNdx + 1 } is blank")
                        .to.not.be.empty

    describe 'Clinical Profile', ->
      profileFinder = null

_ = require 'lodash'

webdriver = require 'selenium-webdriver'

expect = require('./helpers/expect')()

