Files
interview-demo-code/frontend/spa/tests/unit/helpers.test.js
Nikita Kiselev 3cc82e45f0
Some checks are pending
Telegram Mini App Shop Builder / Compute version metadata (push) Waiting to run
Telegram Mini App Shop Builder / Run Frontend tests (push) Waiting to run
Telegram Mini App Shop Builder / Run Backend tests (push) Waiting to run
Telegram Mini App Shop Builder / Run PHP_CodeSniffer (push) Waiting to run
Telegram Mini App Shop Builder / Build module. (push) Blocked by required conditions
Telegram Mini App Shop Builder / release (push) Blocked by required conditions
Squashed commit message
2026-03-11 23:02:54 +03:00

94 lines
3.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect } from 'vitest';
import { isNotEmpty, formatPrice } from '@/helpers.js';
describe('helpers.js', () => {
describe('isNotEmpty', () => {
it('должен возвращать false для null', () => {
expect(isNotEmpty(null)).toBe(false);
});
it('должен возвращать false для undefined', () => {
expect(isNotEmpty(undefined)).toBe(false);
});
it('должен возвращать false для пустой строки', () => {
expect(isNotEmpty('')).toBe(false);
expect(isNotEmpty(' ')).toBe(false);
});
it('должен возвращать true для непустой строки', () => {
expect(isNotEmpty('test')).toBe(true);
expect(isNotEmpty(' test ')).toBe(true);
});
it('должен возвращать false для пустого массива', () => {
expect(isNotEmpty([])).toBe(false);
});
it('должен возвращать true для непустого массива', () => {
expect(isNotEmpty([1, 2, 3])).toBe(true);
});
it('должен возвращать false для пустого объекта', () => {
expect(isNotEmpty({})).toBe(false);
});
it('должен возвращать true для непустого объекта', () => {
expect(isNotEmpty({ key: 'value' })).toBe(true);
});
it('должен возвращать true для чисел', () => {
expect(isNotEmpty(0)).toBe(true);
expect(isNotEmpty(42)).toBe(true);
expect(isNotEmpty(-10)).toBe(true);
});
it('должен возвращать true для булевых значений', () => {
expect(isNotEmpty(true)).toBe(true);
expect(isNotEmpty(false)).toBe(true);
});
});
describe('formatPrice', () => {
it('должен возвращать пустую строку для null', () => {
expect(formatPrice(null)).toBe('');
});
it('должен возвращать пустую строку для undefined', () => {
expect(formatPrice(undefined)).toBe('');
});
it('должен форматировать положительные числа', () => {
expect(formatPrice(1000)).toBe('1 000');
expect(formatPrice(1234567)).toBe('1 234 567');
expect(formatPrice(42)).toBe('42');
});
it('должен форматировать отрицательные числа', () => {
expect(formatPrice(-1000)).toBe('-1 000');
expect(formatPrice(-42)).toBe('-42');
});
it('должен обрабатывать строки с числами', () => {
expect(formatPrice('1000')).toBe('1 000');
expect(formatPrice(' 1234 ')).toBe('1 234');
});
it('должен возвращать пустую строку для нуля', () => {
expect(formatPrice(0)).toBe('');
expect(formatPrice('0')).toBe('');
});
it('должен обрабатывать десятичные числа (округляет)', () => {
expect(formatPrice(1234.56)).toBe('1 235');
expect(formatPrice(999.99)).toBe('1 000');
});
it('должен возвращать пустую строку для невалидных значений', () => {
expect(formatPrice('abc')).toBe('');
expect(formatPrice('')).toBe('');
});
});
});