-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ui): test cases to adapt private key changes
This commit is aimed to add the test cases for the refactor of the private keys components and store.
- Loading branch information
1 parent
40882bb
commit 8cd7502
Showing
13 changed files
with
581 additions
and
74 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
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
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
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
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
126 changes: 126 additions & 0 deletions
126
ui/tests/components/PrivateKeys/PrivateKeyDelete.spec.ts
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,126 @@ | ||
import { createVuetify } from "vuetify"; | ||
import { DOMWrapper, flushPromises, mount, VueWrapper } from "@vue/test-utils"; | ||
import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
import MockAdapter from "axios-mock-adapter"; | ||
import PrivateKeyDelete from "@/components/PrivateKeys/PrivateKeyDelete.vue"; | ||
import { namespacesApi, usersApi } from "@/api/http"; | ||
import { store, key } from "@/store"; | ||
import { router } from "@/router"; | ||
import { envVariables } from "@/envVariables"; | ||
import { SnackbarPlugin } from "@/plugins/snackbar"; | ||
|
||
const node = document.createElement("div"); | ||
node.setAttribute("id", "app"); | ||
document.body.appendChild(node); | ||
|
||
type PrivateKeyDeleteWrapper = VueWrapper<InstanceType<typeof PrivateKeyDelete>>; | ||
|
||
describe("Private Key Delete", () => { | ||
let wrapper: PrivateKeyDeleteWrapper; | ||
|
||
const vuetify = createVuetify(); | ||
|
||
let mockNamespace: MockAdapter; | ||
|
||
let mockUser: MockAdapter; | ||
|
||
const members = [ | ||
{ | ||
id: "xxxxxxxx", | ||
username: "test", | ||
role: "owner", | ||
}, | ||
]; | ||
|
||
const namespaceData = { | ||
name: "test", | ||
owner: "test", | ||
tenant_id: "fake-tenant-data", | ||
members, | ||
settings: { | ||
session_record: true, | ||
connection_announcement: "", | ||
}, | ||
max_devices: 3, | ||
devices_count: 3, | ||
created_at: "", | ||
}; | ||
|
||
const authData = { | ||
status: "success", | ||
token: "", | ||
user: "test", | ||
name: "test", | ||
tenant: "fake-tenant-data", | ||
email: "test@test.com", | ||
id: "xxxxxxxx", | ||
role: "owner", | ||
mfa: { | ||
enable: false, | ||
validate: false, | ||
}, | ||
}; | ||
|
||
const session = true; | ||
|
||
beforeEach(async () => { | ||
const el = document.createElement("div"); | ||
document.body.appendChild(el); | ||
vi.useFakeTimers(); | ||
localStorage.setItem("tenant", "fake-tenant-data"); | ||
envVariables.isCloud = true; | ||
|
||
mockNamespace = new MockAdapter(namespacesApi.getAxios()); | ||
mockUser = new MockAdapter(usersApi.getAxios()); | ||
|
||
mockNamespace.onGet("http://localhost:3000/api/namespaces/fake-tenant-data").reply(200, namespaceData); | ||
mockUser.onGet("http://localhost:3000/api/users/security").reply(200, session); | ||
mockUser.onGet("http://localhost:3000/api/auth/user").reply(200, authData); | ||
|
||
wrapper = mount(PrivateKeyDelete, { | ||
global: { | ||
plugins: [[store, key], vuetify, router, SnackbarPlugin], | ||
config: { | ||
errorHandler: () => { /* ignore global error handler */ }, | ||
}, | ||
}, | ||
}); | ||
store.commit("auth/authSuccess", authData); | ||
store.commit("auth/changeData", authData); | ||
store.commit("namespaces/setNamespace", namespaceData); | ||
store.commit("security/setSecurity", session); | ||
}); | ||
|
||
it("Is a Vue instance", () => { | ||
expect(wrapper.vm).toBeTruthy(); | ||
}); | ||
|
||
it("Renders the component", () => { | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
it("Data is defined", () => { | ||
expect(wrapper.vm.$data).toBeDefined(); | ||
}); | ||
|
||
it("Renders components", async () => { | ||
expect(wrapper.find('[data-test="privatekey-delete-btn"]').exists()).toBe(true); | ||
expect(wrapper.find('[data-test="privatekey-delete-btn-title"]').exists()).toBe(true); | ||
await wrapper.findComponent('[data-test="privatekey-delete-btn"]').trigger("click"); | ||
const dialog = new DOMWrapper(document.body); | ||
await flushPromises(); | ||
expect(dialog.find('[data-test="privatekey-dialog-title"]').exists()).toBe(true); | ||
expect(dialog.find('[data-test="privatekey-dialog-text"]').exists()).toBe(true); | ||
expect(dialog.find('[data-test="privatekey-close-btn"]').exists()).toBe(true); | ||
expect(dialog.find('[data-test="privatekey-remove-btn"]').exists()).toBe(true); | ||
}); | ||
|
||
it("Checks if the remove function updates the store on success", async () => { | ||
const storeSpy = vi.spyOn(store, "dispatch"); | ||
await wrapper.setProps({ id: 1 }); | ||
await wrapper.findComponent('[data-test="privatekey-delete-btn"]').trigger("click"); | ||
await flushPromises(); | ||
await wrapper.findComponent('[data-test="privatekey-remove-btn"]').trigger("click"); | ||
expect(storeSpy).toHaveBeenCalledWith("privateKey/remove", 1); | ||
}); | ||
}); |
Oops, something went wrong.