Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
unit(tag): ensure tag create page works
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Magtoto committed Nov 14, 2022
1 parent 7954210 commit 758068c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pages/tag/create.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { mount } from "@vue/test-utils"
import RequestEnvironment from "$/singletons/request_environment"

import Page from "./create.page.vue"

describe("Page: /tag", () => {
it("can create tag", async() => {
fetchMock.mockResponseOnce(JSON.stringify({
"data": {
"type": "tag",
"attributes": {
"deletedAt": null,
"name": "Xmaple"
}
}
}), { "status": RequestEnvironment.status.OK })
const wrapper = mount(Page, {
"global": {
"provide": {
"pageContext": {}
}
}
})
const tag = {
"data": {
"deletedAt": null,
"name": "Xmaple"
}
}

const nameInput = wrapper.find("input.name")
const submitBtn = wrapper.find("input[type=submit]")

await nameInput.setValue(tag.data.name)
await submitBtn.trigger("submit")

const castFetch = fetch as jest.Mock<any, any>
const [ [ request ] ] = castFetch.mock.calls
expect(request).toHaveProperty("method", "POST")
expect(request).toHaveProperty("url", "/api/tag")
expect(request.json()).resolves.toStrictEqual({
"data": {
"type": "tag",
"attributes": {
"deletedAt": null,
"name": "Xmaple"
}
}
})
})
})

0 comments on commit 758068c

Please sign in to comment.