Skip to content

Commit

Permalink
Merge pull request #18 from alexa/apl-suggester-2023.1
Browse files Browse the repository at this point in the history
Release APL Suggester 2023.1
  • Loading branch information
rahulbanerjee26 committed Feb 6, 2023
2 parents 03cd93c + 5b41909 commit e73b4ec
Show file tree
Hide file tree
Showing 85 changed files with 3,789 additions and 1,344 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apl-suggester",
"version": "2022.2.0",
"version": "2023.1.0",
"description": "This Package is developed for providing suggestions and validations on APL templates.",
"engines": {
"node": ">=8.0.0"
Expand Down Expand Up @@ -75,8 +75,8 @@
"@types/node": "12.0.x",
"@types/sinon": "2.2.x",
"ajv": "6.12.3",
"axios": ">=0.21.1",
"immutable": ">4.0.0-rc",
"axios": "0.27.2",
"immutable": "4.1.0",
"jsdom-global": "3.0.x",
"ts-node": "3.3.x",
"typescript": "3.x"
Expand Down
32 changes: 0 additions & 32 deletions src/__tests__/CommandSchemaValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,6 @@ describe('CommandSchemaValidator.', () => {
await verifyCommand('SetFocusCommand.json', 'SetFocus');
});

it('should validate Sequential command.', async () => {
await verifyCommand('SequentialCommand.json', 'Sequential');
});

it('should validate Parallel command.', async () => {
await verifyCommand('ParallelCommand.json', 'Parallel');
});

it('should validate SendEvent command.', async () => {
await verifyCommand('SendEventCommand.json', 'SendEvent');
});

it('should validate SetValue command.', async () => {
await verifyCommand('SetValueCommand.json', 'SetValue');
});

it('should validate SetState command.', async () => {
await verifyCommand('SetStateCommand.json', 'SetState');
});

it('should validate SetFocus command.', async () => {
await verifyCommand('SetFocusCommand.json', 'SetFocus');
});

it('should validate ClearFocus command.', async () => {
await verifyCommand('ClearFocusCommand.json', 'ClearFocus');
});
Expand Down Expand Up @@ -102,10 +78,6 @@ describe('CommandSchemaValidator.', () => {
await verifyCommand('SetPageCommand.json', 'SetPage');
});

it('should validate SetFocus command.', async () => {
await verifyCommand('SetFocusCommand.json', 'SetFocus');
});

it('should validate AutoPage command.', async () => {
await verifyCommand('AutoPageCommand.json', 'AutoPage');
});
Expand All @@ -118,10 +90,6 @@ describe('CommandSchemaValidator.', () => {
await verifyCommand('ControlMediaCommand.json', 'ControlMedia');
});

it('should validate PlayMedia command.', async () => {
await verifyCommand('PlayMediaCommand.json', 'PlayMedia');
});

it('should validate AnimateItem command.', async () => {
await verifyCommand('AnimateItemCommand.json', 'AnimateItem');
});
Expand Down
37 changes: 26 additions & 11 deletions src/__tests__/ComponentSchemaController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,21 @@ import { IMPORT_LAYOUT_TEMPLATE_13 } from '../util/__tests__/template_test_cases
import { getSampleTemplate, SampleTemplateName } from '../configs';
import * as aplTemplate from '../configs/templates/default_apl.json';

let stub = null;
let componentSchemaController = null;

const validate = async (fileName : string, componentType : string, parentComponent? : string) => {
const data = fs.readFileSync(`src/__tests__/components/${fileName}`, 'utf8');
return await componentSchemaController.validateComponent(aplTemplate, JSON.parse(data),
componentType, parentComponent);
};

const verifyComponent = async (fileName : string, componentType : string, parentComponent? : string) => {
const result = await validate(fileName, componentType, parentComponent);
expect(result.length).to.equal(0);
};

describe('ComponentSchemaController.', () => {
let stub;
let componentSchemaController;

beforeEach(() => {
componentSchemaController = ComponentSchemaController.getInstance();
Expand Down Expand Up @@ -84,7 +96,7 @@ describe('ComponentSchemaController.', () => {
it('should received correct amount of validation errors.', async () => {
const data = fs.readFileSync(`src/__tests__/components/ErrorComponent.json`, 'utf8');
const result = await componentSchemaController.validateComponent({}, JSON.parse(data), 'Image');
expect(result.length).to.be.equal(7);
expect(result.length).to.be.equal(8);
expect(result[0].path).to.be.equal('/');
expect(result[0].level).to.be.equal(NotificationLevel.WARN);
expect(result[0].errorMessage.indexOf('position') > 0).to.be.equal(true);
Expand All @@ -103,6 +115,8 @@ describe('ComponentSchemaController.', () => {
expect(result[5].level).to.be.equal(NotificationLevel.WARN);
expect(result[6].path).to.be.equal('/role');
expect(result[6].level).to.be.equal(NotificationLevel.WARN);
expect(result[7].path).to.be.equal('/filters/0/kind');
expect(result[7].level).to.be.equal(NotificationLevel.WARN);
});

it('should validate Image component correctly with mixin support.', async () => {
Expand Down Expand Up @@ -165,22 +179,23 @@ describe('ComponentSchemaController.', () => {
await verifyComponent('EditText.json', 'EditText');
});

it('should validate Pager component.', async () => {
it('should validate Pager component with onSpeechMark.', async () => {
await verifyComponent('Pager.json', 'Pager');
});

it('should validate Video component.', async () => {
await verifyComponent('Video.json', 'Video');
});

it('should NOT allow textTrack and textTracks in Video component.', async () => {
const result = await validate('VideoTextTracksError.json', 'Video');
expect(result.length).to.equal(3);
expect(result[0].errorMessage).to.equal('should have required property \'type\'');
// In coming 2023.2, "type" enum expects to include "subtitle" and maybe more
expect(result[1].errorMessage).to.equal('should be equal to one of the allowed values : caption');
expect(result[2].errorMessage).to.equal('should NOT be valid');
});
it('should validate Extension component', async () => {
await verifyComponent('ExtensionComponent.json', 'ExtensionComponent');
});

async function verifyComponent(fileName : string, componentType : string, parentComponent? : string) {
const data = fs.readFileSync(`src/__tests__/components/${fileName}`, 'utf8');
const result = await componentSchemaController.validateComponent(aplTemplate, JSON.parse(data),
componentType, parentComponent);
expect(result.length).to.be.equal(0);
}
});
22 changes: 20 additions & 2 deletions src/__tests__/StaticAplTemplateValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,35 @@ describe('Integration Test to verify the JSON schema.', () => {
afterEach(() => {
stub.restore();
});

it('should compile with sample templates.', async () => {
const template = getSampleTemplate(SampleTemplateName.IMAGE_RIGHT_DETAIL);
const result = await validator.validate(template.apl);
expect(result.length).to.be.equal(0);
});

it('should received correct amount of validation errors.', async () => {
it('should receive error for unspecified handler', async () => {
const result = await verifyTemplate('allowedRootHandlerTemplate.json');
expect(result.length).to.equal(1);
expect(result[0].errorMessage).to.equal('should NOT have additional properties : onNonExistHandler');
});
it('should allow onSpeechMark handler in touchwrapper component', async () => {
await readSchemaAndPassAllValidations('allowedComponentHandlerTemplate.json');
});

it('should receive correct amount of validation errors.', async () => {
const result = await verifyTemplate('errorTemplate.json');
expect(result.length).to.be.equal(12);
});

it('should receive correct amount of Command validation errors.', async () => {
const result = await verifyTemplate('errorCommandTemplate.json');
expect(result.length).to.equal(3);
expect(result[0].path).to.equal('/onConfigChange/1/preservedSequencers');
expect(result[1].path).to.equal('/onMount/0/state');
expect(result[2].path).to.equal('/onMount/0');
});

it('should compile with video template when souce is array of string.', async () => {
await readSchemaAndPassAllValidations('videoAplTemplateWithArraySource.json');
});
Expand Down Expand Up @@ -90,7 +108,7 @@ describe('Integration Test to verify the JSON schema.', () => {

it('should show correct validation errors with resource template.', async () => {
const result = await verifyTemplate('errorResourceAplTemplate.json');
expect(result).to.have.lengthOf(2);
expect(result).to.have.lengthOf(6);
});

it('should compile with graphic template and show errors', async () => {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/commands/SequentialCommand.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"delay": 1000,
"repeatCount": 2,
"commands": [],
"catch": [],
"finally": [],
"sequencer": "MAIN"
}
9 changes: 8 additions & 1 deletion src/__tests__/components/ErrorComponent.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,12 @@
"paddingBottom": 40,
"paddingStart": 10,
"paddingEnd": "20dp",
"layoutDirection": "LTL"
"layoutDirection": "LTL",
"filters": [
{
"type": "Noise",
"sigma": 20,
"kind": "invalid_value"
}
]
}
7 changes: 6 additions & 1 deletion src/__tests__/components/Image.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@
},
{
"type": "Noise",
"sigma": 20
"sigma": 20,
"kind": "gaussian"
},
{
"type": "Blend",
"destination": -2,
"mode": "normal"
},
{
"type": "Blend",
"mode": "source-atop"
},
{
"type": "Color",
"color": "#B620E0"
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/components/Pager.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
"value": 0
}
],
"onSpeechMark": [
{
"type": "SetValue",
"componentId": "test",
"property": "test",
"value": 0.5
}
],
"pageDirection": "vertical",
"items": [
{
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/components/Sequence.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"scrollDirection": "vertical",
"paddingLeft": "@marginLeft",
"paddingRight": "@marginRight",
"-fastScrollScale": 0.5,
"data": "${listData}",
"numbered": true,
"bind": [
Expand Down
7 changes: 6 additions & 1 deletion src/__tests__/components/Video.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
},
{
"url": ["https://test", "${expr}"],
"offset": 150
"offset": 150,
"textTrack": [{ "url": "https://test1", "type": "caption" }]
},
{
"url": "${some-expression1}",
"textTracks": [{ "url": "https://test2", "type": "caption", "description":"someDesc" }]
}
],
"autoplay": true,
Expand Down
21 changes: 21 additions & 0 deletions src/__tests__/components/VideoTextTracksError.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "Video",
"source": [
{
"url": "https://testingUrl",
"textTracks": [{ "url": "https://test1", "description":"no type" }]


},
{
"url": "${some-expression}",
"textTrack": [{ "url": "https://test2", "type": "subtitle" }]
},
{
"url": ["https://test", "${expr}"],
"offset": 150,
"textTrack": [{ "url": "https://test3", "type": "caption" }],
"textTracks": [{ "url": "https://test4", "type": "caption", "description":"someDesc" }]
}
]
}
3 changes: 2 additions & 1 deletion src/__tests__/graphics/AVGTextItem.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
"radius": 3,
"verticalOffset": 3
}
]
],
"description": "This is a sample text AVG"
}

0 comments on commit e73b4ec

Please sign in to comment.