Skip to content

Commit

Permalink
fix: only show endpoint key error if user changes the default value
Browse files Browse the repository at this point in the history
  • Loading branch information
vsgoulart committed Dec 12, 2024
1 parent 90e8e0b commit 8d44c8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ DocumentPreview.config = {
name: 'Document preview',
create: (options = {}) => ({
label: 'Document preview',
endpointKey: '=defaultDocumentsEndpointKey',
endpointKey: DEFAULT_ENDPOINT_KEY,
...options,
}),
};

// helpers /////////////////////////////

const DOCUMENT_ID_PLACEHOLDER = '{documentId}';
const DEFAULT_ENDPOINT_KEY = '=defaultDocumentsEndpointKey';

/**
* @typedef GetErrorOptions
Expand All @@ -98,16 +99,18 @@ function getErrors(options) {
let errors = [];

if (!isString(dataSource) || dataSource.length < 1) {
errors.push('Data source is not defined.');
errors.push('Document reference is not defined.');
}

if (!isString(endpointKey) || endpointKey.length < 1) {
errors.push('Endpoint key is not defined.');
}

if (!URL.canParse(endpoint)) {
errors.push('Endpoint is not valid.');
} else if (!isValidDocumentEndpoint(endpoint)) {
if (endpointKey !== DEFAULT_ENDPOINT_KEY && !URL.canParse(endpoint)) {
errors.push(
`If you change the endpoint key from "${DEFAULT_ENDPOINT_KEY}", the document preview won't work with Camunda Tasklist and you must provide a valid URL.`,
);
} else if (endpointKey !== DEFAULT_ENDPOINT_KEY && !isValidDocumentEndpoint(endpoint)) {
errors.push('Endpoint must contain "{documentId}".');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,11 @@ describe('DocumentPreview', function () {
// when
const { container } = createDocumentPreview({
initialData: {
defaultDocumentsEndpointKey: false,
foobar: false,
},
services: {
expressionLanguage: mockExpressionLanguageService,
},
});

// then
const formField = container.querySelector('.fjs-form-field');

expect(formField).to.exist;
expect(formField.classList.contains('fjs-form-field-documentPreview')).to.be.true;

expect(screen.queryByText('Endpoint is not valid.')).to.exist;
});

it('should handle bad endpoint format', function () {
// when
const { container } = createDocumentPreview({
initialData,
field: {
...defaultField,
dataSource: undefined,
endpointKey: '=foobar',
},
services: {
expressionLanguage: mockExpressionLanguageService,
Expand All @@ -77,16 +59,20 @@ describe('DocumentPreview', function () {
expect(formField).to.exist;
expect(formField.classList.contains('fjs-form-field-documentPreview')).to.be.true;

expect(screen.queryByText('Data source is not defined.')).to.exist;
expect(
screen.queryByText(
'If you change the endpoint key from "=defaultDocumentsEndpointKey", the document preview won\'t work with Camunda Tasklist and you must provide a valid URL.',
),
).to.exist;
});

it('should handle missing endpoint', function () {
it('should handle bad endpoint format', function () {
// when
const { container } = createDocumentPreview({
initialData,
field: {
...defaultField,
endpointKey: undefined,
dataSource: undefined,
},
services: {
expressionLanguage: mockExpressionLanguageService,
Expand All @@ -99,8 +85,7 @@ describe('DocumentPreview', function () {
expect(formField).to.exist;
expect(formField.classList.contains('fjs-form-field-documentPreview')).to.be.true;

expect(screen.queryByText('Endpoint key is not defined.')).to.exist;
expect(screen.queryByText('Endpoint is not valid.')).to.exist;
expect(screen.queryByText('Document reference is not defined.')).to.exist;
});

it('should handle missing data source', function () {
Expand Down

0 comments on commit 8d44c8a

Please sign in to comment.