|
1 | 1 | import type { INestApplication } from '@nestjs/common'; |
2 | | -import type { IFieldVo, ISelectFieldOptions } from '@teable/core'; |
3 | | -import { FieldType, ViewType, SortFunc } from '@teable/core'; |
| 2 | +import { Optional } from '@prisma/client/runtime/library'; |
| 3 | +import type { |
| 4 | + IConvertFieldRo, |
| 5 | + IFieldVo, |
| 6 | + ISelectFieldChoice, |
| 7 | + ISelectFieldOptions, |
| 8 | + IUpdateFieldRo, |
| 9 | +} from '@teable/core'; |
| 10 | +import { FieldType, ViewType, SortFunc, Colors } from '@teable/core'; |
4 | 11 | import { |
5 | 12 | createTable, |
6 | 13 | createView, |
@@ -232,4 +239,58 @@ describe('OpenAPI FieldController (e2e)', () => { |
232 | 239 | }, |
233 | 240 | }); |
234 | 241 | }); |
| 242 | + |
| 243 | + it('should still intact for filter condition when add select option', async () => { |
| 244 | + const numberField = fields.find(({ type }) => type === FieldType.Number) as IFieldVo; |
| 245 | + const selectField = fields.find(({ type }) => type === FieldType.SingleSelect) as IFieldVo; |
| 246 | + |
| 247 | + // create all views with some view conditions |
| 248 | + const gridView = await createView(tableId, { |
| 249 | + type: ViewType.Grid, |
| 250 | + filter: { |
| 251 | + conjunction: 'and', |
| 252 | + filterSet: [ |
| 253 | + { fieldId: numberField.id, operator: 'isGreater', value: 1 }, |
| 254 | + { |
| 255 | + fieldId: selectField.id, |
| 256 | + operator: 'is', |
| 257 | + value: (selectField.options as ISelectFieldOptions)?.choices[0].name, |
| 258 | + }, |
| 259 | + ], |
| 260 | + }, |
| 261 | + }); |
| 262 | + |
| 263 | + const newChoices = [ |
| 264 | + ...(selectField.options as ISelectFieldOptions).choices, |
| 265 | + ] as Partial<ISelectFieldChoice>[]; |
| 266 | + |
| 267 | + newChoices.push({ name: 'test-add-choice', color: Colors.YellowLight2 }); |
| 268 | + |
| 269 | + // number field convert to text field |
| 270 | + await convertField(tableId, selectField.id, { |
| 271 | + name: selectField.name, |
| 272 | + dbFieldName: selectField.dbFieldName, |
| 273 | + type: FieldType.SingleSelect, |
| 274 | + options: { |
| 275 | + ...selectField.options, |
| 276 | + choices: newChoices, |
| 277 | + }, |
| 278 | + }); |
| 279 | + |
| 280 | + const views = await getViews(tableId); |
| 281 | + |
| 282 | + const gridViewAfterChange = views.find(({ id }) => id === gridView.id); |
| 283 | + |
| 284 | + expect(gridViewAfterChange?.filter).toEqual({ |
| 285 | + conjunction: 'and', |
| 286 | + filterSet: [ |
| 287 | + { fieldId: numberField.id, operator: 'isGreater', value: 1 }, |
| 288 | + { |
| 289 | + fieldId: selectField.id, |
| 290 | + operator: 'is', |
| 291 | + value: (selectField.options as ISelectFieldOptions)?.choices[0].name, |
| 292 | + }, |
| 293 | + ], |
| 294 | + }); |
| 295 | + }); |
235 | 296 | }); |
0 commit comments