|
| 1 | +import { beforeAll, describe, expect, it, vi } from 'vitest' |
| 2 | +import { |
| 3 | + getConfig, |
| 4 | + loadConfig, |
| 5 | + matchLineWhen, |
| 6 | + cleanZero, |
| 7 | + isSpacing, |
| 8 | + findNearestType, |
| 9 | +} from '../helpers' |
| 10 | + |
| 11 | +vi.mock('vscode', () => { |
| 12 | + const workspace = { |
| 13 | + getConfiguration: () => getConfig(), |
| 14 | + } |
| 15 | + |
| 16 | + return { workspace } |
| 17 | +}) |
| 18 | + |
| 19 | +beforeAll(() => { |
| 20 | + loadConfig() |
| 21 | +}) |
| 22 | + |
| 23 | +describe('matchLineWhen', () => { |
| 24 | + it('should match on px', () => { |
| 25 | + expect(matchLineWhen('12.5px')).toBeTruthy() |
| 26 | + }) |
| 27 | + |
| 28 | + it('should match on rem', () => { |
| 29 | + expect(matchLineWhen('12.5rem')).toBeTruthy() |
| 30 | + }) |
| 31 | + |
| 32 | + it('should match on var', () => { |
| 33 | + expect(matchLineWhen('var(--spacing-large)')).toBeTruthy() |
| 34 | + }) |
| 35 | + |
| 36 | + it('should not match on var only', () => { |
| 37 | + expect(matchLineWhen('var')).toBeFalsy() |
| 38 | + }) |
| 39 | + |
| 40 | + it('should not match on calc only', () => { |
| 41 | + expect(matchLineWhen('calc')).toBeFalsy() |
| 42 | + }) |
| 43 | + |
| 44 | + it('should match on calc', () => { |
| 45 | + expect( |
| 46 | + matchLineWhen("margin-bottom: ${calc('small', 'large')};") |
| 47 | + ).toBeTruthy() |
| 48 | + }) |
| 49 | + |
| 50 | + it('should not match when no number was given', () => { |
| 51 | + expect(matchLineWhen('document.body.removeListener')).toBeFalsy() |
| 52 | + }) |
| 53 | +}) |
| 54 | + |
| 55 | +describe('isSpacing', () => { |
| 56 | + it('should return true on condition', () => { |
| 57 | + expect(isSpacing('margin')).toBeTruthy() |
| 58 | + expect(isSpacing('padding')).toBeTruthy() |
| 59 | + expect(isSpacing('top')).toBeTruthy() |
| 60 | + expect(isSpacing('bottom')).toBeTruthy() |
| 61 | + expect(isSpacing('left')).toBeTruthy() |
| 62 | + expect(isSpacing('right')).toBeTruthy() |
| 63 | + expect(isSpacing('inset')).toBeTruthy() |
| 64 | + }) |
| 65 | +}) |
| 66 | + |
| 67 | +describe('cleanZero', () => { |
| 68 | + it('should remove leading zero', () => { |
| 69 | + expect(cleanZero(0.5)).toBe('.5') |
| 70 | + }) |
| 71 | +}) |
| 72 | + |
| 73 | +describe('findNearestType', () => { |
| 74 | + const list = { small: '8', basis: '16', large: '24' } |
| 75 | + |
| 76 | + it('should find large', () => { |
| 77 | + expect(findNearestType(17, list)).toBe('large') |
| 78 | + }) |
| 79 | + |
| 80 | + it('should find small', () => { |
| 81 | + expect(findNearestType(7, list)).toBe('small') |
| 82 | + }) |
| 83 | + |
| 84 | + it('should find basis', () => { |
| 85 | + expect(findNearestType(15, list)).toBe('basis') |
| 86 | + }) |
| 87 | + |
| 88 | + it('should find large', () => { |
| 89 | + expect(findNearestType(100, list)).toBe('large') |
| 90 | + }) |
| 91 | + |
| 92 | + it('should return basis if empty list was given', () => { |
| 93 | + expect(findNearestType(1, {})).toBe('basis') |
| 94 | + }) |
| 95 | +}) |
0 commit comments