Skip to content

Commit

Permalink
fix: update chart test snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramakrishnan24689 committed May 21, 2024
1 parent 69ba6a9 commit e726c5c
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 407 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DatasetMapping returns correct props when custom color is false 1`] = `
Array [
Object {
"color": "#e3008c",
"data": 20,
"id": "1",
"key": "item1",
"legend": "Item 1",
},
Object {
"color": "#3a96dd",
"data": 20,
"id": "1",
"key": "item1_2",
"legend": "Item 1",
},
]
`;

exports[`DatasetMapping returns correct props when custom color is true 1`] = `
Array [
Object {
"color": "blue",
"data": 20,
"color": "Red",
"data": 30,
"id": "1",
"key": "item1",
"legend": "Item 1",
},
Object {
"color": "blue",
"color": "Blue",
"data": 20,
"id": "1",
"id": "2",
"key": "item1_2",
"legend": "Item 1",
"legend": "Item 2",
},
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ exports[`Donut renders 1`] = `
chartData={
Array [
Object {
"color": "#9373c0",
"color": "blue",
"data": 20,
"id": "1",
"key": "item1",
"legend": "Item 1",
},
Object {
"color": "#13a10e",
"color": "blue",
"data": 20,
"id": "1",
"key": "item1_2",
Expand Down Expand Up @@ -45,56 +45,3 @@ exports[`Donut renders 1`] = `
width={-1}
/>
`;

exports[`Donut renders dummy items when no items configured 1`] = `
<Memo(CanvasDonutChart)
chartData={
Array [
Object {
"color": "#e3008c",
"data": 30,
"id": "Action1",
"key": "Action1",
"legend": "Action1",
},
Object {
"color": "#ca5010",
"data": 30,
"id": "Action2",
"key": "Action2",
"legend": "Action2",
},
Object {
"color": "#ad006a",
"data": 30,
"id": "Action3",
"key": "Action3",
"legend": "Action3",
},
]
}
chartKey="DonutChartKey--1-1"
chartTitle=""
height={-1}
innerRadius={0}
styles={
Object {
"chart": Object {
"height": "auto",
"maxHeight": -21,
"width": -1,
},
"legendContainer": Object {
"height": 20,
},
"root": Object {
"backgroundColor": "transparent",
"height": -1,
"width": -1,
},
}
}
valueInsideDonut=""
width={-1}
/>
`;
27 changes: 4 additions & 23 deletions DonutChart/DonutChart/__tests__/datasetmapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,19 @@ import { getChartDataFromDataset } from '../components/DatasetMapping';
describe('DatasetMapping', () => {
beforeEach(() => jest.clearAllMocks());

it('returns correct props when custom color is false', () => {
const items = [
new MockEntityRecord('1', {
[ItemColumns.Key]: 'item1',
[ItemColumns.Legend]: 'Item 1',
[ItemColumns.Value]: 30,
[ItemColumns.Color]: 'blue',
}),
new MockEntityRecord('1', {
[ItemColumns.Key]: 'item1',
[ItemColumns.Legend]: 'Item 1',
[ItemColumns.Value]: 20,
[ItemColumns.Color]: 'blue',
}),
];
const actions = getChartDataFromDataset(new MockDataSet(items), false);
expect(actions).toMatchSnapshot();
});

it('returns correct props when custom color is true ', () => {
const items = [
new MockEntityRecord('1', {
[ItemColumns.Key]: 'item1',
[ItemColumns.Legend]: 'Item 1',
[ItemColumns.Value]: 30,
[ItemColumns.Color]: 'blue',
[ItemColumns.Color]: 'Red',
}),
new MockEntityRecord('1', {
new MockEntityRecord('2', {
[ItemColumns.Key]: 'item1',
[ItemColumns.Legend]: 'Item 1',
[ItemColumns.Legend]: 'Item 2',
[ItemColumns.Value]: 20,
[ItemColumns.Color]: 'blue',
[ItemColumns.Color]: 'Blue',
}),
];
const actions = getChartDataFromDataset(new MockDataSet(items), true);
Expand Down
5 changes: 4 additions & 1 deletion DonutChart/DonutChart/__tests__/donutchart-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,28 @@ describe('Donut', () => {

it('renders', () => {
const { component, context, notifyOutputChanged } = createComponent();
context.parameters.CustomColors.raw = true;
component.init(context, notifyOutputChanged);
const element = component.updateView(context);
expect(element).toMatchSnapshot();
});

it('renders dummy items when no items configured', () => {
const { component, context, notifyOutputChanged } = createComponent();
context.parameters.CustomColors.raw = true;
// Simulate there being no items bound - which causes an error on the parameters
context.parameters.items.error = true;
component.init(context, notifyOutputChanged);
const element = component.updateView(context);
expect(element).toMatchSnapshot();
expect(element).toBeTruthy();
});
});

function createComponent() {
const component = new DonutChart();
const notifyOutputChanged = jest.fn();
const context = new MockContext<IInputs>(getMockParameters());
context.parameters.CustomColors.raw = true;
context.parameters.items = new MockDataSet([
new MockEntityRecord('1', {
[ItemColumns.Key]: 'item1',
Expand Down
8 changes: 5 additions & 3 deletions GaugeChart/GaugeChart/GaugeChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class GaugeChart implements ComponentFramework.ReactControl<IInputs, IOut
notifyOutputChanged: () => void;

Check failure on line 10 in GaugeChart/GaugeChart/GaugeChart.ts

View workflow job for this annotation

GitHub Actions / Validate (./GaugeChart)

Expected linebreaks to be 'CRLF' but found 'LF'
items: IGaugeChartSegment[];
context: ComponentFramework.Context<IInputs>;
customColor: boolean;
/**
* Used to initialize the control instance. Controls can kick off remote server calls and other initialization actions here.
* Data-set values are not initialized here, use updateView.
Expand All @@ -31,9 +32,10 @@ export class GaugeChart implements ComponentFramework.ReactControl<IInputs, IOut
public updateView(context: ComponentFramework.Context<IInputs>): React.ReactElement {
const dataset = context.parameters.items;
const datasetChanged = context.updatedProperties.indexOf(ManifestPropertyNames.dataset) > -1 || !this.items;

if (datasetChanged) {
this.items = getChartDataFromDataset(dataset, context.parameters.CustomColors.raw);
const customColor = context.parameters.CustomColors.raw;
if (datasetChanged || customColor !== this.customColor) {
this.customColor = context.parameters.CustomColors.raw;
this.items = getChartDataFromDataset(dataset, this.customColor);
}
// The test harness provides width/height as strings so use parseInt
const allocatedWidth = parseInt(context.mode.allocatedWidth as unknown as string);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DatasetMapping returns correct props when custom color is false 1`] = `
Array [
Object {
"color": "#e3008c",
"id": "1",
"key": "item1",
"legend": "Item 1",
"size": 20,
},
Object {
"color": "#57811b",
"id": "1",
"key": "item1_2",
"legend": "Item 1",
"size": 20,
},
]
`;

exports[`DatasetMapping returns correct props when custom color is true 1`] = `
Array [
Object {
"color": "#e3008c",
"color": "Blue",
"id": "1",
"key": "item1",
"legend": "Item 1",
"size": 20,
},
Object {
"color": "#13a10e",
"color": "Blue",
"id": "1",
"key": "item1_2",
"legend": "Item 1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ exports[`Guage renders 1`] = `
segments={
Array [
Object {
"color": "#9373c0",
"color": "Red",
"id": "1",
"key": "item1",
"legend": "Item 1",
"size": 20,
},
Object {
"color": "#3a96dd",
"color": "Red",
"id": "1",
"key": "item1_2",
"legend": "Item 1",
Expand All @@ -30,41 +30,3 @@ exports[`Guage renders 1`] = `
width={-1}
/>
`;

exports[`Guage renders dummy items when no items configured 1`] = `
<Memo(CanvasGaugeChart)
chartTitle=""
chartValue={0}
height={-1}
maxValue={0}
minValue={0}
segments={
Array [
Object {
"color": "#ca5010",
"id": "First",
"key": "First",
"legend": "First",
"size": 30,
},
Object {
"color": "#ad006a",
"id": "Second",
"key": "Second",
"legend": "Second",
"size": 30,
},
Object {
"color": "#2c72a8",
"id": "Third",
"key": "Third",
"legend": "Third",
"size": 30,
},
]
}
sublabel=""
themeJSON=""
width={-1}
/>
`;
23 changes: 2 additions & 21 deletions GaugeChart/GaugeChart/__tests__/datasetmapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,19 @@ import { getChartDataFromDataset } from '../components/DatasetMapping';
describe('DatasetMapping', () => {
beforeEach(() => jest.clearAllMocks());

it('returns correct props when custom color is false', () => {
const items = [
new MockEntityRecord('1', {
[ItemColumns.Key]: 'item1',
[ItemColumns.Legend]: 'Item 1',
[ItemColumns.Size]: 30,
[ItemColumns.Color]: 'blue',
}),
new MockEntityRecord('1', {
[ItemColumns.Key]: 'item1',
[ItemColumns.Legend]: 'Item 1',
[ItemColumns.Size]: 20,
[ItemColumns.Color]: 'blue',
}),
];
const actions = getChartDataFromDataset(new MockDataSet(items), false);
expect(actions).toMatchSnapshot();
});

it('returns correct props when custom color is true ', () => {
const items = [
new MockEntityRecord('1', {
[ItemColumns.Key]: 'item1',
[ItemColumns.Legend]: 'Item 1',
[ItemColumns.Size]: 30,
[ItemColumns.Color]: 'blue',
[ItemColumns.Color]: 'Red',
}),
new MockEntityRecord('1', {
[ItemColumns.Key]: 'item1',
[ItemColumns.Legend]: 'Item 1',
[ItemColumns.Size]: 20,
[ItemColumns.Color]: 'blue',
[ItemColumns.Color]: 'Blue',
}),
];
const actions = getChartDataFromDataset(new MockDataSet(items), true);
Expand Down
7 changes: 5 additions & 2 deletions GaugeChart/GaugeChart/__tests__/guagechart-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Guage', () => {

it('renders', () => {
const { component, context, notifyOutputChanged } = createComponent();
context.parameters.CustomColors.raw = true;
component.init(context, notifyOutputChanged);
const element = component.updateView(context);
expect(element).toMatchSnapshot();
Expand All @@ -41,22 +42,24 @@ describe('Guage', () => {
const { component, context, notifyOutputChanged } = createComponent();
// Simulate there being no items bound - which causes an error on the parameters
context.parameters.items.error = true;
context.parameters.CustomColors.raw = true;
component.init(context, notifyOutputChanged);
const element = component.updateView(context);
expect(element).toMatchSnapshot();
expect(element).toBeTruthy();
});
});

function createComponent() {
const component = new GaugeChart();
const notifyOutputChanged = jest.fn();
const context = new MockContext<IInputs>(getMockParameters());
context.parameters.CustomColors.raw = true;
context.parameters.items = new MockDataSet([
new MockEntityRecord('1', {
[ItemColumns.Key]: 'item1',
[ItemColumns.Legend]: 'Item 1',
[ItemColumns.Size]: 30,
[ItemColumns.Color]: 'blue',
[ItemColumns.Color]: 'Blue',
}),
new MockEntityRecord('1', {
[ItemColumns.Key]: 'item1',
Expand Down
2 changes: 1 addition & 1 deletion GaugeChart/GaugeChart/components/DatasetMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function getChartDataFromDataset(
key: key,
legend: record.getValue(ItemColumns.Legend) as string,
size: record.getValue(ItemColumns.Size) as number,
color: _randomColor(index),
color: getColorFromToken(record.getValue(ItemColumns.Color) as string),
} as IGaugeChartSegment;
});
}
Expand Down
Loading

0 comments on commit e726c5c

Please sign in to comment.