Skip to content

Commit c5e6636

Browse files
committed
fix: default Config
1 parent 32e6cf3 commit c5e6636

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

jest.config.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ module.exports = {
77
testEnvironment: 'node',
88
setupFilesAfterEnv: ["jest-extended/all"],
99
roots: roots,
10-
globals: {
11-
'ts-jest': {
12-
tsconfig: 'tsconfig.test.json',
13-
},
14-
},
1510
transform: {
16-
'^.+\\.tsx?$': 'ts-jest',
11+
'^.+\\.tsx?$': ['ts-jest', {
12+
...require('./tsconfig.test.json')
13+
}],
1714
},
1815
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
1916
setupFiles: ['./tests/jest/setup.ts'],

src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,16 @@ export interface Config {
9393
}
9494

9595
export class Config {
96+
public constructor() {
97+
Object.assign(this, Config.defaultConfig());
98+
}
9699
/**
97100
* Assigns `updatedConfig` keys to the current config file
98101
*
99102
* @param partialConfig
100103
*/
101104
assign(partialConfig: Partial<Config>): Config {
102-
return Object.assign(this, Config.defaultConfig(), partialConfig);
105+
return Object.assign(this, partialConfig);
103106
}
104107

105108
/**

tests/jest/config.test.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import { Config } from '../../src/config';
22
import Storage from '../../src/storage/storage';
33
import { Translator } from '../../src/i18n/language';
4+
import { PluginPosition } from '../../src/plugin';
45

56
describe('Config', () => {
6-
//let config: Partial<Config> = null;
7-
8-
//beforeEach(() => {
9-
// config = Config.fromPartialConfig({
10-
// data: [[1, 2, 3]],
11-
// });
12-
//});
13-
147
it('should have data property', () => {
158
const config = Config.fromPartialConfig({
169
data: [[1, 2, 3]],
@@ -20,16 +13,16 @@ describe('Config', () => {
2013

2114
it('assign should set the default when partial config is empty', () => {
2215
const config = new Config();
23-
config.assign({})
24-
expect(config.width).toEqual("100%");
16+
config.assign({});
17+
expect(config.width).toEqual('100%');
2518
});
2619

2720
it('assign should set the correct default', () => {
2821
const config = new Config();
2922
config.assign({
30-
width: "500px"
31-
})
32-
expect(config.width).toEqual("500px");
23+
width: '500px',
24+
});
25+
expect(config.width).toEqual('500px');
3326
});
3427

3528
it('should return the correct values', () => {
@@ -61,7 +54,11 @@ describe('Config', () => {
6154
search: true,
6255
});
6356

64-
expect(conf.plugin.get('search')).toHaveLength(1);
57+
expect(conf.plugin.get('search')).toStrictEqual({
58+
id: 'search',
59+
position: PluginPosition.Header,
60+
component: expect.any(Function),
61+
});
6562
});
6663

6764
it('should create a userConfig with pagination', () => {
@@ -71,7 +68,11 @@ describe('Config', () => {
7168
pagination: true,
7269
});
7370

74-
expect(conf.plugin.get('pagination')).toHaveLength(1);
71+
expect(conf.plugin.get('pagination')).toStrictEqual({
72+
id: 'pagination',
73+
position: PluginPosition.Footer,
74+
component: expect.any(Function),
75+
});
7576
});
7677

7778
it('should create a userConfig with header', () => {
@@ -100,11 +101,7 @@ describe('Config', () => {
100101
});
101102

102103
expect(conf.header.columns.map((x) => x.name)).toStrictEqual(cols);
103-
expect(conf.header.columns.map((x) => x.sort)).toStrictEqual([
104-
{},
105-
{},
106-
{},
107-
]);
104+
expect(conf.header.columns.map((x) => x.sort)).toStrictEqual([{}, {}, {}]);
108105
});
109106

110107
it('should create a userConfig with header and custom sort', () => {
@@ -144,11 +141,12 @@ describe('Config', () => {
144141

145142
it('should update config', () => {
146143
const config = Config.fromPartialConfig({
147-
data: []
144+
data: [],
148145
}).update({
149146
autoWidth: false,
150147
});
151148
expect(config.width).toBe('100%');
149+
expect(config.height).toBe('auto');
152150
expect(config.autoWidth).toBeFalsy();
153151
});
154152
});

0 commit comments

Comments
 (0)