@@ -3,36 +3,27 @@ const fs = require('fs-extra');
3
3
const path = require ( 'path' ) ;
4
4
const { ThemeDefaults } = require ( '../../../scripts/main/defaults/theme-defaults.js' ) ;
5
5
6
- describe . only ( 'ThemeDefaults' , function ( ) {
7
- const themePath = './test/scripts/main/theme' ;
8
- const basePath = path . join ( themePath , '@advanced-rest-client' ) ;
6
+ const testPaths = require ( '../../setup-paths' ) ;
7
+ testPaths . getBasePath ( ) ;
8
+
9
+ describe ( 'ThemeDefaults' , function ( ) {
10
+ const basePath = path . join ( process . env . ARC_THEMES , '@advanced-rest-client' ) ;
9
11
const defaultFile = path . join ( basePath , 'arc-electron-default-theme' , 'arc-electron-default-theme.css' ) ;
10
12
const defaultPackage = path . join ( basePath , 'arc-electron-default-theme' , 'package.json' ) ;
11
13
const anypointFile = path . join ( basePath , 'arc-electron-anypoint-theme' , 'arc-electron-anypoint-theme.css' ) ;
12
14
const anypointPackage = path . join ( basePath , 'arc-electron-anypoint-theme' , 'package.json' ) ;
13
15
const darkFile = path . join ( basePath , 'arc-electron-dark-theme' , 'arc-electron-dark-theme.css' ) ;
14
16
const darkPackage = path . join ( basePath , 'arc-electron-dark-theme' , 'package.json' ) ;
15
- const themeInfo = path . join ( themePath , 'themes-info.json' ) ;
16
17
17
18
let instance ;
18
- describe ( 'Basics' , function ( ) {
19
- before ( function ( ) {
20
- instance = new ThemeDefaults ( ) ;
21
- } ) ;
22
-
23
- it ( 'Sets themePath property' , function ( ) {
24
- assert . typeOf ( instance . themePath , 'string' ) ;
25
- } ) ;
26
- } ) ;
27
19
28
20
describe ( 'prepareEnvironment()' , function ( ) {
29
21
beforeEach ( function ( ) {
30
22
instance = new ThemeDefaults ( ) ;
31
- instance . themePath = themePath ;
32
23
} ) ;
33
24
34
25
afterEach ( function ( ) {
35
- return fs . remove ( instance . themePath ) ;
26
+ return fs . remove ( process . env . ARC_THEMES ) ;
36
27
} ) ;
37
28
38
29
async function testContents ( themeFile , pkgFile ) {
@@ -59,34 +50,54 @@ describe.only('ThemeDefaults', function() {
59
50
60
51
it ( 'Copies theme info file' , async ( ) => {
61
52
await instance . prepareEnvironment ( ) ;
62
- const exists = await fs . exists ( themeInfo ) ;
53
+ const exists = await fs . exists ( process . env . ARC_THEMES_SETTINGS ) ;
63
54
assert . isTrue ( exists , 'File exists' ) ;
64
55
} ) ;
65
56
} ) ;
66
57
67
58
describe ( 'Updating preinstalled theme files' , ( ) => {
68
59
beforeEach ( function ( ) {
69
60
instance = new ThemeDefaults ( ) ;
70
- instance . themePath = themePath ;
71
61
} ) ;
72
62
73
63
afterEach ( function ( ) {
74
- return fs . remove ( instance . themePath ) ;
64
+ return fs . remove ( process . env . ARC_THEMES ) ;
75
65
} ) ;
76
66
77
67
async function installDummy ( version ) {
78
- version = version || '1 .0.0' ;
68
+ version = version || '0 .0.0' ;
79
69
await fs . outputFile ( defaultFile , 'not-a-theme-file' ) ;
80
70
await fs . writeJson ( defaultPackage , {
81
71
version
82
72
} ) ;
83
73
}
84
74
75
+ async function installDb ( ) {
76
+ const db = await fs . readJson (
77
+ path . join ( __dirname , '..' , '..' , '..' , 'appresources' , 'themes' , 'themes-info.json' ) ) ;
78
+ db . themes . forEach ( ( item ) => item . version = '0.0.0' ) ;
79
+ await fs . outputJson ( process . env . ARC_THEMES_SETTINGS , db ) ;
80
+ }
81
+
85
82
it ( 'updates pre-installed theme file' , async ( ) => {
86
83
await installDummy ( ) ;
87
84
await instance . prepareEnvironment ( ) ;
88
85
const contents = await fs . readFile ( defaultFile , 'utf8' ) ;
89
- assert . notEqual ( contents , 'not-a-theme-file' ) ;
86
+ assert . notEqual ( contents , 'not-a-theme-file' , 'Theme content has changed' ) ;
87
+ const pkg = await fs . readJson ( defaultPackage ) ;
88
+ assert . typeOf ( pkg . version , 'string' , 'Theme package has a version' ) ;
89
+ assert . notEqual ( pkg . version , '0.0.0' , 'Package version is updated' ) ;
90
+ } ) ;
91
+
92
+ it ( 'updates indo db' , async ( ) => {
93
+ await installDummy ( ) ;
94
+ await installDb ( ) ;
95
+ await instance . prepareEnvironment ( ) ;
96
+ const db = await fs . readJson ( process . env . ARC_THEMES_SETTINGS ) ;
97
+ db . themes . forEach ( ( item ) => {
98
+ assert . typeOf ( item . version , 'string' , 'Theme has a version' ) ;
99
+ assert . notEqual ( item . version , '0.0.0' , 'Theme version is updated' ) ;
100
+ } ) ;
90
101
} ) ;
91
102
} ) ;
92
103
} ) ;
0 commit comments