Skip to content

Commit

Permalink
Show toolbar only on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ambisign-gavin committed Feb 23, 2019
1 parent 081728a commit 02140f0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Expand Up @@ -46,5 +46,8 @@ module.exports = {
"error",
{ "ignoreRestSiblings": true }
]
},
"globals": {
"process": true
}
};
14 changes: 14 additions & 0 deletions __tests__/src/sticker/__snapshots__/index.js.snap
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`StickerToolbar should not render when platform is mac 1`] = `
<div>
<StickerDescription />
</div>
`;

exports[`StickerToolbar should render correct when platform is windows 1`] = `
<div>
<StickerToolBar />
<StickerDescription />
</div>
`;
33 changes: 33 additions & 0 deletions __tests__/src/sticker/index.js
@@ -0,0 +1,33 @@
// @flow
import React from 'react';
import { shallow } from 'enzyme';
import { Sticker } from '../../../src/sticker/html';

describe('StickerToolbar', () => {
let originalPlatform;

beforeAll(() => {
originalPlatform = process.platform;
});

afterAll(() => {
Object.defineProperty(process, 'platform', {
value: originalPlatform
});
});

it('should render correct when platform is windows', () => {
Object.defineProperty(process, 'platform', {
value: 'win32'
});
expect(shallow(<Sticker/>)).toMatchSnapshot();
});

it('should not render when platform is mac', () => {
Object.defineProperty(process, 'platform', {
value: 'darwin'
});
expect(shallow(<Sticker/>)).toMatchSnapshot();
});

});
14 changes: 12 additions & 2 deletions src/sticker/html/index.js
Expand Up @@ -7,10 +7,20 @@ import StickerToolBar from '../../component/stickerToolbar';

const app = document.getElementById('app');

const Sticker = () => {
function renderToolBarIfOnWindows() {
console.log('process.platform', process.platform);

if (/^win/i.test(process.platform)) {
return (
<StickerToolBar />
);
}
}

export const Sticker = () => {
return (
<div>
<StickerToolBar />
{renderToolBarIfOnWindows()}
<StickerDescription />
</div>
);
Expand Down

0 comments on commit 02140f0

Please sign in to comment.