Skip to content

Commit

Permalink
🔧 add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreedzt committed Dec 6, 2023
1 parent 7da3699 commit cf4d076
Showing 1 changed file with 119 additions and 1 deletion.
120 changes: 119 additions & 1 deletion src/share/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { it, describe, expect } from 'vitest';
import { transformProfileConfig2GameConfig, getInitProfile } from './utils';
import {
transformProfileConfig2GameConfig,
getInitProfile,
transformProfileConfig2ShareConfig,
validateProfileShareConfig,
transformShareConfig2ProfileConfig,
} from './utils';
import { IShareProfileItem } from './types';

describe('utils: transformProfileConfig2GameConfig', () => {
it.concurrent('empty profile', () => {
Expand Down Expand Up @@ -33,3 +40,114 @@ describe('utils: transformProfileConfig2GameConfig', () => {
});
});
});

describe('utils: transformProfileConfig2ShareConfig', () => {
it.concurrent('empty profile', () => {
const profile = getInitProfile();
profile.config = [];

const result = transformProfileConfig2ShareConfig(profile);

expect(result).toEqual({
type: 'profile',
value: {
title: profile.title,
config: [],
},
});
});

it.concurrent('init profile', () => {
const profile = getInitProfile();

const result = transformProfileConfig2ShareConfig(profile);

expect(result).toEqual({
type: 'profile',
value: {
title: profile.title,
config: profile.config,
},
});
});
});

describe('utils: validateProfileShareConfig', () => {
it.concurrent('empty string', () => {
const result = validateProfileShareConfig('');

expect(result).toBe(false);
});

it.concurrent('empty json string', () => {
const result = validateProfileShareConfig('{}');

expect(result).toBe(false);
});

it.concurrent('empty json array', () => {
const result = validateProfileShareConfig('[]');

expect(result).toBe(false);
});

it.concurrent('empty share config value', () => {
const profile: IShareProfileItem = {
type: 'profile',
value: {
title: '',
config: [],
},
};
const result = validateProfileShareConfig(JSON.stringify(profile));

expect(result).toBe(true);
});
});

describe('utils: transformShareConfig2ProfileConfig', () => {
it.concurrent('empty share config value', () => {
const profile: IShareProfileItem = {
type: 'profile',
value: {
title: '',
config: [],
},
};
const result = transformShareConfig2ProfileConfig(profile);

expect(result).toEqual({
id: expect.any(String),
title: '',
config: [],
});
});

it.concurrent('init share config value', () => {
const profile: IShareProfileItem = {
type: 'profile',
value: {
title: 'test',
config: [
{
label: 'test',
value: 'test',
},
],
},
};

const result = transformShareConfig2ProfileConfig(profile);

expect(result).toEqual({
id: expect.any(String),
title: 'test',
config: [
{
label: 'test',
value: 'test',
},
],
});
});
});

0 comments on commit cf4d076

Please sign in to comment.