Repository: directus/directus
File: app/src/displays/formatted-value/formatted-value.test.ts (TypeScript)

Code before:
				ValueNull: true,
			},
		},
	});
}

function getDisplayText(props: FormattedValueProps) {
	const wrapper = mountFormattedValue(props);
	const value = wrapper.find('.value');

	if (!value.exists()) return null;

	return value.text();
}

describe('decimal formatting', () => {
	it('preserves decimal places with format enabled', () => {
		const text = getDisplayText({ type: 'decimal', value: '123.456', format: true });
		expect(text).toContain('123');
		expect(text).toContain('456');
	});

	it('does not truncate decimals to integer', () => {
		const text = getDisplayText({ type: 'decimal', value: '99.99', format: true });
		expect(text).not.toBe('99');
		expect(text).toContain('99');
	});

	it('displays raw value without format', () => {
		const text = getDisplayText({ type: 'decimal', value: '3.14' });
		expect(text).toBe('3.14');
	});
});

describe('bigInteger formatting', () => {
	it('formats with locale separators', () => {
		const text = getDisplayText({ type: 'bigInteger', value: '1000000', format: true });
		expect(text).toBe('1,000,000');
	});

	it('handles values beyond Number.MAX_SAFE_INTEGER', () => {
		const text = getDisplayText({ type: 'bigInteger', value: '9007199254740993', format: true });
		expect(text).toBe('9,007,199,254,740,993');
	});

	it('leaves invalid bigint strings as-is', () => {
		const text = getDisplayText({ type: 'bigInteger', value: 'not-a-number', format: true });
		expect(text).toBe('not-a-number');
	});

	it('displays raw value without format', () => {

Review comment (suggestion):
shouldn't need this check if we test the specific value, as that tells us both that it contains 99 and it's not truncated to 99.

Code after:
				ValueNull: true,
			},
		},
	});
}

function getDisplayText(props: FormattedValueProps) {
	const wrapper = mountFormattedValue(props);
	const value = wrapper.find('.value');

	if (!value.exists()) return null;

	return value.text();
}

describe('decimal formatting', () => {
	it('preserves decimal places with format enabled', () => {
		const text = getDisplayText({ type: 'decimal', value: '123.456', format: true });
		expect(text).toBe('123.456');
	});

	it('displays raw value without format', () => {
		const text = getDisplayText({ type: 'decimal', value: '3.14' });
		expect(text).toBe('3.14');
	});
});

describe('bigInteger formatting', () => {
	it('formats with locale separators', () => {
		const text = getDisplayText({ type: 'bigInteger', value: '1000000', format: true });
		expect(text).toBe('1,000,000');
	});

	it('handles values beyond Number.MAX_SAFE_INTEGER', () => {
		const text = getDisplayText({ type: 'bigInteger', value: '9007199254740993', format: true });
		expect(text).toBe('9,007,199,254,740,993');
	});

	it('leaves invalid bigint strings as-is', () => {
		const text = getDisplayText({ type: 'bigInteger', value: 'not-a-number', format: true });
		expect(text).toBe('not-a-number');
	});

	it('displays raw value without format', () => {
		const text = getDisplayText({ type: 'bigInteger', value: '12345' });
		expect(text).toBe('12345');
	});
});

describe('bigInteger conditional formatting', () => {
	it('matches eq on large values', () => {