This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
generated from KennethTrecy/web_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit(tag): ensure tag read page works
- Loading branch information
Angelo Magtoto
committed
Nov 14, 2022
1 parent
9ae100a
commit bb7d0f8
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { mount } from "@vue/test-utils" | ||
|
||
import { UPDATE } from "$/permissions/tag_combinations" | ||
import RequestEnvironment from "$/singletons/request_environment" | ||
import { tag as permissionGroup } from "$/permissions/permission_list" | ||
|
||
import Page from "./read.page.vue" | ||
|
||
describe("Page: tag/read", () => { | ||
it("should populate fields with pre-loaded data", () => { | ||
const tag = { | ||
"data": { | ||
"name": "Tagexample1" | ||
} | ||
} | ||
const wrapper = mount(Page, { | ||
"global": { | ||
"provide": { | ||
"pageContext": { | ||
"pageProps": { | ||
tag, | ||
"userProfile": { | ||
"data": { | ||
"roles": { | ||
"data": [ | ||
{ | ||
"name": "A", | ||
"tagFlags": 0 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
const nameInput = wrapper.find("input.name").element as HTMLInputElement | ||
|
||
expect(nameInput.value).toEqual(tag.data.name) | ||
}) | ||
|
||
it("can update tag information", async() => { | ||
fetchMock.mockResponseOnce("", { "status": RequestEnvironment.status.NO_CONTENT }) | ||
|
||
const tag = { | ||
"data": { | ||
"id": "0", | ||
"name": "Tagexample1" | ||
} | ||
} | ||
const updatedTag = { | ||
"data": { | ||
"name": "Xmaple" | ||
} | ||
} | ||
const wrapper = mount(Page, { | ||
"global": { | ||
"provide": { | ||
"pageContext": { | ||
"pageProps": { | ||
tag, | ||
"userProfile": { | ||
"data": { | ||
"roles": { | ||
"data": [ | ||
{ | ||
"name": "A", | ||
"tagFlags": permissionGroup.generateMask(...UPDATE) | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
const nameInput = wrapper.find("input.name") | ||
const submitBtn = wrapper.find("input[type=submit]") | ||
|
||
await nameInput.setValue(updatedTag.data.name) | ||
await submitBtn.trigger("submit") | ||
const confirmPasswordBtn = wrapper.find(".confirm-btn") | ||
await confirmPasswordBtn.trigger("click") | ||
|
||
const castFetch = fetch as jest.Mock<any, any> | ||
const [ [ request ] ] = castFetch.mock.calls | ||
expect(request).toHaveProperty("method", "PATCH") | ||
expect(request).toHaveProperty("url", `/api/tag/${tag.data.id}`) | ||
|
||
const body = await request.json() | ||
expect(body).toHaveProperty("data.attributes.name", updatedTag.data.name) | ||
}) | ||
}) |