 describe "databases list page", ->
   databasesList = null
+
+  shouldShowDatabase = (name) ->
+    expect(databasesList.column("database.name")).toContain(name)
+
+  shouldShowAllDatabases = ->
+    shouldShowDatabase("first_database")
+    shouldShowDatabase("second_database")
+    shouldShowDatabase("third_database")
 
   beforeEach ->
     browser().navigateTo("/e2e/load_fixtures")

  describe "filtering by database name", ->
    it "displays all databases when the filter is not provided", ->
      input("value").enter("")
      expect(databasesList.column("database.name")).toContain("first_database")
      expect(databasesList.column("database.name")).toContain("second_database")
      expect(databasesList.column("database.name")).toContain("third_database")

    it "filters by database name", ->
      input("value").enter("first")
      expect(databasesList.column("database.name")).toContain("first_database")

      input("value").enter("second")
      expect(databasesList.column("database.name")).toContain("second_database")

      input("value").enter("not existing database")
      expect(databasesList.count()).toBe(0)


    it "displays all records when the filter is cleared", ->
      element("button:contains('Clear')").click()
      shouldShowAllDatabases()

  describe "delete a database", ->
    deleteDatabase = (name) ->
