@vtmn/svelte
Advanced tools
Comparing version 0.66.1 to 0.66.2
{ | ||
"name": "@vtmn/svelte", | ||
"version": "0.66.1", | ||
"version": "0.66.2", | ||
"description": "Decathlon Design System - Vitamin Svelte components library", | ||
@@ -132,3 +132,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "dab2969677917ccdd754b2c679398cfad5298d25" | ||
"gitHead": "5afb72a8f87cf14d18dcf98d4038fcfc56349613" | ||
} |
import '@testing-library/jest-dom'; | ||
import { fireEvent, render } from '@testing-library/svelte'; | ||
import VtmnRating from '../VtmnRating.svelte'; | ||
import { computeRatingFill } from '../vtmnRating.util'; | ||
@@ -209,3 +210,3 @@ describe('VtmnRating', () => { | ||
expect(spans[1]).toHaveClass('vtmx-star-fill'); | ||
expect(spans[2]).toHaveClass('vtmx-star-half-fill'); | ||
expect(spans[2]).toHaveClass('vtmx-star-line'); | ||
expect(spans[3]).toHaveClass('vtmx-star-line'); | ||
@@ -228,6 +229,20 @@ expect(spans[4]).toHaveClass('vtmx-star-line'); | ||
expect(spans[1]).toHaveClass('vtmx-star-fill'); | ||
expect(spans[2]).toHaveClass('vtmx-star-half-fill'); | ||
expect(spans[2]).toHaveClass('vtmx-star-fill'); | ||
expect(spans[3]).toHaveClass('vtmx-star-line'); | ||
expect(spans[4]).toHaveClass('vtmx-star-line'); | ||
}); | ||
test("Should have 5 span with class 'vtmx-star-fill' if rating > 4.75 and compact = false", () => { | ||
const { container } = render(VtmnRating, { | ||
name: 'rating', | ||
readonly: true, | ||
compact: false, | ||
value: 4.75, | ||
}); | ||
const spans = getReadonlyPresentations(container); | ||
expect(spans.length).toEqual(5); | ||
for (let i = 0, ii = spans.length; i < ii; i++) { | ||
expect(spans[i]).toBeVisible(); | ||
expect(spans[i]).toHaveClass('vtmx-star-fill'); | ||
} | ||
}); | ||
test("Should have 5 span with class 'vtmx-star-fill' if rating = 5 and compact = false", () => { | ||
@@ -345,2 +360,20 @@ const { container } = render(VtmnRating, { | ||
}); | ||
describe('computeRatingFill', () => { | ||
test('Should return line if isCompact and rattingValue is 0', () => { | ||
expect(computeRatingFill(true, 1, 0)).toBe('line'); | ||
}); | ||
test('Should return fill if isCompact and rattingValue is > 0', () => { | ||
expect(computeRatingFill(true, 1, 0.1)).toBe('fill'); | ||
}); | ||
test('Should return fill if current position < ratingValue', () => { | ||
expect(computeRatingFill(false, 1, 2)).toBe('fill'); | ||
}); | ||
test('Should return half-fill if current position is floating value and ratingValue < position', () => { | ||
expect(computeRatingFill(false, 1, 0.5)).toBe('half-fill'); | ||
}); | ||
test('Should return line if current value < position', () => { | ||
expect(computeRatingFill(false, 4, 1)).toBe('line'); | ||
}); | ||
}); | ||
}); |
@@ -16,1 +16,5 @@ export function isFloat(n) { | ||
} | ||
export function roundToNearestHalf(number) { | ||
return Math.round(number * 2) / 2; | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1511390
155
31686