mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-12-08 01:34:32 +00:00
* Refactor Home component * Refactor Welcome * Refactor small components * Refactor Nav component * refactor Settings * Refactor Chat * Refactor New message notifications * Fix tests * Remove tooltip * Remove react-simple-dropdown * Change to last redux * Switch to redux hooks * Add github action
34 lines
928 B
JavaScript
34 lines
928 B
JavaScript
import { describe, it, expect, vi } from 'vitest';
|
|
|
|
import reducer, { createUser, changeUsername} from './user';
|
|
|
|
vi.mock('@/i18n', () => {
|
|
return {
|
|
getTranslations: vi.fn().mockReturnValue({ path: 'test' }),
|
|
};
|
|
});
|
|
|
|
describe('User reducer', () => {
|
|
it('should return the initial state', () => {
|
|
expect(reducer(undefined, {})).toEqual({ id: '', privateKey: {}, publicKey: {}, username: '' });
|
|
});
|
|
|
|
it('should handle CREATE_USER', () => {
|
|
const payload = { publicKey: { n: 'alicekey' }, username: 'alice' };
|
|
|
|
expect(reducer({},createUser(payload) )).toEqual({
|
|
id: 'alicekey',
|
|
publicKey: { n: 'alicekey' },
|
|
username: 'alice',
|
|
});
|
|
});
|
|
|
|
it('should handle SEND_ENCRYPTED_MESSAGE_CHANGE_USERNAME', () => {
|
|
const payload = { newUsername: 'alice' };
|
|
|
|
expect(reducer({ username: 'polux' }, changeUsername(payload))).toEqual({
|
|
username: 'alice',
|
|
});
|
|
});
|
|
});
|