mirror of https://github.com/Squidex/squidex.git
4 changed files with 168 additions and 35 deletions
@ -0,0 +1,49 @@ |
|||
<!DOCTYPE html> |
|||
<html> |
|||
|
|||
<head> |
|||
<meta charset="utf-8"> |
|||
|
|||
<!-- Load the editor sdk from the local folder or https://cloud.squidex.io/scripts/editor-sdk.js --> |
|||
<script src="editor-sdk.js"></script> |
|||
</head> |
|||
|
|||
<body> |
|||
<button id="button">New Value</button> |
|||
|
|||
<script> |
|||
var numberGenerator = 1; |
|||
|
|||
var button = document.getElementById('button'); |
|||
|
|||
var field = new SquidexFormField(); |
|||
|
|||
function logState(message) { |
|||
console.log(`${message}. Value: <${JSON.stringify(field.getValue(), 2)}>, Form Value: <${JSON.stringify(field.getFormValue())}>`); |
|||
} |
|||
|
|||
logState('Init'); |
|||
|
|||
if (button) { |
|||
button.addEventListener('click', function () { |
|||
numberGenerator++; |
|||
|
|||
field.valueChanged(numberGenerator); |
|||
|
|||
logState('Click'); |
|||
}); |
|||
} |
|||
|
|||
// Handle the value change event and set the text to the editor. |
|||
field.onValueChanged(function (value) { |
|||
logState(`Value changed: <${JSON.stringify(value, 2)}>`); |
|||
}); |
|||
|
|||
// Disable the editor when it should be disabled. |
|||
field.onDisabled(function (disabled) { |
|||
logState(`Disabled: <${JSON.stringify(disabled, 2)}>`); |
|||
}); |
|||
</script> |
|||
</body> |
|||
|
|||
</html> |
|||
@ -0,0 +1,76 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { parseError } from './http-extensions'; |
|||
|
|||
import { ErrorDto } from './../../utils/error'; |
|||
|
|||
describe('ErrorParsing', () => { |
|||
it('should return default when error is javascript exception', () => { |
|||
const response: any = new Error(); |
|||
const result = parseError(response, 'Fallback'); |
|||
|
|||
expect(result).toEqual(new ErrorDto(500, 'Fallback', [], response)); |
|||
}); |
|||
|
|||
it('should just forward error dto', () => { |
|||
const response: any = new ErrorDto(500, 'error', []); |
|||
const result = parseError(response, 'Fallback'); |
|||
|
|||
expect(result).toBe(response); |
|||
}); |
|||
|
|||
it('should return default 412 error', () => { |
|||
const response: any = { status: 412 }; |
|||
const result = parseError(response, 'Fallback'); |
|||
|
|||
expect(result).toEqual(new ErrorDto(412, 'Failed to make the update. Another user has made a change. Please reload.', [], response)); |
|||
}); |
|||
|
|||
it('should return default 429 error', () => { |
|||
const response: any = { status: 429 }; |
|||
const result = parseError(response, 'Fallback'); |
|||
|
|||
expect(result).toEqual(new ErrorDto(429, 'You have exceeded the maximum limit of API calls.', [], response)); |
|||
}); |
|||
|
|||
it('should return error from error object', () => { |
|||
const error = { message: 'My-Message', details: ['My-Detail'] }; |
|||
|
|||
const response: any = { status: 400, error }; |
|||
const result = parseError(response, 'Fallback'); |
|||
|
|||
expect(result).toEqual(new ErrorDto(400, 'My-Message', ['My-Detail'], response)); |
|||
}); |
|||
|
|||
it('should return error from error json', () => { |
|||
const error = { message: 'My-Message', details: ['My-Detail'] }; |
|||
|
|||
const response: any = { status: 400, error: JSON.stringify(error) }; |
|||
const result = parseError(response, 'Fallback'); |
|||
|
|||
expect(result).toEqual(new ErrorDto(400, 'My-Message', ['My-Detail'], response)); |
|||
}); |
|||
|
|||
it('should return default when object is invalid', () => { |
|||
const error = { text: 'invalid' }; |
|||
|
|||
const response: any = { status: 400, error }; |
|||
const result = parseError(response, 'Fallback'); |
|||
|
|||
expect(result).toEqual(new ErrorDto(500, 'Fallback', [], response)); |
|||
}); |
|||
|
|||
it('should return default when json is invalid', () => { |
|||
const error = '{{'; |
|||
|
|||
const response: any = { status: 400, error }; |
|||
const result = parseError(response, 'Fallback'); |
|||
|
|||
expect(result).toEqual(new ErrorDto(500, 'Fallback', [], response)); |
|||
}); |
|||
}); |
|||
Loading…
Reference in new issue