Skip to content

Commit

Permalink
show test results; wip
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis committed Oct 13, 2023
1 parent fe33ad3 commit 0cc5145
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion assets/js/components/Config/MeterModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
:unknown="testUnknown"
:running="testRunning"
:result="testResult"
:error="testError"
@test="testManually"
/>

Expand Down Expand Up @@ -346,7 +347,7 @@ export default {
if (!this.isNew) {
url += `/merge/${this.id}`;
}
await api.post(url, this.apiData);
return await api.post(url, this.apiData);
},
async update() {
if (this.testUnknown) {
Expand Down
7 changes: 6 additions & 1 deletion assets/js/components/Config/TestResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
{{ $t("config.validation.validate") }}
</a>
</div>
<hr v-if="error" />
<div v-if="error">
{{ error }}
</div>
<hr v-if="result" />
<div v-if="result">
{{ result }}
Expand All @@ -41,7 +45,8 @@ export default {
failed: Boolean,
unknown: Boolean,
running: Boolean,
result: String,
result: Object,
error: String,
},
emits: ["test"],
};
Expand Down
3 changes: 2 additions & 1 deletion assets/js/components/Config/VehicleModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
:unknown="testUnknown"
:running="testRunning"
:result="testResult"
:error="testError"
@test="testManually"
/>

Expand Down Expand Up @@ -306,7 +307,7 @@ export default {
if (!this.isNew) {
url += `/merge/${this.id}`;
}
await api.post(url, this.apiData);
return await api.post(url, this.apiData);
},
async update() {
if (this.testUnknown) {
Expand Down
22 changes: 18 additions & 4 deletions assets/js/components/Config/mixins/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const TEST_RUNNING = "running";
export default {
data() {
return {
testResult: "",
testState: TEST_UNKNOWN,
testError: null,
testResult: null,
};
},
computed: {
Expand All @@ -27,21 +28,34 @@ export default {
methods: {
resetTest() {
this.testState = TEST_UNKNOWN;
this.testError = null;
this.testResult = null;
},

async test(testApi) {
if (!this.$refs.form.reportValidity()) return false;
this.testState = TEST_RUNNING;
try {
await testApi();
const res = await testApi();
const result = [];
for (const [key, { value, error }] of Object.entries(res.data.result)) {
if (error) {
this.testState = TEST_FAILED;
this.testResult = null;
this.testError = `${key}: ${error}`;
return false;
}
result.push({ key, value });
}
this.testResult = result;
this.testError = null;
this.testState = TEST_SUCCESS;
this.testResult = null;
return true;
} catch (e) {
console.error(e);
this.testState = TEST_FAILED;
this.testResult = e.response?.data?.error || e.message;
this.testResult = null;
this.testError = e.response?.data?.error || e.message;
}
return false;
},
Expand Down

0 comments on commit 0cc5145

Please sign in to comment.