Skip to content

Commit 8c35efa

Browse files
luizhf42gustavosbarreto
authored andcommitted
test(ui): improve admin's views tests
1 parent ff7fc65 commit 8c35efa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1402
-2751
lines changed

ui/admin/src/router/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import useLicenseStore from "@admin/store/modules/license";
1010
import useAuthStore from "@admin/store/modules/auth";
1111
import { plugin as snackbar } from "@/plugins/snackbar"; // using direct plugin because inject() doesn't work outside components
1212

13-
const routes = [
13+
export const routes = [
1414
{
1515
path: "/unauthorized",
1616
name: "Unauthorized",

ui/admin/src/views/AnnouncementDetails.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ const loadAnnouncement = async () => {
150150
const handleDelete = () => { void router.push({ name: "announcements" }); };
151151
152152
onMounted(loadAnnouncement);
153-
154-
defineExpose({ announcement, contentToHtml });
155153
</script>
156154

157155
<style lang="scss" scoped>

ui/admin/src/views/Dashboard.vue

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
</template>
111111

112112
<script setup lang="ts">
113-
import axios, { AxiosError } from "axios";
113+
import axios from "axios";
114114
import { computed, onMounted, ref } from "vue";
115115
import useStatsStore from "@admin/store/modules/stats";
116116
import useSnackbar from "@/helpers/snackbar";
@@ -127,16 +127,9 @@ onMounted(async () => {
127127
await statsStore.getStats();
128128
} catch (error: unknown) {
129129
hasStatus.value = true;
130-
if (axios.isAxiosError(error)) {
131-
const axiosError = error as AxiosError;
132-
if (axiosError.response?.status === 402) {
133-
snackbar.showError("Failed to load the dashboard stats. Check your license and try again.");
134-
} else {
135-
snackbar.showError("Failed to load the dashboard stats. Please try again.");
136-
}
137-
}
130+
if (axios.isAxiosError(error) && error.response?.status === 402) {
131+
snackbar.showError("Failed to load the dashboard stats. Check your license and try again.");
132+
} else snackbar.showError("Failed to load the dashboard stats. Please try again.");
138133
}
139134
});
140-
141-
defineExpose({ stats, hasStatus });
142135
</script>

ui/admin/src/views/Device.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
>
99
<v-text-field
1010
v-model.trim="filter"
11+
data-test="search-input"
1112
class="w-100 w-md-50"
1213
label="Search by hostname"
1314
color="primary"
@@ -51,6 +52,4 @@ const searchDevices = async () => {
5152
snackbar.showError("Failed to fetch the devices.");
5253
}
5354
};
54-
55-
defineExpose({ filter });
5655
</script>

ui/admin/src/views/FirewallRulesDetails.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,11 @@
114114
</template>
115115

116116
<script setup lang="ts">
117-
import { computed, ref, onMounted } from "vue";
117+
import { computed, onMounted } from "vue";
118118
import { useRoute } from "vue-router";
119119
import useFirewallRulesStore from "@admin/store/modules/firewall_rules";
120120
import isHostname from "@/utils/isHostname";
121121
import useSnackbar from "@/helpers/snackbar";
122-
import { IAdminFirewallRule } from "../interfaces/IFirewallRule";
123122
import showTag from "@/utils/tag";
124123
import { displayOnlyTenCharacters, formatHostnameFilter, formatSourceIP, formatUsername } from "@/utils/string";
125124
@@ -128,11 +127,11 @@ const snackbar = useSnackbar();
128127
const firewallRulesStore = useFirewallRulesStore();
129128
130129
const firewallRuleId = computed(() => route.params.id as string);
131-
const firewallRule = ref({} as IAdminFirewallRule);
130+
const firewallRule = computed(() => firewallRulesStore.firewallRule);
132131
133132
onMounted(async () => {
134133
try {
135-
firewallRule.value = await firewallRulesStore.fetchFirewallRuleById(firewallRuleId.value);
134+
await firewallRulesStore.fetchFirewallRuleById(firewallRuleId.value);
136135
} catch {
137136
snackbar.showError("Failed to get firewall rule details.");
138137
}

ui/admin/src/views/NamespaceDetails.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,14 @@ const route = useRoute();
292292
const loading = ref(false);
293293
const namespaceEdit = ref(false);
294294
const namespaceDelete = ref(false);
295-
const namespace = ref({} as IAdminNamespace);
295+
const namespace = computed(() => namespacesStore.namespace);
296296
const hasNamespace = computed(() => !!namespace.value.tenant_id);
297297
const namespaceId = computed(() => route.params.id);
298298
299299
const fetchNamespaceDetails = async () => {
300300
try {
301301
loading.value = true;
302-
namespace.value = await namespacesStore.fetchNamespaceById(namespaceId.value as string);
302+
await namespacesStore.fetchNamespaceById(namespaceId.value as string);
303303
} catch (error) {
304304
snackbar.showError("Failed to fetch namespace details.");
305305
handleError(error);
@@ -341,8 +341,6 @@ const getOwnerLabel = (namespace: IAdminNamespace) => {
341341
342342
return owner?.email || namespace.owner || "";
343343
};
344-
345-
defineExpose({ namespace });
346344
</script>
347345

348346
<style scoped>

ui/admin/src/views/Namespaces.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<v-text-field
1414
v-model.trim="filter"
15+
data-test="search-input"
1516
label="Search by name"
1617
color="primary"
1718
class="w-100 w-md-50"
@@ -48,6 +49,4 @@ const searchNamespaces = async () => {
4849
4950
await namespacesStore.fetchNamespaceList({ filter: encodedFilter, page: 1 });
5051
};
51-
52-
defineExpose({ filter });
5352
</script>

ui/admin/src/views/NewAnnouncement.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
:error-messages="titleError"
1818
variant="underlined"
1919
placeholder="Enter announcement title"
20-
data-test="announcement-title"
20+
data-test="announcement-title-field"
2121
/>
2222
</v-card-item>
2323

@@ -127,8 +127,6 @@ const postAnnouncement = async () => {
127127
snackbar.showError("Failed to create announcement.");
128128
}
129129
};
130-
131-
defineExpose({ title, titleError });
132130
</script>
133131

134132
<style lang="scss">

ui/admin/src/views/UserDetails.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,12 @@
240240
</template>
241241

242242
<script setup lang="ts">
243-
import { computed, onBeforeMount, ref } from "vue";
243+
import { computed, onBeforeMount } from "vue";
244244
import { useRoute } from "vue-router";
245245
import useUsersStore from "@admin/store/modules/users";
246246
import useAuthStore from "@admin/store/modules/auth";
247247
import UserStatusChip from "@admin/components/User/UserStatusChip.vue";
248248
import UserDelete from "@admin/components/User/UserDelete.vue";
249-
import type { IAdminUser } from "@admin/interfaces/IUser";
250249
import useSnackbar from "@/helpers/snackbar";
251250
import { formatFullDateTime } from "@/utils/date";
252251
@@ -256,7 +255,7 @@ const usersStore = useUsersStore();
256255
const authStore = useAuthStore();
257256
258257
const userId = computed(() => route.params.id as string);
259-
const user = ref({} as IAdminUser);
258+
const user = computed(() => usersStore.user);
260259
261260
const lastLoginText = computed(() => {
262261
const value = user.value?.last_login;
@@ -283,11 +282,9 @@ const loginWithToken = async () => {
283282
284283
onBeforeMount(async () => {
285284
try {
286-
user.value = await usersStore.fetchUserById(userId.value);
285+
await usersStore.fetchUserById(userId.value);
287286
} catch {
288287
snackbar.showError("Failed to get user details.");
289288
}
290289
});
291-
292-
defineExpose({ user });
293290
</script>

ui/admin/src/views/Users.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,4 @@ const searchUsers = async () => {
5656
watchDebounced(filter, async () => {
5757
await searchUsers();
5858
}, { debounce: 1000, maxWait: 5000 });
59-
60-
defineExpose({ filter });
6159
</script>

0 commit comments

Comments
 (0)