-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* studio - added user table * studio - user table improvements * studio - user table unit tests * studio - remove console log * studio - renamed user action remove to delete
- Loading branch information
1 parent
3cac3eb
commit 6babd1f
Showing
16 changed files
with
777 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { vi, describe, it, beforeEach, expect } from "vitest"; | ||
import UserAddForm from "./UserAddForm.vue"; | ||
import { mount } from "@vue/test-utils"; | ||
|
||
const { addUser } = vi.hoisted(() => { | ||
return { | ||
addUser: vi.fn(), | ||
}; | ||
}); | ||
|
||
vi.mock("@/composables/user/userStore", () => { | ||
return { | ||
useUserStore: () => { | ||
return { | ||
addUser, | ||
}; | ||
}, | ||
}; | ||
}); | ||
|
||
describe("UserAddForm", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("should add a user when user submits", async () => { | ||
addUser.mockResolvedValueOnce(true); | ||
expect(addUser).not.toHaveBeenCalled(); | ||
const wrapper = mount(UserAddForm); | ||
await wrapper.find("input#username").setValue("test_user"); | ||
await wrapper.find("input#password").setValue("test_password"); | ||
await wrapper.find("form").trigger("submit"); | ||
await wrapper.vm.$nextTick(); | ||
expect(addUser).toHaveBeenCalledOnce(); | ||
}); | ||
|
||
it("should add a user when user clicks submit button", async () => { | ||
addUser.mockResolvedValueOnce(true); | ||
expect(addUser).not.toHaveBeenCalled(); | ||
const wrapper = mount(UserAddForm); | ||
await wrapper.find("input#username").setValue("test_user"); | ||
await wrapper.find("input#password").setValue("test_password"); | ||
await wrapper.find("button[type=submit]").trigger("click"); | ||
await wrapper.vm.$nextTick(); | ||
expect(addUser).toHaveBeenCalledOnce(); | ||
}); | ||
}); |
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,62 @@ | ||
<script lang="ts" setup> | ||
import { ref } from "vue"; | ||
import { useUserStore } from "@/composables/user/userStore"; | ||
const username = ref(""); | ||
const password = ref(""); | ||
const loading = ref(false); | ||
const { addUser, fetchUsers } = useUserStore(); | ||
const add = (event: Event) => { | ||
loading.value = true; | ||
event.preventDefault(); | ||
addUser({ | ||
username: username.value, | ||
password: password.value, | ||
}) | ||
.then(() => { | ||
loading.value = false; | ||
username.value = ""; | ||
password.value = ""; | ||
fetchUsers(); | ||
}) | ||
.catch(() => { | ||
loading.value = false; | ||
}); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div class="user-add-form"> | ||
<h2>Add User</h2> | ||
<form id="user-add-form" @submit="add"> | ||
<div class="form-group"> | ||
<label for="username">Username</label> | ||
<input id="username" v-model="username" type="text" /> | ||
</div> | ||
<div class="form-group"> | ||
<label for="password">Password</label> | ||
<input id="password" v-model="password" type="text" /> | ||
</div> | ||
<button type="submit" class="button" @click="add">Add User</button> | ||
</form> | ||
</div> | ||
</template> | ||
|
||
<style lang="less" scoped> | ||
.user-add-form { | ||
margin: 1rem auto; | ||
padding: 1rem; | ||
border: 1px solid var(--color-border); | ||
border-radius: 0.5rem; | ||
} | ||
.form-group { | ||
margin: 0.5rem 0; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
} | ||
</style> |
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,46 @@ | ||
import { vi, describe, it, beforeEach, expect } from "vitest"; | ||
import UserTable from "./UserTable.vue"; | ||
import { mount, shallowMount } from "@vue/test-utils"; | ||
|
||
const { users } = vi.hoisted(() => { | ||
return { | ||
users: { | ||
value: [ | ||
{ | ||
username: "test_user", | ||
admin: false, | ||
login: false, | ||
}, | ||
{ | ||
username: "test_user2", | ||
admin: false, | ||
login: false, | ||
}, | ||
], | ||
}, | ||
}; | ||
}); | ||
|
||
vi.mock("@/composables/user/userStore", () => { | ||
return { | ||
useUserStore: () => { | ||
return { users }; | ||
}, | ||
}; | ||
}); | ||
|
||
describe("UserTable", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("renders", () => { | ||
const wrapper = shallowMount(UserTable); | ||
expect(wrapper.exists()).toBe(true); | ||
}); | ||
it("should render message when no users", () => { | ||
users.value = []; | ||
const wrapper = mount(UserTable); | ||
expect(wrapper.text()).toContain("No users found"); | ||
}); | ||
}); |
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,42 @@ | ||
<script lang="ts" setup> | ||
import { addTable } from "@/composables/table/tableConfig"; | ||
import { setTableData } from "@/composables/table/tableData"; | ||
import { userColumns } from "@/composables/user/userConfig"; | ||
import { useUserStore } from "@/composables/user/userStore"; | ||
import { watchEffect } from "vue"; | ||
import AgdbTable from "../base/table/AgdbTable.vue"; | ||
const { users } = useUserStore(); | ||
const TABLE_KEY = Symbol("users"); | ||
addTable({ | ||
name: TABLE_KEY, | ||
columns: userColumns, | ||
uniqueKey: "username", | ||
}); | ||
watchEffect(() => { | ||
setTableData(TABLE_KEY, users.value); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div class="table-wrap"> | ||
<div v-if="users.length" class="user-table"> | ||
<AgdbTable :name="TABLE_KEY" /> | ||
</div> | ||
|
||
<p v-else>No users found</p> | ||
</div> | ||
</template> | ||
|
||
<style lang="less" scoped> | ||
.table-wrap { | ||
overflow: auto; | ||
} | ||
.user-table { | ||
width: 700px; | ||
margin: 0 auto; | ||
} | ||
</style> |
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
Oops, something went wrong.