Skip to content

Commit 4b6ac0e

Browse files
committed
test(entities-shared): fix config card json text
1 parent 7fd8967 commit 4b6ac0e

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

packages/entities/entities-shared/fixtures/mockData.ts

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export const gatewayServiceRecord = {
119119
tls_verify: true,
120120
updated_at: 1686157266,
121121
write_timeout: 60000,
122+
extra: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
122123
}
123124

124125
export const emptyKey = 'preferred_chain'

packages/entities/entities-shared/src/components/entity-base-config-card/ConfigCardItem.vue

+4-9
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ const emit = defineEmits<{
162162
(e: 'navigation-click', record: RecordItem): void,
163163
}>()
164164
165-
const id = useId()
165+
const uniqueId = useId()
166166
167167
const slots = useSlots()
168168
const { i18n: { t, formatUnixTimeStamp } } = composables.useI18n()
@@ -307,26 +307,21 @@ const componentAttrsData = computed((): ComponentAttrsData => {
307307
},
308308
}
309309
310-
case ConfigurationSchemaType.Text: {
311-
// If the schema type is `plain-text` but the value is an object, we want to display it as a JSON code block.
312-
// Otherwise, we'll just fallthrough to the default case and display it as plain text.
310+
default:
311+
// Before fallback to plain text, check if the value is an object, if so, render it as a code block
313312
if (props.item.value != null && typeof props.item.value === 'object') {
314313
return {
315314
tag: 'KCodeBlock',
316315
attrs: {
317316
'data-testid': `${props.item.key}-json-code`,
318-
id: `json-code-${id}`,
317+
id: `json-code-${uniqueId}`,
319318
language: 'json',
320319
code: JSON.stringify(props.item.value, null, ' '),
321320
theme: 'dark',
322321
maxHeight: '480px',
323322
},
324323
}
325324
}
326-
}
327-
328-
// eslint-disable-next-line no-fallthrough
329-
default:
330325
return {
331326
tag: 'div',
332327
attrs: {

packages/entities/entities-shared/src/components/entity-base-config-card/EntityBaseConfigCard.cy.ts

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const customizedKey = 'ca_certificates'
2929
const customTooltip = 'Custom tooltip'
3030
const customLabel = 'CA Certificates'
3131
const unconfiguredKey = 'client_certificate'
32+
const untypedKey = 'extra'
3233
const configSchema: ConfigurationSchema = {
3334
protocol: {
3435
section: ConfigurationSchemaSection.Basic,
@@ -68,6 +69,9 @@ const configSchema: ConfigurationSchema = {
6869
order: 6,
6970
section: ConfigurationSchemaSection.Advanced,
7071
},
72+
[untypedKey]: {
73+
order: 5,
74+
},
7175
[unconfiguredKey]: {
7276
// leave this object empty for tests!!
7377
},
@@ -222,6 +226,15 @@ describe('<EntityBaseConfigCard />', () => {
222226
cy.getTestId(`${unconfiguredKey}-label-tooltip`).should('not.exist')
223227
// type defaults to plain text
224228
cy.getTestId(`${unconfiguredKey}-json-code`).should('be.visible')
229+
230+
// section defaults to Advanced (and hidden defaults to false)
231+
cy.get(`[data-testid="config-card-details-advanced-props"] [data-testid="${untypedKey}-label"]`).should('exist')
232+
// title cases key for the label
233+
cy.getTestId(`${untypedKey}-label`).should('contain.text', convertKeyToTitle(untypedKey))
234+
// no tooltip
235+
cy.getTestId(`${untypedKey}-label-tooltip`).should('not.exist')
236+
// type defaults to plain text
237+
cy.getTestId(`${untypedKey}-plain-text`).should('be.visible')
225238
})
226239

227240
it('allows customizing label and label tooltip', () => {

0 commit comments

Comments
 (0)