-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,66 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { JSDOM } from 'jsdom' | ||
import { validSvgPath } from '../src/utils/inputValidation' | ||
import scrollSvg, { scrollSvgNullable } from '../src' | ||
|
||
describe('Vitest Test', () => { | ||
it('Should always pass', () => { | ||
expect(1).toBe(1) | ||
}) | ||
}) | ||
const DOM = new JSDOM( | ||
`<!DOCTYPE html> | ||
<html lang="en" width="1080" height="1920"> | ||
<head></head> | ||
<body width="1080" height="1920"> | ||
<svg id="svg" width="1080" height="1920" viewBox="0 0 9 699" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path id="svg-path" d="M 4 4 V 694.5" stroke="black" stroke-width="4" /> | ||
</svg> | ||
</body> | ||
</html>`, | ||
{ pretendToBeVisual: true } | ||
) | ||
const { document } = DOM.window | ||
|
||
const dom = new JSDOM(`<!DOCTYPE html>`) | ||
const document = dom.window.document | ||
const sampleSvgPath = document.querySelector('#svg-path') as SVGPathElement | ||
// JSDOM doesn't support getTotalLength yet | ||
sampleSvgPath.getTotalLength = () => 690 | ||
console.log(document) | ||
|
||
// Don't Use outside of testing | ||
/** Only for testing */ | ||
export function getSampleSvgPathForTesting() { | ||
const exampleSvgPath = document.createElementNS('http://www.w3.org/2000/svg', 'path') | ||
exampleSvgPath.setAttribute('d', 'M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80') | ||
exampleSvgPath.setAttribute('stroke', 'black') | ||
exampleSvgPath.setAttribute('stroke-width', '2') | ||
exampleSvgPath.setAttribute('fill', 'none') | ||
return exampleSvgPath | ||
return sampleSvgPath | ||
} | ||
|
||
describe('Setup Tests', () => { | ||
it('checks vitest', () => expect(1).toBe(1)) | ||
|
||
// SVG Validation | ||
const svgPath = getSampleSvgPathForTesting() | ||
it('checks getSampleSvgPathForTesting', () => { | ||
expect(svgPath.tagName).toBe('path') | ||
}) | ||
|
||
it('validates setupSvgPath', () => { | ||
expect(1).toBe(1) | ||
}) | ||
|
||
it('validates svg path validation', () => { | ||
expect(validSvgPath(null as unknown as SVGPathElement)).toBe(false) | ||
expect(validSvgPath(undefined as unknown as SVGPathElement)).toBe(false) | ||
|
||
svgPath.getTotalLength = () => undefined as unknown as number | ||
expect(validSvgPath(svgPath)).toBe(false) | ||
svgPath.getTotalLength = () => 690 | ||
}) | ||
it('validates svg path', () => { | ||
expect(validSvgPath(svgPath)).toBe(true) | ||
}) | ||
|
||
it('validates scrollSvg', () => { | ||
expect(scrollSvgNullable(undefined as unknown as any)).toBe(null) | ||
}) | ||
|
||
it('validates getDrawOrigin', () => { | ||
expect(1).toBe(1) | ||
}) | ||
|
||
it('validates percentToPixelOffset', () => { | ||
expect(1).toBe(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { defaultOptions } from '../src' | ||
import { validateOptions } from '../src/utils/inputValidation' | ||
|
||
describe('Options Tests', () => { | ||
it('checks default options', () => { | ||
expect(defaultOptions).toStrictEqual({ | ||
invert: false, | ||
draw_origin: 'center', | ||
offset: 0, | ||
speed: 1, | ||
undraw: false, | ||
}) | ||
}) | ||
it('validates default options', () => { | ||
expect(validateOptions(defaultOptions, {})).toBe(0) | ||
}) | ||
|
||
it('validates options checker', () => { | ||
expect(validateOptions({ ...defaultOptions, option: 'true' } as unknown as any, {})).toBe(1) | ||
// invert | ||
expect(validateOptions({ ...defaultOptions, invert: 'true' } as unknown as any, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, invert: true }, {})).toBe(0) | ||
// draw origin | ||
expect(validateOptions({ ...defaultOptions, draw_origin: 'middle' } as unknown as any, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, draw_origin: NaN }, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, draw_origin: -0.5 }, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, draw_origin: 1.5 }, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, draw_origin: 0.3 }, {})).toBe(0) | ||
expect(validateOptions({ ...defaultOptions, draw_origin: 'top' }, {})).toBe(0) | ||
// offset | ||
expect(validateOptions({ ...defaultOptions, offset: '100' } as unknown as any, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, offset: NaN }, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, offset: 100 }, {})).toBe(0) | ||
// speed | ||
expect(validateOptions({ ...defaultOptions, speed: '100' } as unknown as any, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, speed: NaN }, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, speed: -1 }, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, speed: 2 }, {})).toBe(0) | ||
// undraw | ||
expect(validateOptions({ ...defaultOptions, undraw: 'true' } as unknown as any, {})).toBe(1) | ||
expect(validateOptions({ ...defaultOptions, undraw: true }, {})).toBe(0) | ||
}) | ||
}) |