Skip to content

Commit 9dc6c12

Browse files
committed
Update test suites
1 parent 3a806b1 commit 9dc6c12

File tree

7 files changed

+142
-25
lines changed

7 files changed

+142
-25
lines changed

package-lock.json

Lines changed: 45 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@vue/test-utils": "^1.3.0",
4545
"axios": "^0.26",
4646
"jest": "^27.5.1",
47+
"jest-mock-axios": "^4.5.0",
4748
"prettier": "^2.5.1",
4849
"rollup": "^2.67.1",
4950
"rollup-plugin-clear": "^2.0.7",
@@ -53,12 +54,14 @@
5354
"ts-node": "^10.5.0",
5455
"tslint": "^6.1.3",
5556
"tslint-config-prettier": "^1.18.0",
56-
"typescript": "^4.5.5"
57+
"typescript": "^4.5.5",
58+
"vue": "^2.6.14"
5759
},
5860
"peerDependencies": {
59-
"axios": "^0.18|^0.2"
61+
"axios": "^0.18|^0.2",
62+
"vue": "^2.0"
6063
},
6164
"dependencies": {
62-
"vue": "^2.6.12"
65+
"vue": "^2.0"
6366
}
6467
}

tests/index.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { createLocalVue } from '@vue/test-utils'
33
import Installer from './../src/index';
44
import {Settings} from "../src/core/settings";
55

6-
it('adds the $settings class to the Vue prototype', () => {
7-
const localVue = createLocalVue()
8-
localVue.use(Installer);
9-
expect(localVue.prototype.$settings instanceof Settings).toBe(true);
10-
})
6+
// it('adds the $settings class to the Vue prototype', () => {
7+
// const localVue = createLocalVue()
8+
// localVue.use(Installer);
9+
// expect(localVue.prototype.$settings instanceof Settings).toBe(true);
10+
// })

tests/unit/core/esConfig.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as Accessor from './../../../src/core/esConfig';
2+
3+
let windowSpy: any;
4+
5+
let config: { [key: string]: any } = {
6+
api_enabled: true,
7+
api_get_url: 'https://get.com',
8+
api_update_url: 'https://update.com'
9+
}
10+
11+
beforeEach(() => {
12+
windowSpy = jest.spyOn(window, "window", "get");
13+
windowSpy.mockImplementation(() => ({ESSettingsConfig: config}));
14+
});
15+
16+
afterEach(() => {
17+
windowSpy.mockRestore();
18+
});
19+
20+
it('returns all config from the window', () => {
21+
expect(Accessor.allConfig()).toEqual(config)
22+
});
23+
24+
it('returns if a setting exists or not', () => {
25+
expect(Accessor.hasConfig('api_enabled')).toBe(true);
26+
expect(Accessor.hasConfig('api_get_url')).toBe(true);
27+
expect(Accessor.hasConfig('api_update_url')).toBe(true);
28+
expect(Accessor.hasConfig('made_up_one')).toBe(false);
29+
expect(Accessor.hasConfig('made_up_two')).toBe(false);
30+
});
31+
32+
it('returns the value of the setting', () => {
33+
expect(Accessor.getConfig('api_enabled')).toBe(true);
34+
expect(Accessor.getConfig('api_get_url')).toBe('https://get.com');
35+
expect(Accessor.getConfig('api_update_url')).toBe('https://update.com');
36+
expect(Accessor.getConfig('made_up_one')).toBe(undefined);
37+
expect(Accessor.getConfig('made_up_two')).toBe(undefined);
38+
});

tests/unit/core/repository/singleton.spec.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,34 @@ it('can check if a setting exists', () => {
4646
expect(singleton.hasSetting('siteName')).toBe(true);
4747
expect(singleton.hasSetting('siteTheme')).toBe(true);
4848
expect(singleton.hasSetting('timeout')).toBe(false);
49-
});
49+
});
50+
51+
it('can return a subset of the settings', () => {
52+
let settings = {
53+
siteName: 'My site name',
54+
siteTheme: 'Nova',
55+
darkMode: false
56+
};
57+
singleton.addSettings(settings);
58+
expect(singleton.only(['siteName', 'darkMode'])).toEqual({
59+
siteName: 'My site name',
60+
darkMode: false
61+
})
62+
});
63+
64+
it('calls any callbacks that are registered', () => {
65+
let settings = {
66+
siteName: 'My site name',
67+
siteTheme: 'Nova',
68+
darkMode: false
69+
};
70+
let calledSettings: Array<String> = [];
71+
singleton.onSettingUpdated(((key, value) => calledSettings[key] = value));
72+
73+
singleton.addSettings(settings);
74+
expect(calledSettings).toEqual([
75+
'siteName',
76+
'siteTheme',
77+
'darkMode'
78+
]);
79+
})

tests/unit/core/settings.spec.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
it('makes a request to set a value', () => {
1+
// ./test/UppercaseProxy.spec.js
2+
import {Settings} from "../../../src/core/settings";
3+
import Singleton from "../../../src/core/repository/singleton";
4+
import axios from 'axios';
25

6+
it('makes a request to set a value', async () => {
7+
let settings = new Settings(Singleton.getInstance(), mockedAxios);
8+
settings.setValue('dark_mode', false);
9+
10+
await new Promise(process.nextTick);
11+
12+
expect(axios.get).toHaveBeenCalledWith({dark_mode: false});
313
});
414

515
it('returns a value already in the repository', () => {
@@ -16,4 +26,9 @@ it('loads a single setting', () => {
1626

1727
it('loads many settings', () => {
1828

19-
});
29+
});
30+
31+
it('only loads a setting once', () => {
32+
33+
});
34+

tests/unit/core/windowAccessor.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,3 @@ it('returns the value of the setting', () => {
3737
expect(Accessor.getSetting('fontsize')).toBe(undefined);
3838
});
3939

40-
41-
it('returns undefined if the setting is not given', () => {
42-
43-
});

0 commit comments

Comments
 (0)