1
0
Fork 0
mirror of synced 2024-08-23 05:51:29 +12:00

updatee test assertion

This commit is contained in:
Martin McKeaveney 2024-05-15 14:31:29 +01:00
parent d89cd0955e
commit fddf82eaa7

View file

@ -1,12 +1,11 @@
import { it, expect, describe, vi } from "vitest" import { it, expect, describe, vi } from "vitest"
import Dropzone from "./Dropzone.svelte" import Dropzone from "./Dropzone.svelte"
import { render, fireEvent } from "@testing-library/svelte" import { render, fireEvent } from "@testing-library/svelte"
import { notifications } from "@budibase/bbui"; import { notifications } from "@budibase/bbui"
import { admin } from "stores/portal" import { admin } from "stores/portal"
vi.spyOn(notifications, "error").mockImplementation(() => {}) vi.spyOn(notifications, "error").mockImplementation(() => {})
describe("Dropzone", () => { describe("Dropzone", () => {
let instance = null let instance = null
@ -26,15 +25,13 @@ describe("Dropzone", () => {
}) })
instance = render(Dropzone, { props: { fileSizeLimit: 1000000 } }) // 1MB instance = render(Dropzone, { props: { fileSizeLimit: 1000000 } }) // 1MB
const fileInput = instance.getByLabelText("Select a file to upload") const fileInput = instance.getByLabelText("Select a file to upload")
const file = new File( const file = new File(["hello".repeat(2000000)], "hello.png", {
["hello".repeat(2000000)], type: "image/png",
"hello.png", })
{
type: "image/png"
}
)
await fireEvent.change(fileInput, { target: { files: [file] } }) await fireEvent.change(fileInput, { target: { files: [file] } })
expect(notifications.error).toHaveBeenCalledWith("Files cannot exceed 1MB. Please try again with smaller files.") expect(notifications.error).toHaveBeenCalledWith(
"Files cannot exceed 1MB. Please try again with smaller files."
)
}) })
it("Ensure the file size error message is not shown when running on self host", async () => { it("Ensure the file size error message is not shown when running on self host", async () => {
@ -44,14 +41,10 @@ describe("Dropzone", () => {
}) })
instance = render(Dropzone, { props: { fileSizeLimit: 1000000 } }) // 1MB instance = render(Dropzone, { props: { fileSizeLimit: 1000000 } }) // 1MB
const fileInput = instance.getByLabelText("Select a file to upload") const fileInput = instance.getByLabelText("Select a file to upload")
const file = new File( const file = new File(["hello".repeat(2000000)], "hello.png", {
["hello".repeat(2000000)], type: "image/png",
"hello.png", })
{
type: "image/png"
}
)
await fireEvent.change(fileInput, { target: { files: [file] } }) await fireEvent.change(fileInput, { target: { files: [file] } })
expect(notifications.error).not.toHaveBeenCalledWith("Files cannot exceed 1MB. Please try again with smaller files.") expect(notifications.error).not.toHaveBeenCalled()
}) })
}) })