unchartedelixir / uncharted

33 stars 8 forks source link

Create helper render_chart/1 test helper #37

Closed zkayser closed 3 years ago

zkayser commented 3 years ago

This MR introduces an UnchartedPhoenix.TestRenderer module that is meant to be imported into test files for UnchartedPhoenix in place of using LiveViewTests's live_component/3 macro.

The UnchartedPhoenix.TestRenderer module exposes a render_chart/1 function that can take in any Uncharted chart type and render it using the appropriate UnchartedPhoenix live component. This is predicated on the Uncharted.Component protocol being implemented for the chart type you are trying to render.

The render_chart/1 function will pipe everything through a call to UnchartedPhoenix.render/2, ensuring that component ids are added to the component, thus preventing us from having to manually pass an id: #{some_value} option to every call to live_component/3 we would otherwise need to test our LiveView components.