Copilot commented on code in PR #5843: URL: https://github.com/apache/texera/pull/5843#discussion_r3447914154
########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/gaugeChart/GaugeChartOpDescSpec.scala: ########## @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.amber.operator.visualization.gaugeChart + +import org.apache.texera.amber.core.tuple.{AttributeType, Schema} +import org.apache.texera.amber.operator.LogicalOp +import org.apache.texera.amber.operator.metadata.OperatorGroupConstants +import org.apache.texera.amber.util.JSONUtils.objectMapper +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +class GaugeChartOpDescSpec extends AnyFlatSpec with Matchers { + + "GaugeChartOpDesc.operatorInfo" should + "advertise the name and Financial visualization group" in { + val info = (new GaugeChartOpDesc).operatorInfo + info.userFriendlyName shouldBe "Gauge Chart" + info.operatorGroupName shouldBe OperatorGroupConstants.VISUALIZATION_FINANCIAL_GROUP + info.inputPorts should have length 1 + info.outputPorts should have length 1 + } + + "GaugeChartOpDesc" should "default value/delta/threshold to empty and steps to an empty list" in { + val d = new GaugeChartOpDesc + d.value shouldBe "" + d.delta shouldBe "" + d.threshold shouldBe "" + d.steps shouldBe empty + } + + "GaugeChartOpDesc.getOutputSchemas" should + "produce a single html-content STRING column keyed by the declared output port" in { + val op = new GaugeChartOpDesc + op.getOutputSchemas(Map.empty) shouldBe Map( + op.operatorInfo.outputPorts.head.id -> Schema().add("html-content", AttributeType.STRING) + ) + } + + "GaugeChartOpDesc.generatePythonCode" should "emit a Plotly Indicator figure" in { + val d = new GaugeChartOpDesc + d.value = "score" + val code = d.generatePythonCode() + code should include("class ProcessTableOperator(UDFTableOperator)") + code should include("plotly.graph_objects") + code should include("go.Indicator(") + } + + "GaugeChartOpDesc" should "round-trip value/delta/threshold through the polymorphic base" in { + val d = new GaugeChartOpDesc + d.value = "v" + d.delta = "dl" + d.threshold = "th" + val restored = objectMapper.readValue(objectMapper.writeValueAsString(d), classOf[LogicalOp]) + restored shouldBe a[GaugeChartOpDesc] + val g = restored.asInstanceOf[GaugeChartOpDesc] + g.value shouldBe "v" + g.delta shouldBe "dl" + g.threshold shouldBe "th" + } Review Comment: The round-trip test only asserts value/delta/threshold. Since `GaugeChartOpDesc` also has a `steps: List[GaugeChartSteps]` config field (and this PR aims to pin descriptor behavior), this leaves serialization/deserialization of `steps` untested. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/rangeSlider/RangeSliderOpDescSpec.scala: ########## @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.amber.operator.visualization.rangeSlider + +import org.apache.texera.amber.core.tuple.{AttributeType, Schema} +import org.apache.texera.amber.operator.LogicalOp +import org.apache.texera.amber.operator.metadata.OperatorGroupConstants +import org.apache.texera.amber.util.JSONUtils.objectMapper +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +class RangeSliderOpDescSpec extends AnyFlatSpec with Matchers { + + "RangeSliderOpDesc.operatorInfo" should + "advertise the name and Basic visualization group" in { + val info = (new RangeSliderOpDesc).operatorInfo + info.userFriendlyName shouldBe "Range Slider" + info.operatorDescription shouldBe "Visualize data in a Range Slider" + info.operatorGroupName shouldBe OperatorGroupConstants.VISUALIZATION_BASIC_GROUP + info.inputPorts should have length 1 + info.outputPorts should have length 1 + } + + "RangeSliderOpDesc" should "default xAxis and yAxis to the empty string" in { + val d = new RangeSliderOpDesc + d.xAxis shouldBe "" + d.yAxis shouldBe "" + } + + "RangeSliderOpDesc.getOutputSchemas" should + "produce a single html-content STRING column keyed by the declared output port" in { + val op = new RangeSliderOpDesc + op.getOutputSchemas(Map.empty) shouldBe Map( + op.operatorInfo.outputPorts.head.id -> Schema().add("html-content", AttributeType.STRING) + ) + } + + "RangeSliderOpDesc.generatePythonCode" should "emit a Plotly Scatter figure" in { + val d = new RangeSliderOpDesc + d.xAxis = "x" + d.yAxis = "y" + val code = d.generatePythonCode() + code should include("class ProcessTableOperator(UDFTableOperator)") + code should include("go.Scatter(") + } + + "RangeSliderOpDesc" should "round-trip xAxis and yAxis through the polymorphic base" in { + val d = new RangeSliderOpDesc + d.xAxis = "month" + d.yAxis = "sales" + val restored = objectMapper.readValue(objectMapper.writeValueAsString(d), classOf[LogicalOp]) + restored shouldBe a[RangeSliderOpDesc] + val r = restored.asInstanceOf[RangeSliderOpDesc] + r.xAxis shouldBe "month" + r.yAxis shouldBe "sales" + } Review Comment: The round-trip test only asserts `xAxis` and `yAxis`, but `RangeSliderOpDesc` also persists `duplicateType` (defaults to NOTHING). Without asserting it survives the polymorphic JSON round-trip, regressions in that field's serialization would go unnoticed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
