Skip to content

Commit b29a2bc

Browse files
fralongoFrancesco Longo
andauthored
chore: Add value in RadioGroup and Tiles analytics metadata (#3668)
Co-authored-by: Francesco Longo <[email protected]>
1 parent 0ed050e commit b29a2bc

File tree

6 files changed

+64
-13
lines changed

6 files changed

+64
-13
lines changed

src/radio-group/__tests__/analytics-metadata.test.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import React from 'react';
44
import { render } from '@testing-library/react';
55

6-
import {
7-
activateAnalyticsMetadata,
8-
GeneratedAnalyticsMetadataFragment,
9-
} from '@cloudscape-design/component-toolkit/internal/analytics-metadata';
6+
import { activateAnalyticsMetadata } from '@cloudscape-design/component-toolkit/internal/analytics-metadata';
107
import { getGeneratedAnalyticsMetadata } from '@cloudscape-design/component-toolkit/internal/analytics-metadata/utils';
118

129
import FormField from '../../../lib/components/form-field';
@@ -35,7 +32,13 @@ function renderRadioGroup(props: RadioGroupProps) {
3532
return createWrapper(renderResult.container).findRadioGroup()!;
3633
}
3734

38-
const getMetadata = (label: string, position: string, value: string, disabled?: boolean) => {
35+
const getMetadata = (
36+
label: string,
37+
position: string,
38+
value: string,
39+
disabled: boolean = false,
40+
currentValue: string | null
41+
) => {
3942
const eventMetadata = {
4043
action: 'select',
4144
detail: {
@@ -45,13 +48,16 @@ const getMetadata = (label: string, position: string, value: string, disabled?:
4548
},
4649
};
4750

48-
let metadata: GeneratedAnalyticsMetadataFragment = {
51+
let metadata = {
4952
contexts: [
5053
{
5154
type: 'component',
5255
detail: {
5356
name: 'awsui.RadioGroup',
5457
label: componentLabel,
58+
properties: {
59+
value: `${currentValue}`,
60+
},
5561
},
5662
},
5763
],
@@ -71,19 +77,25 @@ describe('Checkbox renders correct analytics metadata', () => {
7177

7278
validateComponentNameAndLabels(wrapper.findInputByValue('second')!.getElement(), labels);
7379
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('second')!.getElement())).toEqual(
74-
getMetadata('Second choice', '2', 'second', false)
80+
getMetadata('Second choice', '2', 'second', false, 'second')
7581
);
7682
validateComponentNameAndLabels(wrapper.findInputByValue('first')!.getElement(), labels);
7783
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('first')!.getElement())).toEqual(
78-
getMetadata('First choice', '2', 'first', true)
84+
getMetadata('First choice', '2', 'first', true, 'second')
85+
);
86+
});
87+
test('with null value', () => {
88+
const wrapper = renderRadioGroup({ value: null });
89+
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('second')!.getElement())).toEqual(
90+
getMetadata('Second choice', '2', 'second', false, null)
7991
);
8092
});
8193
test('readonly', () => {
8294
const wrapper = renderRadioGroup({ value: 'second', readOnly: true });
8395

8496
validateComponentNameAndLabels(wrapper.findInputByValue('second')!.getElement(), labels);
8597
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('second')!.getElement())).toEqual(
86-
getMetadata('Second choice', '2', 'second', true)
98+
getMetadata('Second choice', '2', 'second', true, 'second')
8799
);
88100
});
89101
describe('when rendered in a form field', () => {
@@ -101,6 +113,9 @@ describe('Checkbox renders correct analytics metadata', () => {
101113
detail: {
102114
name: 'awsui.RadioGroup',
103115
label: 'form field label',
116+
properties: {
117+
value: '2',
118+
},
104119
},
105120
},
106121
{
@@ -127,6 +142,9 @@ describe('Checkbox renders correct analytics metadata', () => {
127142
detail: {
128143
name: 'awsui.RadioGroup',
129144
label: 'aria label',
145+
properties: {
146+
value: '2',
147+
},
130148
},
131149
},
132150
{

src/radio-group/analytics-metadata/interfaces.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ export interface GeneratedAnalyticsMetadataRadioGroupSelect {
1515
export interface GeneratedAnalyticsMetadataRadioGroupComponent {
1616
name: 'awsui.RadioGroup';
1717
label: string | LabelIdentifier;
18+
properties: {
19+
value: string;
20+
};
1821
}

src/radio-group/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const RadioGroup = React.forwardRef((props: RadioGroupProps, ref: React.Ref<Radi
2424
component: {
2525
name: 'awsui.RadioGroup',
2626
label: { root: 'self' },
27+
properties: {
28+
value: `${props.value}`,
29+
},
2730
} as GeneratedAnalyticsMetadataRadioGroupComponent,
2831
})}
2932
/>

src/tiles/__tests__/analytics-metadata.test.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ function renderTiles(props: TilesProps) {
3737
return createWrapper(renderResult.container).findTiles()!;
3838
}
3939

40-
const getMetadata = (label: string, position: string, value: string, disabled?: boolean) => {
40+
const getMetadata = (
41+
label: string,
42+
position: string,
43+
value: string,
44+
disabled: boolean = false,
45+
currentValue: string | null
46+
) => {
4147
const eventMetadata = {
4248
action: 'select',
4349
detail: {
@@ -54,6 +60,9 @@ const getMetadata = (label: string, position: string, value: string, disabled?:
5460
detail: {
5561
name: 'awsui.Tiles',
5662
label: componentLabel,
63+
properties: {
64+
value: `${currentValue}`,
65+
},
5766
},
5867
},
5968
],
@@ -74,20 +83,26 @@ describe('Tiles renders correct analytics metadata', () => {
7483
// in the whole tile
7584
validateComponentNameAndLabels(wrapper.findItemByValue('second')!.getElement(), labels);
7685
expect(getGeneratedAnalyticsMetadata(wrapper.findItemByValue('second')!.getElement())).toEqual(
77-
getMetadata('Second choice', '2', 'second', false)
86+
getMetadata('Second choice', '2', 'second', false, 'second')
7887
);
7988
// in the radio within the tile
8089
validateComponentNameAndLabels(wrapper.findInputByValue('first')!.getElement(), labels);
8190
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('first')!.getElement())).toEqual(
82-
getMetadata('First choice', '2', 'first', true)
91+
getMetadata('First choice', '2', 'first', true, 'second')
92+
);
93+
});
94+
test('with null value', () => {
95+
const wrapper = renderTiles({ value: null });
96+
expect(getGeneratedAnalyticsMetadata(wrapper.findItemByValue('second')!.getElement())).toEqual(
97+
getMetadata('Second choice', '2', 'second', false, null)
8398
);
8499
});
85100
test('readonly', () => {
86101
const wrapper = renderTiles({ value: 'second', readOnly: true });
87102

88103
validateComponentNameAndLabels(wrapper.findInputByValue('second')!.getElement(), labels);
89104
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('second')!.getElement())).toEqual(
90-
getMetadata('Second choice', '2', 'second', true)
105+
getMetadata('Second choice', '2', 'second', true, 'second')
91106
);
92107
});
93108
describe('when rendered in a form field', () => {
@@ -105,6 +120,9 @@ describe('Tiles renders correct analytics metadata', () => {
105120
detail: {
106121
name: 'awsui.Tiles',
107122
label: 'form field label',
123+
properties: {
124+
value: '2',
125+
},
108126
},
109127
},
110128
{
@@ -131,6 +149,9 @@ describe('Tiles renders correct analytics metadata', () => {
131149
detail: {
132150
name: 'awsui.Tiles',
133151
label: 'aria label',
152+
properties: {
153+
value: '2',
154+
},
134155
},
135156
},
136157
{

src/tiles/analytics-metadata/interfaces.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ export interface GeneratedAnalyticsMetadataTilesSelect {
1515
export interface GeneratedAnalyticsMetadataTilesComponent {
1616
name: 'awsui.Tiles';
1717
label: string | LabelIdentifier;
18+
properties: {
19+
value: string;
20+
};
1821
}

src/tiles/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const Tiles = React.forwardRef((props: TilesProps, ref: React.Ref<TilesProps.Ref
2020
const componentAnalyticsMetadata: GeneratedAnalyticsMetadataTilesComponent = {
2121
name: 'awsui.Tiles',
2222
label: { root: 'self' },
23+
properties: {
24+
value: `${props.value}`,
25+
},
2326
};
2427
return (
2528
<InternalTiles

0 commit comments

Comments
 (0)