From b254a07e570a92ea96306628634f436d2e03b49d Mon Sep 17 00:00:00 2001 From: Carolina Wright Date: Wed, 12 Oct 2022 15:03:32 -0300 Subject: [PATCH 1/3] fix(ApiFormItemElement): no selected value for enum --- demo/W-11836777/W-11836777.yaml | 87 ++++++++++++++++++++++++++++ demo/api-form-item.js | 25 ++++++++ demo/apis.json | 1 + src/ApiFormItemElement.js | 3 +- test/ApiFormItemElement.enum.test.js | 19 ++++++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 demo/W-11836777/W-11836777.yaml diff --git a/demo/W-11836777/W-11836777.yaml b/demo/W-11836777/W-11836777.yaml new file mode 100644 index 0000000..2b5f331 --- /dev/null +++ b/demo/W-11836777/W-11836777.yaml @@ -0,0 +1,87 @@ +openapi: 3.0.0 +info: + title: eMPF API Specification - Contribution Module + description: eMPF API Specification - Contribution Module + version: 0.1.0 +paths: + /cas/ad/contribution/external/v1/bill/list: + get: + tags: + - ER-Portal-API + summary: CON-PERIOD-BILLABLE CON - Retrieve period bill + description: | + **API ID:** CON-PERIOD-BILLABLE \ + **CM:** CM-Web-Employer-Contribution A1, A2, A3, A4, B1, B2, B3, B4 \ + **FS:** FS-UF-CON-REE-009,FS-UF-CON-CEE-001 \ + CON - Retrieve period bill + parameters: + - $ref: '#/components/parameters/pageSize' + responses: + '200': + description: successfully + content: + application/json: + schema: + $ref: '#/components/schemas/periodBillableResponse' + '400': + $ref: '#/components/responses/400' + security: + - bearerAuth: [] + +components: + parameters: + pageSize: + in: query + required: true + name: pageSize + description: Page Size + schema: + enum: + - 25 + - 50 + - 100 + example: 50 + type: integer + schemas: + GlobalSuccessResponse: + type: object + properties: + success: + type: boolean + description: The flag indicates there is no bussiness error occurred in the request + code: + type: integer + example: '200' + periodBillableResponse: + allOf: + - $ref: '#/components/schemas/GlobalSuccessResponse' + - properties: + payload: + $ref: '#/components/schemas/periodBillablesResDto' + periodBillablesResDto: + type: object + properties: + pageRecords: + type: integer + example: 50 + page: + type: integer + example: 0 + pageSize: + type: integer + example: 50 + totalPages: + type: integer + example: 3 + totalRecords: + type: integer + example: 139 + responses: + '400': + description: Business validation exception + + securitySchemes: + bearerAuth: + type: http + scheme: bearer + bearerFormat: JWT diff --git a/demo/api-form-item.js b/demo/api-form-item.js index ad38125..26a7f81 100644 --- a/demo/api-form-item.js +++ b/demo/api-form-item.js @@ -121,6 +121,18 @@ class ComponentDemo extends DemoPage { enum: ['apple', 'banana', 'cherries', 'grapes', 'lemon', 'orange', 'pear', 'watermelon'] } }); + + this.m12 = /** @type AmfFormItem */({ + name: '', + value: 50, + schema: { + required: true, + apiType: 'integer', + inputLabel: 'Enum integer', + inputType: 'text', + enum: ['25', '50', '100'] + } + }); } _readonlyHandler(e) { @@ -306,6 +318,19 @@ class ComponentDemo extends DemoPage { @change="${this._valueHandler}"> ${this.v10} + +
+

Enum with integer options

+ +
`; } } diff --git a/demo/apis.json b/demo/apis.json index 6fe2566..062c704 100644 --- a/demo/apis.json +++ b/demo/apis.json @@ -6,5 +6,6 @@ "annotated-oauth2/annotated-oauth2.raml": "RAML 1.0", "APIC-298/APIC-298.json": ["OAS 2.0", "application/json"], "APIC-289/APIC-289.yaml": ["OAS 2.0", "application/yaml"], + "W-11836777/W-11836777.yaml": ["OAS 3.0", "application/yaml"], "no-auto-encoding/no-auto-encoding.raml": "RAML 1.0" } diff --git a/src/ApiFormItemElement.js b/src/ApiFormItemElement.js index 49c8ea1..4a928cb 100644 --- a/src/ApiFormItemElement.js +++ b/src/ApiFormItemElement.js @@ -502,6 +502,7 @@ export class ApiFormItemElement extends ValidatableMixin(LitElement) { // non required items should have an option to set a null value. values.unshift(''); } + const selectedValue = schema.apiType === 'integer' ? value.toString() : value; return html` diff --git a/test/ApiFormItemElement.enum.test.js b/test/ApiFormItemElement.enum.test.js index ba90506..65ca799 100644 --- a/test/ApiFormItemElement.enum.test.js +++ b/test/ApiFormItemElement.enum.test.js @@ -111,6 +111,25 @@ describe('ApiFormItemElement', () => { const item = items[0]; assert.equal(item.getAttribute('data-value'), '', 'has no value'); }); + + it('renders template when no enum values', async () => { + element.model = { + name: '', + value: 50, + schema: { + required: true, + apiType: 'integer', + inputLabel: 'Enum integer', + inputType: 'text', + enum: ['25', '50', '100'] + } + }; + await nextFrame(); + await nextFrame(); + + const listBox = element.shadowRoot.querySelector('anypoint-listbox'); + assert.isDefined(listBox.selected, 'listbox has the property'); + }); }); describe('Enum values: a11y', () => { From 05658dc2e670c9d844520e8019964e60720fc41e Mon Sep 17 00:00:00 2001 From: Carolina Wright Date: Wed, 12 Oct 2022 15:04:05 -0300 Subject: [PATCH 2/3] build: bump version --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index d0e6db2..50c8ccb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@api-components/api-forms", - "version": "0.2.4", + "version": "0.2.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0b8cb58..43eec17 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@api-components/api-forms", "description": "A library containing helper classes to compute API data from the AMF web API model.", - "version": "0.2.4", + "version": "0.2.5", "license": "Apache-2.0", "main": "index.js", "module": "index.js", From 70fe8a5fdae272c7e1ae1818a2dee3fbc40ffe28 Mon Sep 17 00:00:00 2001 From: Carolina Wright Date: Wed, 12 Oct 2022 15:23:12 -0300 Subject: [PATCH 3/3] test: fix name --- test/ApiFormItemElement.enum.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ApiFormItemElement.enum.test.js b/test/ApiFormItemElement.enum.test.js index 65ca799..2b0a54a 100644 --- a/test/ApiFormItemElement.enum.test.js +++ b/test/ApiFormItemElement.enum.test.js @@ -112,7 +112,7 @@ describe('ApiFormItemElement', () => { assert.equal(item.getAttribute('data-value'), '', 'has no value'); }); - it('renders template when no enum values', async () => { + it('renders listBox with selected item', async () => { element.model = { name: '', value: 50,