Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): ✨ ⬆️ added test settings #72

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ export interface IWorkflowDb {
usedCredentials?: IUsedCredential[];
}

export interface TestSuiteDb {
name: string;
id: string;
createdAt: string;
updatedAt: string;
description: string;
}

// Identical to cli.Interfaces.ts
export interface IWorkflowShortResponse {
id: string;
Expand Down Expand Up @@ -871,6 +879,7 @@ export interface WorkflowsState {
workflowExecutionData: IExecutionResponse | null;
workflowExecutionPairedItemMappings: { [itemId: string]: Set<string> };
workflowsById: IWorkflowsMap;
testSuitesById: TestSuiteDbMap;
}

export interface RootState {
Expand Down Expand Up @@ -1172,7 +1181,9 @@ export interface IWorkflowsState {
export interface IWorkflowsMap {
[name: string]: IWorkflowDb;
}

export interface TestSuiteDbMap {
[name: string]: TestSuiteDb;
}
export interface CommunityNodesState {
availablePackageCount: number;
installedPackages: CommunityPackageMap;
Expand Down
58 changes: 57 additions & 1 deletion packages/editor-ui/src/api/workflows.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IExecutionsCurrentSummaryExtended, IRestApiContext } from '@/Interface';
import type { IExecutionsCurrentSummaryExtended, IRestApiContext, TestSuiteDb } from '@/Interface';
import type { ExecutionFilters, ExecutionOptions, IDataObject } from 'n8n-workflow';
import { ExecutionStatus, WorkflowExecuteMode } from 'n8n-workflow';
import { makeRestApiRequest } from '@/utils';
Expand All @@ -23,6 +23,62 @@ export async function getWorkflows(context: IRestApiContext, filter?: object) {
return await makeRestApiRequest(context, 'GET', '/workflows', sendData);
}

export async function getTestSuite(workFlowId: string) {
return await new Promise<TestSuiteDb[]>((resolve) => {
/**
* TODO: FETCH ALL TEST SUITES WITH WORKFLOW ID
*/
setTimeout(() => {
resolve([
{
name: workFlowId,
id: workFlowId,
createdAt: new Date().toUTCString(),
updatedAt: new Date().toUTCString(),
description: 'some description',
},
]);
}, 3000);
});
}

export async function postTestSuite(workFlowId: string, description: string) {
return await new Promise<TestSuiteDb[]>((resolve) => {
/**
* TODO: FETCH ALL TEST SUITES WITH WORKFLOW ID
*/
setTimeout(() => {
resolve([
{
name: workFlowId,
id: workFlowId,
createdAt: new Date().toUTCString(),
updatedAt: new Date().toUTCString(),
description,
},
]);
}, 3000);
});
}

export async function patchTestSuite(payload: {
workflowId: string;
testId: string;
id: string;
outputType: string;
error: string;
output: string;
}) {
return await new Promise((resolve) => {
/**
* TODO: FETCH ALL TEST SUITES WITH WORKFLOW ID
*/
setTimeout(() => {
resolve(payload);
}, 3000);
});
}

export async function getActiveWorkflows(context: IRestApiContext) {
return await makeRestApiRequest(context, 'GET', '/active');
}
Expand Down
171 changes: 171 additions & 0 deletions packages/editor-ui/src/components/AddTestSuiteModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<template>
<Modal
width="540px"
:name="ADD_TEST_SUITE_MODAL_KEY"
:title="$locale.baseText('testSuites.addTestSuite.title')"
:eventBus="modalBus"
:center="true"
:beforeClose="onModalClose"
:showClose="!loading"
>
<template #content>
<div :class="[$style.formContainer, 'mt-m']">
<n8n-input-label
:class="$style.labelTooltip"
:label="$locale.baseText('testSuites.addTest.description.label')"
:tooltipText="$locale.baseText('testSuites.addTest.description.tooltip')"
>
<n8n-input
name="description"
v-model="description"
type="text"
:maxlength="300"
:placeholder="''"
:required="true"
:disabled="loading"
/>
</n8n-input-label>
<div :class="[$style.infoText, 'mt-4xs']">
<span
size="small"
:class="[$style.infoText, infoTextErrorMessage ? $style.error : '']"
v-text="infoTextErrorMessage"
></span>
</div>
</div>
</template>
<template #footer>
<n8n-button
:loading="loading"
:disabled="!description || loading"
:label="
loading
? $locale.baseText('testSuites.addTest.saveButton.label.loading')
: $locale.baseText('testSuites.addTest.saveButton.label')
"
size="large"
float="right"
@click="onAddClick"
/>
</template>
</Modal>
</template>

<script lang="ts">
import Modal from './Modal.vue';
import { ADD_TEST_SUITE_MODAL_KEY } from '../constants';
import mixins from 'vue-typed-mixins';
import { showMessage } from '@/mixins/showMessage';
import { mapStores } from 'pinia';
import { createEventBus } from '@/event-bus';
import { useWorkflowsStore } from '@/stores';

export default mixins(showMessage).extend({
name: 'AddTestSuiteModal',
components: {
Modal,
},
props: {
workFlowId: {
type: String,
default: '',
},
},
data() {
return {
loading: false,
description: '',
modalBus: createEventBus(),
infoTextErrorMessage: '',
ADD_TEST_SUITE_MODAL_KEY,
};
},
computed: {
...mapStores(useWorkflowsStore),
},
methods: {
async onAddClick() {
try {
this.infoTextErrorMessage = '';
this.loading = true;
await this.workflowsStore.addWorkflowTestSuite(
this.$route.params.workflow,
this.description,
);
this.loading = false;
this.modalBus.emit('close');
this.$showMessage({
title: this.$locale.baseText('testSuites.addTest.saveButton.success'),
type: 'success',
});
} catch (error) {
if (error.httpStatusCode && error.httpStatusCode === 400) {
this.infoTextErrorMessage = error.message;
} else {
this.$showError(error, this.$locale.baseText('testSuites.addTest.saveButton.error'));
}
} finally {
this.loading = false;
}
},
onModalClose() {
return !this.loading;
},
},
});
</script>

<style module lang="scss">
.descriptionContainer {
display: flex;
justify-content: space-between;
align-items: center;
border: var(--border-width-base) var(--border-style-base) var(--color-info-tint-1);
border-radius: var(--border-radius-base);
background-color: var(--color-background-light);

button {
& > span {
flex-direction: row-reverse;
& > span {
margin-left: var(--spacing-3xs);
}
}
}
}

.formContainer {
font-size: var(--font-size-2xs);
font-weight: var(--font-weight-regular);
color: var(--color-text-base);
}

.checkbox {
span:nth-child(2) {
vertical-align: text-top;
}
}

.error {
color: var(--color-danger);

span {
border-color: var(--color-danger);
}
}
</style>

<style lang="scss">
.el-tooltip__popper {
max-width: 240px;
img {
width: 100%;
}
p {
line-height: 1.2;
}
p + p {
margin-top: var(--spacing-2xs);
}
}
</style>
Loading