(
input: MatSliderThumb,
{
min,
max,
value,
translateX,
width,
step,
}: {min: number; max: number; value: number; translateX: number; width?: number; step?: number},
)
| 46 | } |
| 47 | |
| 48 | function checkInput( |
| 49 | input: MatSliderThumb, |
| 50 | { |
| 51 | min, |
| 52 | max, |
| 53 | value, |
| 54 | translateX, |
| 55 | width, |
| 56 | step, |
| 57 | }: {min: number; max: number; value: number; translateX: number; width?: number; step?: number}, |
| 58 | ): void { |
| 59 | expect(input.min).withContext('min').toBe(min); |
| 60 | expect(input.max).withContext('max').toBe(max); |
| 61 | expect(input.value).withContext('value').toBe(value); |
| 62 | |
| 63 | // The discrepancy between the "ideal" and "actual" translateX comes from |
| 64 | // the 3px offset from the start & end of the slider track to the first |
| 65 | // and last tick marks. |
| 66 | // |
| 67 | // The "actual" translateX is calculated based on a slider that is 6px |
| 68 | // smaller than the width of the slider. Using this "actual" translateX in |
| 69 | // tests would make it even more difficult than it already is to tell if |
| 70 | // the translateX is off, so we abstract things in here so tests can be |
| 71 | // more intuitive. |
| 72 | // |
| 73 | // The most clear way to compare the two tx's is to just turn them into |
| 74 | // percentages by dividing by their (total height) / 100. |
| 75 | const idealTXPercentage = Math.round(translateX / 3); |
| 76 | const actualTXPercentage = Math.round((input.translateX - 3) / 2.94); |
| 77 | expect(actualTXPercentage) |
| 78 | .withContext(`translateX: ${input.translateX} should be close to ${translateX}`) |
| 79 | .toBe(idealTXPercentage); |
| 80 | if (step !== undefined) { |
| 81 | expect(input.step).withContext('step').toBe(step); |
| 82 | } |
| 83 | if (width !== undefined) { |
| 84 | const realWidth = parseInt( |
| 85 | (input as MatSliderRangeThumb)._hostElement.style.width.match(/\d+/)![0], |
| 86 | 10, |
| 87 | ); |
| 88 | expect(realWidth) |
| 89 | .withContext('width') |
| 90 | .toBeCloseTo((300 * width) / 100 + 16, 0); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // Note that this test is outside of the other `describe` blocks, because they all run |
| 95 | // `detectChanges` in the `beforeEach` and we're testing specifically what happens if it |
no outgoing calls
no test coverage detected
searching dependent graphs…