[go: nahoru, domu]

Skip to content

Commit

Permalink
tests(ui): added interface views related unitary tests
Browse files Browse the repository at this point in the history
This commit adds tests for view components unitary tests, testing
rendering and integration API Calls.
  • Loading branch information
luannmoreira authored and gustavosbarreto committed Apr 12, 2024
1 parent 2bfa847 commit 879dbda
Show file tree
Hide file tree
Showing 33 changed files with 2,960 additions and 457 deletions.
1 change: 1 addition & 0 deletions ui/src/components/firewall/FirewallRuleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<template v-slot:activator="{ props }">
<div v-bind="props">
<FirewallRuleDelete
v-if="item.id"
:id="item.id"
@update="refreshFirewallRules"
:notHasAuthorization="!hasAuthorizationFormDialogEdit()"
Expand Down
144 changes: 67 additions & 77 deletions ui/src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
</v-card>
</template>

<script lang="ts">
import { computed, defineComponent, onMounted, ref } from "vue";
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import axios, { AxiosError } from "axios";
import Card from "../components/Card/Card.vue";
import { useStore } from "../store";
Expand All @@ -41,84 +41,74 @@ type ItemCard = {
stats: number;
};
export default defineComponent({
name: "DashboardView",
components: { Card },
setup() {
const store = useStore();
const hasStatus = ref(false);
const itemsStats = computed(() => store.getters["stats/stats"]);
const hasNamespace = computed(
() => store.getters["namespaces/getNumberNamespaces"] !== 0,
);
const items = computed(() => [
{
id: 1,
title: "Registered Devices",
fieldObject: "registered_devices",
content: "Registered devices into the tenancy account",
icon: "mdi-devices",
stats: itemsStats.value.registered_devices || 0,
buttonName: "Add Device",
pathName: "devices",
nameUseTest: "registeredDevices-btn",
},
{
id: 2,
title: "Online Devices",
fieldObject: "online_devices",
content: "Devices are online and ready for connecting",
icon: "mdi-devices",
stats: itemsStats.value.online_devices || 0,
buttonName: "View all Devices",
pathName: "devices",
nameUseTest: "viewOnlineDevices-btn",
},
{
id: 3,
title: "Active Sessions",
fieldObject: "active_sessions",
content: "Active SSH Sessions opened by users",
icon: "mdi-devices",
stats: itemsStats.value.active_sessions || 0,
buttonName: "View all Sessions",
pathName: "sessions",
nameUseTest: "viewActiveSession-btn",
},
] as ItemCard[]);
const store = useStore();
const hasStatus = ref(false);
const itemsStats = computed(() => store.getters["stats/stats"]);
const hasNamespace = computed(
() => store.getters["namespaces/getNumberNamespaces"] !== 0,
);
const items = computed(() => [
{
id: 1,
title: "Registered Devices",
fieldObject: "registered_devices",
content: "Registered devices into the tenancy account",
icon: "mdi-devices",
stats: itemsStats.value.registered_devices || 0,
buttonName: "Add Device",
pathName: "devices",
nameUseTest: "registeredDevices-btn",
},
{
id: 2,
title: "Online Devices",
fieldObject: "online_devices",
content: "Devices are online and ready for connecting",
icon: "mdi-devices",
stats: itemsStats.value.online_devices || 0,
buttonName: "View all Devices",
pathName: "devices",
nameUseTest: "viewOnlineDevices-btn",
},
{
id: 3,
title: "Active Sessions",
fieldObject: "active_sessions",
content: "Active SSH Sessions opened by users",
icon: "mdi-devices",
stats: itemsStats.value.active_sessions || 0,
buttonName: "View all Sessions",
pathName: "sessions",
nameUseTest: "viewActiveSession-btn",
},
] as ItemCard[]);
onMounted(async () => {
if (!hasNamespace.value) return;
onMounted(async () => {
if (!hasNamespace.value) return;
try {
await store.dispatch("stats/get");
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError;
switch (true) {
case axiosError.response && axiosError.response?.status === 403: {
hasStatus.value = true;
break;
}
default: {
hasStatus.value = true;
store.dispatch(
"snackbar/showSnackbarErrorAction",
INotificationsError.dashboard,
);
break;
}
}
try {
await store.dispatch("stats/get");
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError;
switch (true) {
case axiosError.response && axiosError.response?.status === 403: {
hasStatus.value = true;
break;
}
default: {
hasStatus.value = true;
store.dispatch(
"snackbar/showSnackbarErrorAction",
INotificationsError.dashboard,
);
break;
}
handleError(error);
}
});
return {
hasStatus,
itemsStats,
items,
};
},
}
handleError(error);
}
});
defineExpose({ hasStatus });
</script>
94 changes: 36 additions & 58 deletions ui/src/views/DetailsDevice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
</v-card>
</template>

<script lang="ts">
import { computed, defineComponent, onMounted } from "vue";
<script setup lang="ts">
import { computed, onMounted } from "vue";
import { useRoute } from "vue-router";
import { useStore } from "../store";
import { displayOnlyTenCharacters } from "../utils/string";
Expand All @@ -131,63 +131,41 @@ import TerminalDialog from "../components/Terminal/TerminalDialog.vue";
import { formatDate } from "@/utils/formateDate";
import handleError from "@/utils/handleError";
export default defineComponent({
name: "DeviceDetails",
inheritAttrs: true,
setup() {
const store = useStore();
const route = useRoute();
const deviceId = computed(() => route.params.id);
const device = computed(() => store.getters["devices/get"]);
onMounted(async () => {
try {
await store.dispatch("devices/get", deviceId.value);
} catch (error: unknown) {
store.dispatch(
"snackbar/showSnackbarErrorAction",
INotificationsError.deviceDetails,
);
handleError(error);
}
});
const deviceIsEmpty = computed(
() => store.getters["devices/get"]
const store = useStore();
const route = useRoute();
const deviceId = computed(() => route.params.id);
const device = computed(() => store.getters["devices/get"]);
onMounted(async () => {
try {
await store.dispatch("devices/get", deviceId.value);
} catch (error: unknown) {
store.dispatch(
"snackbar/showSnackbarErrorAction",
INotificationsError.deviceDetails,
);
handleError(error);
}
});
const deviceIsEmpty = computed(
() => store.getters["devices/get"]
&& Object.keys(store.getters["devices/get"]).length === 0,
);
const refreshUsers = async () => {
try {
await store.dispatch("devices/get", deviceId.value);
} catch (error: unknown) {
store.dispatch(
"snackbar/showSnackbarErrorAction",
INotificationsError.deviceDetails,
);
handleError(error);
}
};
const receiveName = (params: string) => {
device.value.name = params;
};
const refreshUsers = async () => {
try {
await store.dispatch("devices/get", deviceId.value);
} catch (error: unknown) {
store.dispatch(
"snackbar/showSnackbarErrorAction",
INotificationsError.deviceDetails,
);
handleError(error);
}
};
const receiveName = (params: string) => {
device.value.name = params;
};
return {
device,
deviceIsEmpty,
displayOnlyTenCharacters,
showTag,
formatDate,
refreshUsers,
receiveName,
};
},
components: {
DeviceIcon,
TagFormUpdate,
DeviceDelete,
DeviceRename,
TerminalDialog,
},
});
</script>
Loading

0 comments on commit 879dbda

Please sign in to comment.