From e960a7676d314885ab1758ac1a9e861664eb6de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Sat, 24 Feb 2024 22:16:40 +0100 Subject: [PATCH] fix(ns-openapi-3-1): retain meta & attributes during refracting (#3861) This change is specific to cases when semantic ApiDOM is refractored from generic ApiDOM. Refs #3842 --- .../elements/Info/__snapshots__/index.ts.snap | 2 ++ .../test/refractor/elements/Info/index.ts | 28 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/apidom-ns-openapi-3-1/test/refractor/elements/Info/__snapshots__/index.ts.snap b/packages/apidom-ns-openapi-3-1/test/refractor/elements/Info/__snapshots__/index.ts.snap index c0503ac3d..fec1c2310 100644 --- a/packages/apidom-ns-openapi-3-1/test/refractor/elements/Info/__snapshots__/index.ts.snap +++ b/packages/apidom-ns-openapi-3-1/test/refractor/elements/Info/__snapshots__/index.ts.snap @@ -1,5 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`refractor elements InfoElement given generic ApiDOM element should refract to semantic ApiDOM tree 1`] = `(InfoElement)`; + exports[`refractor elements InfoElement should refract to semantic ApiDOM tree 1`] = ` (InfoElement (MemberElement diff --git a/packages/apidom-ns-openapi-3-1/test/refractor/elements/Info/index.ts b/packages/apidom-ns-openapi-3-1/test/refractor/elements/Info/index.ts index 18c5918b1..31fe2b709 100644 --- a/packages/apidom-ns-openapi-3-1/test/refractor/elements/Info/index.ts +++ b/packages/apidom-ns-openapi-3-1/test/refractor/elements/Info/index.ts @@ -1,5 +1,5 @@ -import { expect } from 'chai'; -import { sexprs } from '@swagger-api/apidom-core'; +import { assert, expect } from 'chai'; +import { ObjectElement, sexprs, toValue } from '@swagger-api/apidom-core'; import { InfoElement } from '../../../../src'; @@ -19,6 +19,30 @@ describe('refractor', function () { expect(sexprs(infoElement)).toMatchSnapshot(); }); + + context('given generic ApiDOM element', function () { + let infoElement: InfoElement; + + beforeEach(function () { + infoElement = InfoElement.refract( + new ObjectElement({}, { classes: ['example'] }, { attr: true }), + ) as InfoElement; + }); + + specify('should refract to semantic ApiDOM tree', function () { + expect(sexprs(infoElement)).toMatchSnapshot(); + }); + + specify('should deepmerge meta', function () { + assert.deepEqual(toValue(infoElement.meta), { + classes: ['info', 'example'], + }); + }); + + specify('should deepmerge attributes', function () { + assert.isTrue(infoElement.attributes.get('attr').equals(true)); + }); + }); }); }); });