Skip to content

Commit

Permalink
fixup! charts: add weight property to operational points
Browse files Browse the repository at this point in the history
  • Loading branch information
Akctarus committed Jan 8, 2025
1 parent 49735f6 commit 72dc4ea
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions ui-speedspacechart/src/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ describe('filterVisibleElements', () => {
const getPosition = (element: Element) => element.position;
const getWeight = (element: Element) => element.weight;

it('filters visible elements based on minSpace', () => {
it('should filter visible elements based on minSpace', () => {
const options: VisibilityFilterOptions<Element> = {
elements,
getPosition,
Expand All @@ -394,7 +394,7 @@ describe('filterVisibleElements', () => {
]);
});

it('returns all elements if minSpace is 0', () => {
it('should return all elements if minSpace is 0', () => {
const options: VisibilityFilterOptions<Element> = {
elements,
getPosition,
Expand All @@ -408,7 +408,7 @@ describe('filterVisibleElements', () => {
expect(result).toEqual(elements.sort((a, b) => a.position - b.position));
});

it('returns an empty array if no elements are provided', () => {
it('should return an empty array if no elements are provided', () => {
const options: VisibilityFilterOptions<Element> = {
elements: [],
getPosition,
Expand All @@ -421,7 +421,7 @@ describe('filterVisibleElements', () => {
expect(result).toEqual([]);
});

it('prioritizes higher weights when positions overlap', () => {
it('should prioritize higher weights when positions overlap', () => {
const overlappingElements: Element[] = [
{ id: 1, position: 10, weight: 5 },
{ id: 2, position: 12, weight: 6 }, // Overlaps with id: 1
Expand All @@ -443,6 +443,49 @@ describe('filterVisibleElements', () => {
{ id: 3, position: 25, weight: 4 },
]);
});

it('should prioritize elements with higher weights when positions are identical', () => {
const elementsWithSamePosition: Element[] = [
{ id: 1, position: 10, weight: 3 },
{ id: 2, position: 10, weight: 5 },
{ id: 3, position: 10, weight: 1 },
];

const options: VisibilityFilterOptions<Element> = {
elements: elementsWithSamePosition,
getPosition,
getWeight,
minSpace: 5,
};

const result = filterVisibleElements(options);

expect(result).toEqual([
{ id: 2, position: 10, weight: 5 }, // Highest weight
]);
});

it('should handle elements with equal weights but conflicting positions', () => {
const equalWeightElements: Element[] = [
{ id: 1, position: 10, weight: 5 },
{ id: 2, position: 12, weight: 5 }, // Same weight, close position
{ id: 3, position: 30, weight: 5 },
];

const options: VisibilityFilterOptions<Element> = {
elements: equalWeightElements,
getPosition,
getWeight,
minSpace: 10,
};

const result = filterVisibleElements(options);

expect(result).toEqual([
{ id: 1, position: 10, weight: 5 },
{ id: 3, position: 30, weight: 5 },
]);
});
});

describe('getSnappedStop', () => {
Expand Down

0 comments on commit 72dc4ea

Please sign in to comment.