mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-09 05:27:57 -05:00
* INJIMOB-3246 Code coverage for Inji-Wallet repo increase above 5% Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com> * INJIMOB-3246: added snapshot tests and coverage increased to +4% Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com> * removed duplicated lines Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com> * Added updateCredentialInformation tests Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com> * added code rabbit changes Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com> * removed platform-specific tests without mocking Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com> * standardize mocks in VcItemContainerProfileImage tests Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com> --------- Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com>
161 lines
4.4 KiB
TypeScript
161 lines
4.4 KiB
TypeScript
import {VCActivityLog} from './ActivityLogEvent';
|
|
|
|
describe('ActivityLog', () => {
|
|
let instance: {timestamp: any};
|
|
|
|
beforeEach(() => {
|
|
instance = new VCActivityLog();
|
|
jest.mock('jsonld', () => ({
|
|
compact: jest.fn(),
|
|
expand: jest.fn(),
|
|
}));
|
|
});
|
|
|
|
it('Activity log instance should have a timestamp set', () => {
|
|
expect(instance.timestamp).not.toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('getActionText', () => {
|
|
let activityLog;
|
|
let mockIl18nfn;
|
|
const wellknown = {
|
|
credential_configurations_supported: {
|
|
mockId: {
|
|
display: [
|
|
{
|
|
name: 'fake VC',
|
|
locale: 'en',
|
|
logo: {
|
|
url: 'https://mosip.github.io/inji-config/logos/mosipid-logo.png',
|
|
alt_text: 'a square logo of a MOSIP',
|
|
},
|
|
background_color: '#1A0983',
|
|
background_image: {
|
|
uri: 'https://mosip.github.io/inji-config/logos/mosipid-logo.png',
|
|
},
|
|
text_color: '#000000',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
};
|
|
beforeEach(() => {
|
|
mockIl18nfn = jest.fn();
|
|
jest.mock('jsonld', () => ({
|
|
compact: jest.fn(),
|
|
expand: jest.fn(),
|
|
}));
|
|
activityLog = new VCActivityLog({
|
|
id: 'mockId',
|
|
credentialConfigurationId: 'mockId',
|
|
idType: ['mockIDtype'] as string[],
|
|
_vcKey: 'mock_vc_key',
|
|
type: 'mockType',
|
|
timestamp: 1234,
|
|
deviceName: 'fakeDevice',
|
|
vcLabel: 'fakeVClabel',
|
|
});
|
|
});
|
|
// BDD examples
|
|
it('should fetch id type from translation file mock', () => {
|
|
mockIl18nfn.mockImplementation(input => {
|
|
if (input === `VcDetails:mockIDtype`) {
|
|
return 'National ID';
|
|
}
|
|
});
|
|
activityLog.getActionText(mockIl18nfn, wellknown);
|
|
expect(mockIl18nfn).toHaveBeenCalledWith('mockType', {
|
|
idType: 'fake VC',
|
|
vcStatus: '',
|
|
});
|
|
expect(mockIl18nfn).toHaveBeenCalledTimes(1);
|
|
// TODO: assert the returned string
|
|
});
|
|
it.skip('should not fetch id type from translation file mock', () => {
|
|
// Reason: The test assertion needs fix
|
|
activityLog.idType = undefined;
|
|
activityLog.getActionText(mockIl18nfn, wellknown);
|
|
expect(mockIl18nfn).toHaveBeenCalledWith('mockType', {
|
|
idType: '',
|
|
});
|
|
expect(mockIl18nfn).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
|
|
describe('VCActivityLog.getLogFromObject', () => {
|
|
it('should create VCActivityLog instance from object', () => {
|
|
const mockData = {
|
|
id: 'test-id',
|
|
type: 'VC_ADDED',
|
|
timestamp: 1234567890,
|
|
deviceName: 'Test Device',
|
|
};
|
|
|
|
const log = VCActivityLog.getLogFromObject(mockData);
|
|
|
|
expect(log).toBeInstanceOf(VCActivityLog);
|
|
expect(log.id).toBe('test-id');
|
|
expect(log.type).toBe('VC_ADDED');
|
|
expect(log.timestamp).toBe(1234567890);
|
|
expect(log.deviceName).toBe('Test Device');
|
|
});
|
|
|
|
it('should create VCActivityLog from empty object', () => {
|
|
const log = VCActivityLog.getLogFromObject({});
|
|
|
|
expect(log).toBeInstanceOf(VCActivityLog);
|
|
expect(log.timestamp).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('VCActivityLog.getActionLabel', () => {
|
|
it('should return formatted action label with device name and time', () => {
|
|
const mockLog = new VCActivityLog({
|
|
deviceName: 'iPhone 12',
|
|
timestamp: Date.now() - 60000, // 1 minute ago
|
|
});
|
|
|
|
const label = mockLog.getActionLabel('en');
|
|
|
|
expect(label).toContain('iPhone 12');
|
|
expect(label).toContain('·');
|
|
expect(label).toContain('ago');
|
|
});
|
|
|
|
it('should return only time when device name is empty', () => {
|
|
const mockLog = new VCActivityLog({
|
|
deviceName: '',
|
|
timestamp: Date.now() - 120000, // 2 minutes ago
|
|
});
|
|
|
|
const label = mockLog.getActionLabel('en');
|
|
|
|
expect(label).not.toContain('·');
|
|
expect(label).toContain('ago');
|
|
});
|
|
|
|
it('should filter out empty labels', () => {
|
|
const mockLog = new VCActivityLog({
|
|
deviceName: ' ', // whitespace only
|
|
timestamp: Date.now(),
|
|
});
|
|
|
|
const label = mockLog.getActionLabel('en');
|
|
|
|
expect(label).not.toContain('·');
|
|
expect(label).toBeTruthy();
|
|
});
|
|
|
|
it('should format time with device name in English locale', () => {
|
|
const mockLog = new VCActivityLog({
|
|
deviceName: 'Test Device',
|
|
timestamp: Date.now() - 300000, // 5 minutes ago
|
|
});
|
|
|
|
const labelEn = mockLog.getActionLabel('en');
|
|
expect(labelEn).toBeTruthy();
|
|
expect(labelEn).toContain('Test Device');
|
|
});
|
|
});
|