|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { propertiesLoader } from './properties'; // Adjust the import path as needed |
| 3 | + |
| 4 | +describe('propertiesLoader', () => { |
| 5 | + const loader = propertiesLoader(); |
| 6 | + |
| 7 | + const sampleProperties = ` |
| 8 | +# General messages |
| 9 | +welcome.message=Welcome to our application! |
| 10 | +error.message=An error has occurred. Please try again later. |
| 11 | +
|
| 12 | +# User-related messages |
| 13 | +user.login=Please enter your username and password. |
| 14 | +user.username=Username |
| 15 | +user.password=Password |
| 16 | + `.trim(); |
| 17 | + |
| 18 | + it('should load properties correctly', async () => { |
| 19 | + const result = await loader.load(sampleProperties); |
| 20 | + expect(result).toEqual({ |
| 21 | + 'welcome.message': 'Welcome to our application!', |
| 22 | + 'error.message': 'An error has occurred. Please try again later.', |
| 23 | + 'user.login': 'Please enter your username and password.', |
| 24 | + 'user.username': 'Username', |
| 25 | + 'user.password': 'Password' |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should save properties correctly', async () => { |
| 30 | + const input = { |
| 31 | + 'app.name': 'My App', |
| 32 | + 'app.version': '1.0.0', |
| 33 | + 'user.greeting': 'Hello, {0}!' |
| 34 | + }; |
| 35 | + |
| 36 | + const result = await loader.save(input); |
| 37 | + expect(result).toContain('app.name=My App'); |
| 38 | + expect(result).toContain('app.version=1.0.0'); |
| 39 | + expect(result).toContain('user.greeting=Hello, {0}!'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should handle empty input when loading', async () => { |
| 43 | + const result = await loader.load(''); |
| 44 | + expect(result).toEqual({}); |
| 45 | + }); |
| 46 | +}); |
0 commit comments