zui icon indicating copy to clipboard operation
zui copied to clipboard

Flaky System Test: Export Queries

Open jameskerr opened this issue 2 years ago • 0 comments

Failed with these errors:

      19 | test("clicking the export button", async () => {
      20 |   const sidebar = screen.getByRole("complementary", {name: "sidebar"})
    > 21 |   const brimFolder = within(sidebar).getByText("Brim")
         |                                      ^
      22 |   await system.rightClick(brimFolder)
      23 |   system.mockSaveDialog({canceled: false, filePath})
      24 |   const menuItem = await screen.findByText("Export Folder as JSON")

      at Object.getElementError (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/config.js:37:19)
      at node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/query-helpers.js:90:38
      at node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/query-helpers.js:62:17
      at getByText (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/query-helpers.js:111:19)
      at _callee2$ (test/system/export-queries.test.ts:21:38)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:281:22)
      at Generator.prototype.<computed> [as next] (node_modules/regenerator-runtime/runtime.js:106:21)
      at asyncGeneratorStep (test/system/export-queries.test.ts:15:103)
      at _next (test/system/export-queries.test.ts:17:194)
      at test/system/export-queries.test.ts:17:364
      at Object.<anonymous> (test/system/export-queries.test.ts:17:97)

  ● canceling the export

    TestingLibraryElementError: Unable to find an element with the text: Brim. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

The test code:

import {screen, within} from "@testing-library/react"
import fsExtra from "fs-extra"
import os from "os"
import path from "path"
import {SystemTest} from "./system-test"

const filePath = path.join(os.tmpdir(), "myQueries.json")
const system = new SystemTest("export-queries")

beforeAll(async () => {
  system.mountApp()
  await system.importFile("sample.tsv")
})

afterEach(() => {
  fsExtra.removeSync(filePath)
})

test("clicking the export button", async () => {
  const sidebar = screen.getByRole("complementary", {name: "sidebar"})
  const brimFolder = within(sidebar).getByText("Brim")
  await system.rightClick(brimFolder)
  system.mockSaveDialog({canceled: false, filePath})
  const menuItem = await screen.findByText("Export Folder as JSON")
  await system.click(menuItem)
  await screen.findByText("Export Complete")

  expect(fsExtra.statSync(filePath).size).toBe(2888)
})

test("canceling the export", async () => {
  const sidebar = screen.getByRole("complementary", {name: "sidebar"})
  const brimFolder = within(sidebar).getByText("Brim")
  await system.rightClick(brimFolder)
  system.mockSaveDialog({canceled: true, filePath})
  const menuItem = await screen.findByText("Export Folder as JSON")
  await system.click(menuItem)

  expect(await fsExtra.pathExists(filePath)).toBe(false)
})

jameskerr avatar Jan 13 '22 18:01 jameskerr