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

feat: send hostname #28

Merged
merged 2 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: add test for send hostname
  • Loading branch information
kyuwoo.choi committed Apr 11, 2018
commit 4d02efb73ddc55be78ac72fcbb5a1457ff27824d
5 changes: 5 additions & 0 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
import {forEach, imagePing} from 'tui-code-snippet';
const {min, max} = Math;
let hostnameSent = false;

module.exports = {
/**
Expand Down Expand Up @@ -78,6 +79,10 @@ module.exports = {
*/
sendHostName() {
const {hostname} = location;
if (hostnameSent) {
return;
}
hostnameSent = true;

imagePing('https://www.google-analytics.com/collect', {
v: 1,
Expand Down
19 changes: 10 additions & 9 deletions test/imageEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ import snippet from 'tui-code-snippet';
import ImageEditor from '../src/js/imageEditor';

describe('ImageEditor', () => {
// hostnameSent module scope variable can not be reset.
// maintain cases with xit as it always fail, if you want to test these cases, change xit to fit one by one
describe('constructor', () => {
let imageEditor;
let imageEditor, el;

beforeEach(() => {
el = document.createElement('div');
spyOn(snippet, 'imagePing');
});

afterEach(() => {
imageEditor.destroy();
});

it('should send hostname by default', () => {
const el = document.createElement('div');
spyOn(snippet, 'imagePing');

xit('should send hostname by default', () => {
imageEditor = new ImageEditor(el);

expect(snippet.imagePing).toHaveBeenCalled();
});

it('should not send hostname on usageStatistics option false', () => {
const el = document.createElement('div');
spyOn(snippet, 'imagePing');

xit('should not send hostname on usageStatistics option false', () => {
imageEditor = new ImageEditor(el, {
usageStatistics: false
});
Expand Down