Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config of End-to-End & Search window e2e test code #163

Merged
merged 13 commits into from
Jan 23, 2019
Next Next commit
Refactor about constant of path
  • Loading branch information
HyunmoAhn committed Jan 15, 2019
commit bd25cefc9394458b61a7ed94d15d129cfd43203f
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"alias": {
"actions": "./app/actions",
"assets": "./app/assets",
"config": "./app/config.js",
"constants": "./app/constants",
"components": "./app/components",
"main": "./app/main",
Expand Down
34 changes: 34 additions & 0 deletions app/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { app, remote } from 'electron';
import path from 'path';

const BASIC_PATH = (app || remote.app).getPath('appData');
const TEMP_DIR = process.platform === 'win32' ? 'C:\\Windows\\Temp' : '/tmp';
const IS_TEST = process.env.NODE_ENV === 'test';
const SETTING_FILE = 'store.json';

export const SETTING_FILE_PATH = !IS_TEST ?
path.join(BASIC_PATH, 'oh-my-desk', SETTING_FILE) :
path.join(TEMP_DIR, SETTING_FILE);

const ROOT_PATH = path.resolve(__dirname, '..');

function getPagePath(target) {
const ENV = process.env.NODE_ENV;
const MIDDLE_PATH = ENV === 'development' ?
path.join('app', 'renderer', 'pages', target) :
path.join('build');

return `file://${path.join(ROOT_PATH, MIDDLE_PATH, `${target}.html`)}`;
}
export const WIDGET_PATH = getPagePath('widget');
export const PREFERENCE_PATH = getPagePath('preference');
export const SEARCH_PATH = getPagePath('search');
export const UPDATE_WINDOW_PATH = getPagePath('UpdateWindow');
export const UPDATE_PROGRESS_PATH = getPagePath('UpdateProgress');

export const TRAY_ICON_PATH = path.join(ROOT_PATH, 'app', 'assets', 'iconTemplate.png');
export const LOGO_ICON_PATH = path.join(ROOT_PATH, 'app', 'assets', 'oh-my-desk-icon.png');

export const DEFAULT_SETTING = {

};
39 changes: 1 addition & 38 deletions app/constants/path/index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,8 @@
import { app, remote } from 'electron';
import path from 'path';

/**
* Path for globally.
*/
export const CONFIG_PATH = (app || remote.app).getPath('appData');
export const SETTING_FILE_NAME = '/oh-my-desk/store.json';

/**
* Path for main process.
*/

function getPagePath(target) {
const rootPath = process.env.NODE_ENV === 'development' ?
path.resolve(__dirname, '../../..') : path.resolve(__dirname, '..');
const projectPath = process.env.NODE_ENV === 'development' ? `app/renderer/pages/${target}` : 'build';
const htmlPath = `${target}.html`;

return path.join(rootPath, projectPath, htmlPath);
}

export const WIDGET_PATH = getPagePath('widget');
export const PREFERENCE_PATH = getPagePath('preference');
export const SEARCH_PATH = getPagePath('search');
export const UPDATE_WINDOW_PATH = getPagePath('UpdateWindow');
export const UPDATE_PROGRESS_PATH = getPagePath('UpdateProgress');

function getAssetPath(image) {
const rootPath = process.env.NODE_ENV === 'development' ?
path.resolve(__dirname, '../../..') : path.resolve(__dirname, '..');
const assetPath = 'app/assets';

return path.join(rootPath, assetPath, `${image}.png`);
}

export const TRAY_ICON_PATH = getAssetPath('iconTemplate');
export const LOGO_ICON_PATH = getAssetPath('oh-my-desk-icon');

/**
* Path for renderer process.
*/
const ROOT_PATH = process.env.NODE_ENV === 'development' ? // TODO find better method to get root path.
path.resolve(__dirname, '../../../..') : path.resolve(__dirname, '..');
export const PRELOAD_SCRIPT_PATH = path.join(ROOT_PATH, 'build/preloadScript.js');
export const PRELOAD_SCRIPT_PATH = path.join(ROOT_PATH, 'build/preloadScript.js'); // eslint-disable-line
4 changes: 2 additions & 2 deletions app/main/controllers/search.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { app, dialog } from 'electron';
import * as TYPES from 'actions/constant/actionTypes';
import TrayBar from 'main/utils/menu/trayMenuBar';
import * as PATH from 'constants/path';
import { LOGO_ICON_PATH } from 'config';
import i18n from 'constants/i18n';

const searchController = (action) => {
Expand All @@ -18,7 +18,7 @@ const searchController = (action) => {
title: text.quit,
message: text.quitMessage,
buttons: [text.ok, text.cancel],
icon: PATH.LOGO_ICON_PATH,
icon: LOGO_ICON_PATH,
};
dialog.showMessageBox(options, (index) => {
const isYesBtn = index === 0;
Expand Down
11 changes: 2 additions & 9 deletions app/main/utils/__tests__/update/openUpdateProgress.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BrowserWindow } from 'electron';
import uuid from 'uuid';
import url from 'url';
import * as PATH from 'constants/path';
import { UPDATE_PROGRESS_PATH } from 'config';
import store from 'store/storeMain';
import openUpdateProgress from 'main/utils/update/openUpdateProgress';
import { updateProgressWindowOpen, updateProgressWindowClose } from 'actions/update';
Expand Down Expand Up @@ -45,12 +44,6 @@ describe('test openUpdateProgress', () => {
openUpdateProgress();

expect(mockWindow.loadURL).toHaveBeenCalledTimes(1);
expect(mockWindow.loadURL).toHaveBeenCalledWith(
url.format({
pathname: PATH.UPDATE_PROGRESS_PATH,
protocol: 'file:',
slashes: true,
}),
);
expect(mockWindow.loadURL).toHaveBeenCalledWith(UPDATE_PROGRESS_PATH);
});
});
11 changes: 2 additions & 9 deletions app/main/utils/__tests__/update/openUpdateWindow.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BrowserWindow } from 'electron';
import url from 'url';
import * as PATH from 'constants/path';
import { UPDATE_WINDOW_PATH } from 'config';
import openUpdateWindow from 'main/utils/update/openUpdateWindow';

describe('test openUpdateWindow', () => {
Expand All @@ -15,12 +14,6 @@ describe('test openUpdateWindow', () => {
openUpdateWindow();

expect(mockWindow.loadURL).toHaveBeenCalledTimes(1);
expect(mockWindow.loadURL).toHaveBeenCalledWith(
url.format({
pathname: PATH.UPDATE_WINDOW_PATH,
protocol: 'file:',
slashes: true,
}),
);
expect(mockWindow.loadURL).toHaveBeenCalledWith(UPDATE_WINDOW_PATH);
});
});
9 changes: 4 additions & 5 deletions app/main/utils/__tests__/widget/makeWidget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Immutable from 'immutable';
import * as actions from 'actions/widget';
import { BrowserWindow as MockBrowserWindow } from 'app/__mocks__/electron';
import storeMock from 'store/storeMain';
import * as PATH from 'constants/path';
import { WIDGET_PATH, LOGO_ICON_PATH } from 'config';
import * as updateWidgetContentBounds from 'main/utils/widget/updateWidgetContentBounds';
import makeWidget from 'main/utils/widget/makeWidget';

Expand Down Expand Up @@ -106,7 +106,7 @@ describe('test makeWidgetWindow', () => {
title: 'Close Widget',
message: 'Content of progress will be disappear. \nDo close making window?',
buttons: ['Ok', 'Cancel'],
icon: PATH.LOGO_ICON_PATH,
icon: LOGO_ICON_PATH,
}, expect.any(Function));
});

Expand All @@ -131,7 +131,7 @@ describe('test makeWidgetWindow', () => {
title: 'Close Widget',
message: 'Content of progress will be disappear. \nDo close making window?',
buttons: ['Ok', 'Cancel'],
icon: PATH.LOGO_ICON_PATH,
icon: LOGO_ICON_PATH,
}, expect.any(Function));
});

Expand Down Expand Up @@ -216,8 +216,7 @@ describe('test makeWidgetWindow', () => {
it('when process.env.NODE_ENV === development', () => {
makeWidget('mock-id', mockInfo);
expect(mock.loadURL).toHaveBeenCalledTimes(1);
expect(mock.loadURL)
.toHaveBeenCalledWith(`file://${PATH.WIDGET_PATH}`);
expect(mock.loadURL).toHaveBeenCalledWith(WIDGET_PATH);
});

// TODO test about process.env.NODE_ENV === 'production'
Expand Down
11 changes: 2 additions & 9 deletions app/main/utils/__tests__/window/openPreference.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { BrowserWindow } from 'electron';
import Immutable from 'immutable';
import uuid from 'uuid';
import url from 'url';
import store from 'store/storeMain';
import * as PATH from 'constants/path';
import { PREFERENCE_PATH } from 'config';
import openPreference from 'main/utils/window/openPreference';
import { openBrowserWindow } from 'actions/window';
import * as preferenceActions from 'actions/preference';
Expand Down Expand Up @@ -64,13 +63,7 @@ describe('test openPreference', () => {
openPreference();

expect(mockWindow.loadURL).toHaveBeenCalledTimes(1);
expect(mockWindow.loadURL).toHaveBeenCalledWith(
url.format({
pathname: PATH.PREFERENCE_PATH,
protocol: 'file:',
slashed: true,
}),
);
expect(mockWindow.loadURL).toHaveBeenCalledWith(PREFERENCE_PATH);
});

it('should call BrowserWindow.on', () => {
Expand Down
13 changes: 7 additions & 6 deletions app/main/utils/disk/getData.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import fs from 'fs';
import * as PATH from 'constants/path';
import * as SETTING from 'constants/setting';
import {
DEFAULT_SETTING,
SETTING_FILE_PATH,
} from 'config';

const getData = () => {
const STORED_PATH = `${PATH.CONFIG_PATH}/${PATH.SETTING_FILE_NAME}`;
if (!fs.existsSync(STORED_PATH)) {
return JSON.parse(SETTING.defaultWidgets);
if (!fs.existsSync(SETTING_FILE_PATH)) {
return DEFAULT_SETTING;
}

const storedData = fs.readFileSync(STORED_PATH, { encoding: 'utf-8' });
const storedData = fs.readFileSync(SETTING_FILE_PATH, { encoding: 'utf-8' });

return JSON.parse(storedData);
};
Expand Down
4 changes: 2 additions & 2 deletions app/main/utils/disk/saveData.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fs from 'fs';
import * as PATH from 'constants/path';
import { SETTING_FILE_PATH } from 'config';
import store from 'store/storeMain';

const saveData = () => {
const data = store.getState().get('share');

fs.writeFileSync(`${PATH.CONFIG_PATH}/${PATH.SETTING_FILE_NAME}`, JSON.stringify(data.toJS()));
fs.writeFileSync(SETTING_FILE_PATH, JSON.stringify(data.toJS()));
};

export default saveData;
14 changes: 6 additions & 8 deletions app/main/utils/menu/trayMenuBar.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { app, globalShortcut, Menu } from 'electron';
import menuBar from 'menubar';
import url from 'url';
import store from 'store/storeMain';
import {
searchTrayClose,
searchTrayOpen,
} from 'actions/search';
import * as PATH from 'constants/path';
import {
SEARCH_PATH,
TRAY_ICON_PATH,
} from 'config';
import i18n from 'constants/i18n';
import openPreference from 'main/utils/window/openPreference';

const trayMenuBar = menuBar({
icon: PATH.TRAY_ICON_PATH,
index: url.format({
pathname: PATH.SEARCH_PATH,
protocol: 'file:',
slashes: true,
}),
icon: TRAY_ICON_PATH,
index: SEARCH_PATH,
showDockIcon: true,
tooltip: `oh-my-desk ${app.getVersion()}`,
fullscreenable: false,
Expand Down
9 changes: 2 additions & 7 deletions app/main/utils/update/openUpdateProgress.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BrowserWindow } from 'electron';
import url from 'url';
import { v4 } from 'uuid';
import store from 'store/storeMain';
import * as PATH from 'constants/path';
import { UPDATE_PROGRESS_PATH } from 'config';
import {
updateProgressWindowOpen,
updateProgressWindowClose,
Expand All @@ -26,11 +25,7 @@ const openUpdateWindow = () => {

store.dispatch(updateProgressWindowOpen(id, updateWindow));

updateWindow.loadURL(url.format({
pathname: PATH.UPDATE_PROGRESS_PATH,
protocol: 'file:',
slashes: true,
}));
updateWindow.loadURL(UPDATE_PROGRESS_PATH);
};

export default openUpdateWindow;
9 changes: 2 additions & 7 deletions app/main/utils/update/openUpdateWindow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BrowserWindow } from 'electron';
import url from 'url';
import * as PATH from 'constants/path';
import { UPDATE_WINDOW_PATH } from 'config';

const openUpdateWindow = () => {
const updateWindow = new BrowserWindow({
Expand All @@ -13,11 +12,7 @@ const openUpdateWindow = () => {
},
});

updateWindow.loadURL(url.format({
pathname: PATH.UPDATE_WINDOW_PATH,
protocol: 'file:',
slashes: true,
}));
updateWindow.loadURL(UPDATE_WINDOW_PATH);
};

export default openUpdateWindow;
11 changes: 3 additions & 8 deletions app/main/utils/widget/makeWidget.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { BrowserWindow, dialog } from 'electron';
import url from 'url';
import * as actions from 'actions/widget';
import { widgetInfoByIdSelector } from 'store/reducers/share/identification/selectors';
import store from 'store/storeMain';
import createWidget from 'main/utils/widget/createWidget';
import updateWidgetContentBounds from 'main/utils/widget/updateWidgetContentBounds';
import * as PATH from 'constants/path';
import { WIDGET_PATH, LOGO_ICON_PATH } from 'config';
import i18n from 'constants/i18n';

const makeWidget = (id, info, isFocus) => {
Expand All @@ -26,11 +25,7 @@ const makeWidget = (id, info, isFocus) => {
minHeight: 300,
});

widget.loadURL(url.format({
pathname: PATH.WIDGET_PATH,
protocol: 'file:',
slashes: true,
}));
widget.loadURL(WIDGET_PATH);

widget.once('ready-to-show', () => {
if (isFocus) {
Expand Down Expand Up @@ -67,7 +62,7 @@ const makeWidget = (id, info, isFocus) => {
title: text.closeWidget,
message: text.closeMessage(targetInfo.get('name')),
buttons: [text.ok, text.cancel],
icon: PATH.LOGO_ICON_PATH,
icon: LOGO_ICON_PATH,
};
dialog.showMessageBox(options, (index) => {
if (index === 0) { // when click Yes button
Expand Down
9 changes: 2 additions & 7 deletions app/main/utils/window/openPreference.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { BrowserWindow } from 'electron';
import { v4 } from 'uuid';
import url from 'url';
import store from 'store/storeMain';
import * as identificationSelector from 'store/reducers/share/identification/selectors';
import * as identification from 'store/reducers/personal/identification/selectors';
import { openBrowserWindow } from 'actions/window';
import * as preferenceAction from 'actions/preference';
import * as PATH from 'constants/path';
import { PREFERENCE_PATH } from 'config';

const openPreference = () => {
const winId = identificationSelector.preferenceSelector(store.getState());
Expand All @@ -29,11 +28,7 @@ const openPreference = () => {
},
});

winPreference.loadURL(url.format({
pathname: PATH.PREFERENCE_PATH,
protocol: 'file:',
slashes: true,
}));
winPreference.loadURL(PREFERENCE_PATH);

if (process.env.NODE_ENV === 'development') {
winPreference.webContents.openDevTools();
Expand Down
1 change: 1 addition & 0 deletions webpack.basic.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module.exports = {
alias: {
actions: path.resolve(__dirname, 'app/actions'),
assets: path.resolve(__dirname, 'app/assets'),
config: path.resolve(__dirname, 'app/config.js'),
constants: path.resolve(__dirname, 'app/constants'),
components: path.resolve(__dirname, 'app/components'),
main: path.resolve(__dirname, 'app/main'),
Expand Down