mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-04-20 03:00:24 -04:00
* INJIMOB-3792: Added tests increase code coverage Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> * INJIMOB-3792 Test-covrage fix Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> * INJIMOB-3792 Fix failing snapshot test Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> * INJIMOB-3792: Test-coverage suggestion fix Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> * INJIMOB-3792 code-coverage reviews fixes Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> * INJIMOB-3792 Refractoring test files for coverage enhancement Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> * INJIMOB-3792 Refractoring changes for code-coverage Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> * INJIMOB-3792 Refractoring changes in test files for code-coverage Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> * INJIMOB-3792 Fix snapshot test files for code-coverage Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> * INJIMOB-3792 Enhance test files for better code-coverage Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> --------- Signed-off-by: Kaushik Gupta <146950347+Kaushikgupta469@users.noreply.github.com> Signed-off-by: Swati Goel <meet2swati@gmail.com> Co-authored-by: Swati Goel <meet2swati@gmail.com>
173 lines
5.0 KiB
TypeScript
173 lines
5.0 KiB
TypeScript
import {VPShareActivityLog} from './VPShareActivityLogEvent';
|
|
import {VCItemContainerFlowType} from '../shared/Utils';
|
|
|
|
describe('VPShareActivityLog', () => {
|
|
describe('constructor', () => {
|
|
it('should create instance with default values', () => {
|
|
const log = new VPShareActivityLog({});
|
|
|
|
expect(log.type).toBe('');
|
|
expect(log.timestamp).toBeDefined();
|
|
expect(log.flow).toBe(VCItemContainerFlowType.VP_SHARE);
|
|
expect(log.info).toBe('');
|
|
});
|
|
|
|
it('should create instance with provided values', () => {
|
|
const timestamp = Date.now();
|
|
const log = new VPShareActivityLog({
|
|
type: 'SHARED_SUCCESSFULLY',
|
|
timestamp,
|
|
flow: VCItemContainerFlowType.QR_LOGIN,
|
|
info: 'Test info',
|
|
});
|
|
|
|
expect(log.type).toBe('SHARED_SUCCESSFULLY');
|
|
expect(log.timestamp).toBe(timestamp);
|
|
expect(log.flow).toBe(VCItemContainerFlowType.QR_LOGIN);
|
|
expect(log.info).toBe('Test info');
|
|
});
|
|
|
|
it('should handle different activity types', () => {
|
|
const types: Array<
|
|
| 'SHARED_SUCCESSFULLY'
|
|
| 'SHARED_WITH_FACE_VERIFIACTION'
|
|
| 'VERIFIER_AUTHENTICATION_FAILED'
|
|
| 'INVALID_AUTH_REQUEST'
|
|
| 'USER_DECLINED_CONSENT'
|
|
> = [
|
|
'SHARED_SUCCESSFULLY',
|
|
'SHARED_WITH_FACE_VERIFIACTION',
|
|
'VERIFIER_AUTHENTICATION_FAILED',
|
|
'INVALID_AUTH_REQUEST',
|
|
'USER_DECLINED_CONSENT',
|
|
];
|
|
|
|
types.forEach(type => {
|
|
const log = new VPShareActivityLog({type});
|
|
expect(log.type).toBe(type);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('getActionText', () => {
|
|
it('should return formatted action text', () => {
|
|
const log = new VPShareActivityLog({
|
|
type: 'SHARED_SUCCESSFULLY',
|
|
info: 'Test info',
|
|
});
|
|
|
|
const mockT = jest.fn(key => `Translated: ${key}`);
|
|
const result = log.getActionText(mockT);
|
|
|
|
expect(mockT).toHaveBeenCalledWith(
|
|
'ActivityLogText:vpSharing:SHARED_SUCCESSFULLY',
|
|
{info: 'Test info'},
|
|
);
|
|
expect(result).toContain('Translated:');
|
|
});
|
|
|
|
it('should handle empty type', () => {
|
|
const log = new VPShareActivityLog({type: ''});
|
|
const mockT = jest.fn(key => key);
|
|
|
|
log.getActionText(mockT);
|
|
expect(mockT).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should pass info to translation function', () => {
|
|
const log = new VPShareActivityLog({
|
|
type: 'TECHNICAL_ERROR',
|
|
info: 'Error details',
|
|
});
|
|
|
|
const mockT = jest.fn();
|
|
log.getActionText(mockT);
|
|
|
|
expect(mockT).toHaveBeenCalledWith(
|
|
expect.any(String),
|
|
expect.objectContaining({info: 'Error details'}),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('getLogFromObject', () => {
|
|
it('should create log from object', () => {
|
|
const data = {
|
|
type: 'SHARED_SUCCESSFULLY',
|
|
timestamp: 1234567890,
|
|
flow: VCItemContainerFlowType.VP_SHARE,
|
|
info: 'Test',
|
|
};
|
|
|
|
const log = VPShareActivityLog.getLogFromObject(data);
|
|
|
|
expect(log).toBeInstanceOf(VPShareActivityLog);
|
|
expect(log.type).toBe('SHARED_SUCCESSFULLY');
|
|
expect(log.timestamp).toBe(1234567890);
|
|
});
|
|
|
|
it('should handle empty object', () => {
|
|
const log = VPShareActivityLog.getLogFromObject({});
|
|
|
|
expect(log).toBeInstanceOf(VPShareActivityLog);
|
|
expect(log.type).toBe('');
|
|
});
|
|
|
|
it('should handle partial object', () => {
|
|
const log = VPShareActivityLog.getLogFromObject({
|
|
type: 'USER_DECLINED_CONSENT',
|
|
});
|
|
|
|
expect(log).toBeInstanceOf(VPShareActivityLog);
|
|
expect(log.type).toBe('USER_DECLINED_CONSENT');
|
|
});
|
|
});
|
|
|
|
describe('getActionLabel', () => {
|
|
it('should return formatted action label in English', () => {
|
|
const log = new VPShareActivityLog({
|
|
timestamp: Date.now() - 60000, // 1 minute ago
|
|
});
|
|
|
|
const label = log.getActionLabel('enUS');
|
|
|
|
expect(typeof label).toBe('string');
|
|
expect(label).toContain('ago');
|
|
});
|
|
|
|
it('should handle different languages', () => {
|
|
const log = new VPShareActivityLog({
|
|
timestamp: Date.now() - 3600000, // 1 hour ago
|
|
});
|
|
|
|
const languages = ['enUS', 'hi', 'kn', 'ta', 'ar'];
|
|
|
|
languages.forEach(lang => {
|
|
const label = log.getActionLabel(lang);
|
|
expect(typeof label).toBe('string');
|
|
expect(label.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
it('should show relative time', () => {
|
|
const recentTimestamp = Date.now() - 5000; // 5 seconds ago
|
|
const log = new VPShareActivityLog({timestamp: recentTimestamp});
|
|
|
|
const label = log.getActionLabel('enUS');
|
|
|
|
expect(label).toBeDefined();
|
|
expect(label.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should handle old timestamps', () => {
|
|
const oldTimestamp = Date.now() - 86400000; // 1 day ago
|
|
const log = new VPShareActivityLog({timestamp: oldTimestamp});
|
|
|
|
const label = log.getActionLabel('enUS');
|
|
|
|
expect(label).toBeDefined();
|
|
expect(label).toContain('ago');
|
|
});
|
|
});
|
|
});
|