From 6768b7d58d66ffe421da3e0f652563d368ee5e14 Mon Sep 17 00:00:00 2001 From: Michael Wiesenbauer <11874984+mwiesenbauer@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:20:47 +0100 Subject: [PATCH] add tests for App component rendering --- .../__snapshots__/index.test.js.snap | 1081 +++++++++++++++++ test/components/index.test.js | 20 +- 2 files changed, 1100 insertions(+), 1 deletion(-) diff --git a/test/components/__snapshots__/index.test.js.snap b/test/components/__snapshots__/index.test.js.snap index e20d6d272..62d969e24 100644 --- a/test/components/__snapshots__/index.test.js.snap +++ b/test/components/__snapshots__/index.test.js.snap @@ -1,5 +1,1086 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`App component should render AsyncAPI v2 document 1`] = ` +"const schema = { + \\"asyncapi\\": \\"2.0.0\\", + \\"info\\": { + \\"title\\": \\"Streetlights API\\", + \\"version\\": \\"1.0.0\\", + \\"description\\": \\"The Smartylighting Streetlights API allows you to remotely manage the city lights.\\\\n\\\\n### Check out its awesome features:\\\\n\\\\n* Turn a specific streetlight on/off 🌃\\\\n* Dim a specific streetlight 😎\\\\n* Receive real-time information about environmental lighting conditions 📈\\\\n\\", + \\"license\\": { + \\"name\\": \\"Apache 2.0\\", + \\"url\\": \\"https://www.apache.org/licenses/LICENSE-2.0\\" + } + }, + \\"servers\\": { + \\"production\\": { + \\"url\\": \\"test.mosquitto.org:{port}\\", + \\"protocol\\": \\"mqtt\\", + \\"description\\": \\"Test broker\\", + \\"variables\\": { + \\"port\\": { + \\"description\\": \\"Secure connection (TLS) is available through port 8883.\\", + \\"default\\": \\"1883\\", + \\"enum\\": [ + \\"1883\\", + \\"8883\\" + ] + } + }, + \\"security\\": [ + { + \\"apiKey\\": [] + }, + { + \\"supportedOauthFlows\\": [ + \\"streetlights:on\\", + \\"streetlights:off\\", + \\"streetlights:dim\\" + ] + }, + { + \\"openIdConnectWellKnown\\": [] + } + ] + } + }, + \\"defaultContentType\\": \\"application/json\\", + \\"tags\\": [ + { + \\"name\\": \\"One\\" + }, + { + \\"name\\": \\"Two\\" + } + ], + \\"channels\\": { + \\"smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured\\": { + \\"description\\": \\"The topic on which measured values may be produced and consumed.\\", + \\"parameters\\": { + \\"streetlightId\\": { + \\"description\\": \\"The ID of the streetlight.\\", + \\"schema\\": { + \\"type\\": \\"string\\", + \\"x-parser-schema-id\\": \\"streetlightId\\" + } + } + }, + \\"publish\\": { + \\"summary\\": \\"Inform about environmental lighting conditions of a particular streetlight.\\", + \\"operationId\\": \\"receiveLightMeasurement\\", + \\"traits\\": [ + { + \\"bindings\\": { + \\"kafka\\": { + \\"clientId\\": \\"my-app-id\\" + } + } + } + ], + \\"message\\": { + \\"name\\": \\"lightMeasured\\", + \\"title\\": \\"Light measured\\", + \\"summary\\": \\"Inform about environmental lighting conditions of a particular streetlight.\\", + \\"contentType\\": \\"application/json\\", + \\"traits\\": [ + { + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + } + } + ], + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"lumens\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"description\\": \\"Light intensity measured in lumens.\\", + \\"x-parser-schema-id\\": \\"\\" + }, + \\"sentAt\\": { + \\"type\\": \\"string\\", + \\"format\\": \\"date-time\\", + \\"description\\": \\"Date and time when the message was sent.\\", + \\"x-parser-schema-id\\": \\"sentAt\\" + } + }, + \\"x-parser-schema-id\\": \\"lightMeasuredPayload\\" + }, + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"tags\\": [ + { + \\"name\\": \\"One\\" + } + ], + \\"bindings\\": { + \\"kafka\\": { + \\"clientId\\": \\"my-app-id\\" + } + } + } + }, + \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/on\\": { + \\"parameters\\": { + \\"streetlightId\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.parameters.streetlightId\\" + }, + \\"subscribe\\": { + \\"operationId\\": \\"turnOn\\", + \\"traits\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.traits[0]\\" + ], + \\"message\\": { + \\"name\\": \\"turnOnOff\\", + \\"title\\": \\"Turn on/off\\", + \\"summary\\": \\"Command a particular streetlight to turn the lights on or off.\\", + \\"traits\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.message.traits[0]\\" + ], + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"command\\": { + \\"type\\": \\"string\\", + \\"enum\\": [ + \\"on\\", + \\"off\\" + ], + \\"description\\": \\"Whether to turn on or off the light.\\", + \\"x-parser-schema-id\\": \\"\\" + }, + \\"sentAt\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.message.payload.properties.sentAt\\" + }, + \\"x-parser-schema-id\\": \\"turnOnOffPayload\\" + }, + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"tags\\": [ + { + \\"name\\": \\"Two\\" + } + ], + \\"bindings\\": { + \\"kafka\\": { + \\"clientId\\": \\"my-app-id\\" + } + } + } + }, + \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/off\\": { + \\"parameters\\": { + \\"streetlightId\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.parameters.streetlightId\\" + }, + \\"subscribe\\": { + \\"operationId\\": \\"turnOff\\", + \\"traits\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.traits[0]\\" + ], + \\"message\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.subscribe.message\\", + \\"tags\\": [ + { + \\"name\\": \\"One\\" + } + ], + \\"bindings\\": { + \\"kafka\\": { + \\"clientId\\": \\"my-app-id\\" + } + } + } + }, + \\"smartylighting/streetlights/1/0/action/{streetlightId}/dim\\": { + \\"parameters\\": { + \\"streetlightId\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.parameters.streetlightId\\" + }, + \\"subscribe\\": { + \\"operationId\\": \\"dimLight\\", + \\"traits\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.traits[0]\\" + ], + \\"message\\": { + \\"name\\": \\"dimLight\\", + \\"title\\": \\"Dim light\\", + \\"summary\\": \\"Command a particular streetlight to dim the lights.\\", + \\"traits\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.message.traits[0]\\" + ], + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"percentage\\": { + \\"type\\": \\"integer\\", + \\"description\\": \\"Percentage to which the light should be dimmed to.\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"sentAt\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.message.payload.properties.sentAt\\" + }, + \\"x-parser-schema-id\\": \\"dimLightPayload\\" + }, + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"tags\\": [ + { + \\"name\\": \\"Two\\" + } + ], + \\"bindings\\": { + \\"kafka\\": { + \\"clientId\\": \\"my-app-id\\" + } + } + } + } + }, + \\"components\\": { + \\"messages\\": { + \\"lightMeasured\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.message\\", + \\"turnOnOff\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.subscribe.message\\", + \\"dimLight\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/dim.subscribe.message\\" + }, + \\"schemas\\": { + \\"lightMeasuredPayload\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.message.payload\\", + \\"turnOnOffPayload\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.subscribe.message.payload\\", + \\"dimLightPayload\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/dim.subscribe.message.payload\\", + \\"sentAt\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.message.payload.properties.sentAt\\" + }, + \\"securitySchemes\\": { + \\"apiKey\\": { + \\"type\\": \\"apiKey\\", + \\"in\\": \\"user\\", + \\"description\\": \\"Provide your API key as the user and leave the password empty.\\" + }, + \\"supportedOauthFlows\\": { + \\"type\\": \\"oauth2\\", + \\"description\\": \\"Flows to support OAuth 2.0\\", + \\"flows\\": { + \\"implicit\\": { + \\"authorizationUrl\\": \\"https://authserver.example/auth\\", + \\"scopes\\": { + \\"streetlights:on\\": \\"Ability to switch lights on\\", + \\"streetlights:off\\": \\"Ability to switch lights off\\", + \\"streetlights:dim\\": \\"Ability to dim the lights\\" + } + }, + \\"password\\": { + \\"tokenUrl\\": \\"https://authserver.example/token\\", + \\"scopes\\": { + \\"streetlights:on\\": \\"Ability to switch lights on\\", + \\"streetlights:off\\": \\"Ability to switch lights off\\", + \\"streetlights:dim\\": \\"Ability to dim the lights\\" + } + }, + \\"clientCredentials\\": { + \\"tokenUrl\\": \\"https://authserver.example/token\\", + \\"scopes\\": { + \\"streetlights:on\\": \\"Ability to switch lights on\\", + \\"streetlights:off\\": \\"Ability to switch lights off\\", + \\"streetlights:dim\\": \\"Ability to dim the lights\\" + } + }, + \\"authorizationCode\\": { + \\"authorizationUrl\\": \\"https://authserver.example/auth\\", + \\"tokenUrl\\": \\"https://authserver.example/token\\", + \\"refreshUrl\\": \\"https://authserver.example/refresh\\", + \\"scopes\\": { + \\"streetlights:on\\": \\"Ability to switch lights on\\", + \\"streetlights:off\\": \\"Ability to switch lights off\\", + \\"streetlights:dim\\": \\"Ability to dim the lights\\" + } + } + } + }, + \\"openIdConnectWellKnown\\": { + \\"type\\": \\"openIdConnect\\", + \\"openIdConnectUrl\\": \\"https://authserver.example/.well-known\\" + } + }, + \\"parameters\\": { + \\"streetlightId\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.parameters.streetlightId\\" + }, + \\"messageTraits\\": { + \\"commonHeaders\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.message.traits[0]\\" + }, + \\"operationTraits\\": { + \\"kafka\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish.traits[0]\\" + } + }, + \\"x-parser-spec-parsed\\": true, + \\"x-parser-api-version\\": 3, + \\"x-parser-spec-stringified\\": true +}; + const config = {\\"show\\":{\\"sidebar\\":true},\\"sidebar\\":{\\"showOperations\\":\\"byDefault\\"}}; + const appRoot = document.getElementById('root'); + AsyncApiStandalone.render( + { schema, config, }, appRoot + );" +`; + +exports[`App component should render AsyncAPI v3 document 1`] = ` +"const schema = { + \\"asyncapi\\": \\"3.0.0\\", + \\"info\\": { + \\"title\\": \\"Streetlights API\\", + \\"version\\": \\"1.0.0\\", + \\"description\\": \\"The Smartylighting Streetlights API allows you to remotely manage the city lights.\\\\n\\\\n### Check out its awesome features:\\\\n\\\\n* Turn a specific streetlight on/off 🌃\\\\n* Dim a specific streetlight 😎\\\\n* Receive real-time information about environmental lighting conditions 📈\\\\n\\", + \\"license\\": { + \\"name\\": \\"Apache 2.0\\", + \\"url\\": \\"https://www.apache.org/licenses/LICENSE-2.0\\" + } + }, + \\"defaultContentType\\": \\"application/json\\", + \\"servers\\": { + \\"production\\": { + \\"host\\": \\"test.mosquitto.org:{port}\\", + \\"protocol\\": \\"mqtt\\", + \\"description\\": \\"Test broker\\", + \\"variables\\": { + \\"port\\": { + \\"description\\": \\"Secure connection (TLS) is available through port 8883.\\", + \\"default\\": \\"1883\\", + \\"enum\\": [ + \\"1883\\", + \\"8883\\" + ] + } + } + } + }, + \\"channels\\": { + \\"smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured\\": { + \\"address\\": \\"smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured\\", + \\"messages\\": { + \\"receiveLightMeasurement.message\\": { + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"name\\": \\"lightMeasured\\", + \\"title\\": \\"Light measured\\", + \\"summary\\": \\"Inform about environmental lighting conditions of a particular streetlight.\\", + \\"contentType\\": \\"application/json\\", + \\"tags\\": [ + { + \\"name\\": \\"message-tag1\\", + \\"externalDocs\\": { + \\"description\\": \\"External docs description 1\\", + \\"url\\": \\"https://www.asyncapi.com/\\" + } + }, + { + \\"name\\": \\"message-tag2\\", + \\"description\\": \\"Description 2\\", + \\"externalDocs\\": { + \\"url\\": \\"https://www.asyncapi.com/\\" + } + }, + { + \\"name\\": \\"message-tag3\\" + }, + { + \\"name\\": \\"message-tag4\\", + \\"description\\": \\"Description 4\\" + }, + { + \\"name\\": \\"message-tag5\\", + \\"externalDocs\\": { + \\"url\\": \\"https://www.asyncapi.com/\\" + } + } + ], + \\"traits\\": [ + { + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + } + } + ], + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"lumens\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"description\\": \\"Light intensity measured in lumens.\\", + \\"x-pi\\": false, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"sentAt\\": { + \\"type\\": \\"string\\", + \\"format\\": \\"date-time\\", + \\"description\\": \\"Date and time when the message was sent.\\", + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"x-parser-unique-object-id\\": \\"receiveLightMeasurement.message\\" + } + }, + \\"description\\": \\"The topic on which measured values may be produced and consumed.\\", + \\"parameters\\": { + \\"streetlightId\\": { + \\"description\\": \\"The ID of the streetlight.\\" + } + }, + \\"x-parser-unique-object-id\\": \\"smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured\\" + }, + \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/on\\": { + \\"address\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/on\\", + \\"messages\\": { + \\"turnOn.message\\": { + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"name\\": \\"turnOnOff\\", + \\"title\\": \\"Turn on/off\\", + \\"summary\\": \\"Command a particular streetlight to turn the lights on or off.\\", + \\"traits\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.messages.receiveLightMeasurement.message.traits[0]\\" + ], + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"command\\": { + \\"type\\": \\"string\\", + \\"enum\\": [ + \\"on\\", + \\"off\\" + ], + \\"description\\": \\"Whether to turn on or off the light.\\", + \\"x-pi\\": false, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"sentAt\\": { + \\"type\\": \\"string\\", + \\"format\\": \\"date-time\\", + \\"description\\": \\"Date and time when the message was sent.\\", + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"x-parser-unique-object-id\\": \\"turnOn.message\\" + } + }, + \\"parameters\\": { + \\"streetlightId\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.parameters.streetlightId\\" + }, + \\"x-parser-unique-object-id\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/on\\" + }, + \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/off\\": { + \\"address\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/off\\", + \\"messages\\": { + \\"turnOff.message\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.messages.turnOn.message\\" + }, + \\"parameters\\": { + \\"streetlightId\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.parameters.streetlightId\\" + }, + \\"x-parser-unique-object-id\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/off\\" + }, + \\"smartylighting/streetlights/1/0/action/{streetlightId}/dim\\": { + \\"address\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/dim\\", + \\"messages\\": { + \\"dimLight.message\\": { + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"name\\": \\"dimLight\\", + \\"title\\": \\"Dim light\\", + \\"summary\\": \\"Command a particular streetlight to dim the lights.\\", + \\"traits\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.messages.receiveLightMeasurement.message.traits[0]\\" + ], + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"percentage\\": { + \\"type\\": \\"integer\\", + \\"description\\": \\"Percentage to which the light should be dimmed to.\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"sentAt\\": { + \\"type\\": \\"string\\", + \\"format\\": \\"date-time\\", + \\"description\\": \\"Date and time when the message was sent.\\", + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"x-parser-unique-object-id\\": \\"dimLight.message\\" + } + }, + \\"parameters\\": { + \\"streetlightId\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.parameters.streetlightId\\" + }, + \\"x-parser-unique-object-id\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/dim\\" + }, + \\"some.channel\\": { + \\"address\\": \\"some.channel\\", + \\"messages\\": { + \\"subscribe.message.0\\": { + \\"name\\": \\"Success\\", + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"result\\": { + \\"type\\": \\"string\\", + \\"examples\\": [ + \\"success\\" + ], + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"x-parser-unique-object-id\\": \\"subscribe.message.0\\" + }, + \\"subscribe.message.1\\": { + \\"name\\": \\"Failure\\", + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"error\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"errorCode\\": { + \\"type\\": \\"integer\\", + \\"x-parser-schema-id\\": \\"\\" + }, + \\"errorMessage\\": { + \\"type\\": \\"string\\", + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"x-parser-schema-id\\": \\"\\" + } + }, + \\"examples\\": [ + { + \\"error\\": { + \\"errorCode\\": 404, + \\"errorMessage\\": \\"Something messed up\\" + } + } + ], + \\"x-parser-schema-id\\": \\"\\" + }, + \\"x-parser-unique-object-id\\": \\"subscribe.message.1\\" + } + }, + \\"x-parser-unique-object-id\\": \\"some.channel\\" + } + }, + \\"operations\\": { + \\"receiveLightMeasurement\\": { + \\"bindings\\": { + \\"kafka\\": { + \\"clientId\\": { + \\"const\\": \\"my-app-id\\" + } + } + }, + \\"action\\": \\"receive\\", + \\"channel\\": { + \\"address\\": \\"smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured\\", + \\"messages\\": { + \\"receiveLightMeasurement.message\\": { + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100 + } + } + }, + \\"name\\": \\"lightMeasured\\", + \\"title\\": \\"Light measured\\", + \\"summary\\": \\"Inform about environmental lighting conditions of a particular streetlight.\\", + \\"contentType\\": \\"application/json\\", + \\"tags\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.messages.receiveLightMeasurement.message.tags\\", + \\"traits\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.messages.receiveLightMeasurement.message.traits\\", + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"lumens\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"description\\": \\"Light intensity measured in lumens.\\", + \\"x-pi\\": false + }, + \\"sentAt\\": { + \\"type\\": \\"string\\", + \\"format\\": \\"date-time\\", + \\"description\\": \\"Date and time when the message was sent.\\" + } + } + }, + \\"x-parser-unique-object-id\\": \\"receiveLightMeasurement.message\\" + } + }, + \\"description\\": \\"The topic on which measured values may be produced and consumed.\\", + \\"parameters\\": { + \\"streetlightId\\": { + \\"description\\": \\"The ID of the streetlight.\\" + } + }, + \\"x-parser-unique-object-id\\": \\"smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured\\" + }, + \\"summary\\": \\"Inform about environmental lighting conditions of a particular streetlight.\\", + \\"description\\": \\"This is the description with **bold** text.\\\\n\\\\nOn multiple lines.\\\\n\\", + \\"tags\\": [ + { + \\"name\\": \\"oparation-tag1\\", + \\"externalDocs\\": { + \\"description\\": \\"External docs description 1\\", + \\"url\\": \\"https://www.asyncapi.com/\\" + } + }, + { + \\"name\\": \\"oparation-tag2\\", + \\"description\\": \\"Description 2\\", + \\"externalDocs\\": { + \\"url\\": \\"https://www.asyncapi.com/\\" + } + }, + { + \\"name\\": \\"oparation-tag3\\" + }, + { + \\"name\\": \\"oparation-tag4\\", + \\"description\\": \\"Description 4\\" + }, + { + \\"name\\": \\"message-tag5\\", + \\"externalDocs\\": { + \\"url\\": \\"https://www.asyncapi.com/\\" + } + } + ], + \\"traits\\": [ + { + \\"bindings\\": { + \\"kafka\\": { + \\"clientId\\": { + \\"const\\": \\"my-app-id\\" + } + } + } + } + ], + \\"messages\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.messages.receiveLightMeasurement.message\\" + ], + \\"x-parser-unique-object-id\\": \\"receiveLightMeasurement\\" + }, + \\"turnOn\\": { + \\"bindings\\": { + \\"kafka\\": { + \\"clientId\\": { + \\"const\\": \\"my-app-id\\" + } + } + }, + \\"action\\": \\"send\\", + \\"channel\\": { + \\"address\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/on\\", + \\"messages\\": { + \\"turnOn.message\\": { + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100 + } + } + }, + \\"name\\": \\"turnOnOff\\", + \\"title\\": \\"Turn on/off\\", + \\"summary\\": \\"Command a particular streetlight to turn the lights on or off.\\", + \\"traits\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.messages.turnOn.message.traits\\", + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"command\\": { + \\"type\\": \\"string\\", + \\"enum\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.messages.turnOn.message.payload.properties.command.enum\\", + \\"description\\": \\"Whether to turn on or off the light.\\", + \\"x-pi\\": false + }, + \\"sentAt\\": { + \\"type\\": \\"string\\", + \\"format\\": \\"date-time\\", + \\"description\\": \\"Date and time when the message was sent.\\" + } + } + }, + \\"x-parser-unique-object-id\\": \\"turnOn.message\\" + } + }, + \\"parameters\\": { + \\"streetlightId\\": { + \\"description\\": \\"The ID of the streetlight.\\" + } + }, + \\"x-parser-unique-object-id\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/on\\" + }, + \\"traits\\": [ + \\"$ref:$.operations.receiveLightMeasurement.traits[0]\\" + ], + \\"messages\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.messages.turnOn.message\\" + ], + \\"x-parser-unique-object-id\\": \\"turnOn\\" + }, + \\"turnOff\\": { + \\"bindings\\": { + \\"kafka\\": { + \\"clientId\\": { + \\"const\\": \\"my-app-id\\" + } + } + }, + \\"action\\": \\"send\\", + \\"channel\\": { + \\"address\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/off\\", + \\"messages\\": { + \\"turnOff.message\\": { + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100 + } + } + }, + \\"name\\": \\"turnOnOff\\", + \\"title\\": \\"Turn on/off\\", + \\"summary\\": \\"Command a particular streetlight to turn the lights on or off.\\", + \\"traits\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.messages.turnOn.message.traits\\", + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"command\\": { + \\"type\\": \\"string\\", + \\"enum\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.messages.turnOn.message.payload.properties.command.enum\\", + \\"description\\": \\"Whether to turn on or off the light.\\", + \\"x-pi\\": false + }, + \\"sentAt\\": { + \\"type\\": \\"string\\", + \\"format\\": \\"date-time\\", + \\"description\\": \\"Date and time when the message was sent.\\" + } + } + }, + \\"x-parser-unique-object-id\\": \\"turnOn.message\\" + } + }, + \\"parameters\\": { + \\"streetlightId\\": { + \\"description\\": \\"The ID of the streetlight.\\" + } + }, + \\"x-parser-unique-object-id\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/turn/off\\" + }, + \\"traits\\": [ + \\"$ref:$.operations.receiveLightMeasurement.traits[0]\\" + ], + \\"messages\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.messages.turnOn.message\\" + ], + \\"x-parser-unique-object-id\\": \\"turnOff\\" + }, + \\"dimLight\\": { + \\"bindings\\": { + \\"kafka\\": { + \\"clientId\\": { + \\"const\\": \\"my-app-id\\" + } + } + }, + \\"action\\": \\"send\\", + \\"channel\\": { + \\"address\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/dim\\", + \\"messages\\": { + \\"dimLight.message\\": { + \\"headers\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"my-app-header\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"maximum\\": 100 + } + } + }, + \\"name\\": \\"dimLight\\", + \\"title\\": \\"Dim light\\", + \\"summary\\": \\"Command a particular streetlight to dim the lights.\\", + \\"traits\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/dim.messages.dimLight.message.traits\\", + \\"payload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"percentage\\": { + \\"type\\": \\"integer\\", + \\"description\\": \\"Percentage to which the light should be dimmed to.\\", + \\"minimum\\": 0, + \\"maximum\\": 100 + }, + \\"sentAt\\": { + \\"type\\": \\"string\\", + \\"format\\": \\"date-time\\", + \\"description\\": \\"Date and time when the message was sent.\\" + } + } + }, + \\"x-parser-unique-object-id\\": \\"dimLight.message\\" + } + }, + \\"parameters\\": { + \\"streetlightId\\": { + \\"description\\": \\"The ID of the streetlight.\\" + } + }, + \\"x-parser-unique-object-id\\": \\"smartylighting/streetlights/1/0/action/{streetlightId}/dim\\" + }, + \\"traits\\": [ + \\"$ref:$.operations.receiveLightMeasurement.traits[0]\\" + ], + \\"messages\\": [ + \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/dim.messages.dimLight.message\\" + ], + \\"x-parser-unique-object-id\\": \\"dimLight\\" + }, + \\"some.channel.subscribe\\": { + \\"action\\": \\"send\\", + \\"channel\\": \\"$ref:$.channels.some.channel\\", + \\"description\\": \\"this description shows in markdown\\", + \\"messages\\": [ + \\"$ref:$.channels.some.channel.messages.subscribe.message.0\\", + \\"$ref:$.channels.some.channel.messages.subscribe.message.1\\" + ], + \\"x-parser-unique-object-id\\": \\"some.channel.subscribe\\" + } + }, + \\"components\\": { + \\"messages\\": { + \\"lightMeasured\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.messages.receiveLightMeasurement.message\\", + \\"turnOnOff\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.messages.turnOn.message\\", + \\"dimLight\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/dim.messages.dimLight.message\\", + \\"successMessage\\": \\"$ref:$.channels.some.channel.messages.subscribe.message.0\\", + \\"failureMessage\\": \\"$ref:$.channels.some.channel.messages.subscribe.message.1\\" + }, + \\"schemas\\": { + \\"lightMeasuredPayload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"lumens\\": { + \\"type\\": \\"integer\\", + \\"minimum\\": 0, + \\"description\\": \\"Light intensity measured in lumens.\\", + \\"x-pi\\": false, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"sentAt\\": { + \\"type\\": \\"string\\", + \\"format\\": \\"date-time\\", + \\"description\\": \\"Date and time when the message was sent.\\", + \\"x-parser-schema-id\\": \\"sentAt\\" + } + }, + \\"x-parser-schema-id\\": \\"lightMeasuredPayload\\" + }, + \\"turnOnOffPayload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"command\\": { + \\"type\\": \\"string\\", + \\"enum\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.messages.turnOn.message.payload.properties.command.enum\\", + \\"description\\": \\"Whether to turn on or off the light.\\", + \\"x-pi\\": false, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"sentAt\\": \\"$ref:$.components.schemas.lightMeasuredPayload.properties.sentAt\\" + }, + \\"x-parser-schema-id\\": \\"turnOnOffPayload\\" + }, + \\"dimLightPayload\\": { + \\"type\\": \\"object\\", + \\"properties\\": { + \\"percentage\\": { + \\"type\\": \\"integer\\", + \\"description\\": \\"Percentage to which the light should be dimmed to.\\", + \\"minimum\\": 0, + \\"maximum\\": 100, + \\"x-parser-schema-id\\": \\"\\" + }, + \\"sentAt\\": \\"$ref:$.components.schemas.lightMeasuredPayload.properties.sentAt\\" + }, + \\"x-parser-schema-id\\": \\"dimLightPayload\\" + }, + \\"sentAt\\": \\"$ref:$.components.schemas.lightMeasuredPayload.properties.sentAt\\" + }, + \\"securitySchemes\\": { + \\"apiKey\\": { + \\"type\\": \\"apiKey\\", + \\"in\\": \\"user\\", + \\"description\\": \\"Provide your API key as the user and leave the password empty.\\" + }, + \\"supportedOauthFlows\\": { + \\"type\\": \\"oauth2\\", + \\"description\\": \\"Flows to support OAuth 2.0\\", + \\"flows\\": { + \\"implicit\\": { + \\"authorizationUrl\\": \\"https://authserver.example/auth\\", + \\"availableScopes\\": { + \\"streetlights:on\\": \\"Ability to switch lights on\\", + \\"streetlights:off\\": \\"Ability to switch lights off\\", + \\"streetlights:dim\\": \\"Ability to dim the lights\\" + } + }, + \\"password\\": { + \\"tokenUrl\\": \\"https://authserver.example/token\\", + \\"availableScopes\\": { + \\"streetlights:on\\": \\"Ability to switch lights on\\", + \\"streetlights:off\\": \\"Ability to switch lights off\\", + \\"streetlights:dim\\": \\"Ability to dim the lights\\" + } + }, + \\"clientCredentials\\": { + \\"tokenUrl\\": \\"https://authserver.example/token\\", + \\"availableScopes\\": { + \\"streetlights:on\\": \\"Ability to switch lights on\\", + \\"streetlights:off\\": \\"Ability to switch lights off\\", + \\"streetlights:dim\\": \\"Ability to dim the lights\\" + } + }, + \\"authorizationCode\\": { + \\"authorizationUrl\\": \\"https://authserver.example/auth\\", + \\"tokenUrl\\": \\"https://authserver.example/token\\", + \\"refreshUrl\\": \\"https://authserver.example/refresh\\", + \\"availableScopes\\": { + \\"streetlights:on\\": \\"Ability to switch lights on\\", + \\"streetlights:off\\": \\"Ability to switch lights off\\", + \\"streetlights:dim\\": \\"Ability to dim the lights\\" + } + } + } + }, + \\"openIdConnectWellKnown\\": { + \\"type\\": \\"openIdConnect\\", + \\"openIdConnectUrl\\": \\"https://authserver.example/.well-known\\" + } + }, + \\"parameters\\": { + \\"streetlightId\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.parameters.streetlightId\\" + }, + \\"messageTraits\\": { + \\"commonHeaders\\": \\"$ref:$.channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.messages.receiveLightMeasurement.message.traits[0]\\" + }, + \\"operationTraits\\": { + \\"kafka\\": \\"$ref:$.operations.receiveLightMeasurement.traits[0]\\" + } + }, + \\"x-parser-spec-parsed\\": true, + \\"x-parser-api-version\\": 3, + \\"x-parser-spec-stringified\\": true +}; + const config = {\\"show\\":{\\"sidebar\\":true},\\"sidebar\\":{\\"showOperations\\":\\"byDefault\\"}}; + const appRoot = document.getElementById('root'); + AsyncApiStandalone.render( + { schema, config, }, appRoot + );" +`; + exports[`Index component should render AsyncAPI v2 document 1`] = ` " diff --git a/test/components/index.test.js b/test/components/index.test.js index 4dce67d55..f183620e1 100644 --- a/test/components/index.test.js +++ b/test/components/index.test.js @@ -1,6 +1,6 @@ import { render } from '@asyncapi/generator-react-sdk'; import { Parser, fromFile } from '@asyncapi/parser'; -import { Index } from '../../components/index'; +import {App, Index} from '../../components/index'; import path from 'path'; const asyncapi_v3_path = path.resolve(__dirname, '../spec/asyncapi_v3.yml'); const asyncapi_v2_path = path.resolve(__dirname, '../spec/asyncapi_v2.yml'); @@ -23,3 +23,21 @@ describe('Index component', () => { expect(actual).toMatchSnapshot(); }); }); + +describe('App component', () => { + it('should render AsyncAPI v3 document', async () => { + const { document } = await fromFile(parser, asyncapi_v3_path).parse(); + expect(document).not.toBeUndefined(); + const result = render(); + const actual = result.trim(); + expect(actual).toMatchSnapshot(); + }); + + it('should render AsyncAPI v2 document', async () => { + const { document } = await fromFile(parser, asyncapi_v2_path).parse(); + expect(document).not.toBeUndefined(); + const result = render(); + const actual = result.trim(); + expect(actual).toMatchSnapshot(); + }); +}); \ No newline at end of file