|
1 | 1 | import React from "react"
|
2 |
| -import { fromJS } from "immutable" |
| 2 | +import { List, fromJS } from "immutable" |
3 | 3 | import { render } from "enzyme"
|
4 | 4 | import ParameterRow from "components/parameter-row"
|
5 | 5 |
|
@@ -84,3 +84,142 @@ describe("<ParameterRow/>", () => {
|
84 | 84 | expect(wrapper.find(".parameter__type").text()).toEqual("string")
|
85 | 85 | })
|
86 | 86 | })
|
| 87 | + |
| 88 | +describe("bug #5573: zero default and example values", function () { |
| 89 | + it("should apply a Swagger 2.0 default value of zero", function () { |
| 90 | + const paramValue = fromJS({ |
| 91 | + description: "a pet", |
| 92 | + type: "integer", |
| 93 | + default: 0 |
| 94 | + }) |
| 95 | + |
| 96 | + let props = { |
| 97 | + getComponent: () => "div", |
| 98 | + specSelectors: { |
| 99 | + security() { }, |
| 100 | + parameterWithMetaByIdentity() { return paramValue }, |
| 101 | + isOAS3() { return false }, |
| 102 | + isSwagger2() { return true } |
| 103 | + }, |
| 104 | + fn: {}, |
| 105 | + operation: { get: () => { } }, |
| 106 | + onChange: jest.fn(), |
| 107 | + param: paramValue, |
| 108 | + rawParam: paramValue, |
| 109 | + onChangeConsumes: () => { }, |
| 110 | + pathMethod: [], |
| 111 | + getConfigs: () => { return {} }, |
| 112 | + specPath: List([]) |
| 113 | + } |
| 114 | + |
| 115 | + render(<ParameterRow {...props} />) |
| 116 | + |
| 117 | + expect(props.onChange).toHaveBeenCalled() |
| 118 | + expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false) |
| 119 | + }) |
| 120 | + it("should apply a Swagger 2.0 example value of zero", function () { |
| 121 | + const paramValue = fromJS({ |
| 122 | + description: "a pet", |
| 123 | + type: "integer", |
| 124 | + schema: { |
| 125 | + example: 0 |
| 126 | + } |
| 127 | + }) |
| 128 | + |
| 129 | + let props = { |
| 130 | + getComponent: () => "div", |
| 131 | + specSelectors: { |
| 132 | + security() { }, |
| 133 | + parameterWithMetaByIdentity() { return paramValue }, |
| 134 | + isOAS3() { return false }, |
| 135 | + isSwagger2() { return true } |
| 136 | + }, |
| 137 | + fn: {}, |
| 138 | + operation: { get: () => { } }, |
| 139 | + onChange: jest.fn(), |
| 140 | + param: paramValue, |
| 141 | + rawParam: paramValue, |
| 142 | + onChangeConsumes: () => { }, |
| 143 | + pathMethod: [], |
| 144 | + getConfigs: () => { return {} }, |
| 145 | + specPath: List([]) |
| 146 | + } |
| 147 | + |
| 148 | + render(<ParameterRow {...props} />) |
| 149 | + |
| 150 | + expect(props.onChange).toHaveBeenCalled() |
| 151 | + expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false) |
| 152 | + }) |
| 153 | + it("should apply an OpenAPI 3.0 default value of zero", function () { |
| 154 | + const paramValue = fromJS({ |
| 155 | + description: "a pet", |
| 156 | + schema: { |
| 157 | + type: "integer", |
| 158 | + default: 0 |
| 159 | + } |
| 160 | + }) |
| 161 | + |
| 162 | + let props = { |
| 163 | + getComponent: () => "div", |
| 164 | + specSelectors: { |
| 165 | + security() { }, |
| 166 | + parameterWithMetaByIdentity() { return paramValue }, |
| 167 | + isOAS3() { return true }, |
| 168 | + isSwagger2() { return false } |
| 169 | + }, |
| 170 | + oas3Selectors: { |
| 171 | + activeExamplesMember: () => null |
| 172 | + }, |
| 173 | + fn: {}, |
| 174 | + operation: { get: () => { } }, |
| 175 | + onChange: jest.fn(), |
| 176 | + param: paramValue, |
| 177 | + rawParam: paramValue, |
| 178 | + onChangeConsumes: () => { }, |
| 179 | + pathMethod: [], |
| 180 | + getConfigs: () => { return {} }, |
| 181 | + specPath: List([]) |
| 182 | + } |
| 183 | + |
| 184 | + render(<ParameterRow {...props} />) |
| 185 | + |
| 186 | + expect(props.onChange).toHaveBeenCalled() |
| 187 | + expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false) |
| 188 | + }) |
| 189 | + it("should apply an OpenAPI 3.0 example value of zero", function () { |
| 190 | + const paramValue = fromJS({ |
| 191 | + description: "a pet", |
| 192 | + schema: { |
| 193 | + type: "integer", |
| 194 | + example: 0 |
| 195 | + } |
| 196 | + }) |
| 197 | + |
| 198 | + let props = { |
| 199 | + getComponent: () => "div", |
| 200 | + specSelectors: { |
| 201 | + security() { }, |
| 202 | + parameterWithMetaByIdentity() { return paramValue }, |
| 203 | + isOAS3() { return true }, |
| 204 | + isSwagger2() { return false } |
| 205 | + }, |
| 206 | + oas3Selectors: { |
| 207 | + activeExamplesMember: () => null |
| 208 | + }, |
| 209 | + fn: {}, |
| 210 | + operation: { get: () => { } }, |
| 211 | + onChange: jest.fn(), |
| 212 | + param: paramValue, |
| 213 | + rawParam: paramValue, |
| 214 | + onChangeConsumes: () => { }, |
| 215 | + pathMethod: [], |
| 216 | + getConfigs: () => { return {} }, |
| 217 | + specPath: List([]) |
| 218 | + } |
| 219 | + |
| 220 | + render(<ParameterRow {...props} />) |
| 221 | + |
| 222 | + expect(props.onChange).toHaveBeenCalled() |
| 223 | + expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false) |
| 224 | + }) |
| 225 | +}) |
0 commit comments