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

Task/cu 86942hp4v/7 shop create retail plugin for gg #69

Merged
1 change: 1 addition & 0 deletions plugin-retail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./src/plugin/retail');
32 changes: 32 additions & 0 deletions src/plugin/retail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var logger = require('../utils/utils').logger;

Check failure on line 1 in src/plugin/retail.js

View check run for this annotation

SonarQubePR NSoft / seven-gravity-gateway Sonarqube Results

src/plugin/retail.js#L1

Unexpected var, use let or const instead.

var preventKeysList = [];

Check failure on line 3 in src/plugin/retail.js

View check run for this annotation

SonarQubePR NSoft / seven-gravity-gateway Sonarqube Results

src/plugin/retail.js#L3

Unexpected var, use let or const instead.

function shouldPreventKeyDefaultBehavior(key) {
if (!preventKeysList.length) return false;

return !!preventKeysList.find(function(preventKey) {
return preventKey.key === key;
});
Lanchi marked this conversation as resolved.
Show resolved Hide resolved
}

function Retail() {}

Check failure on line 13 in src/plugin/retail.js

View check run for this annotation

SonarQubePR NSoft / seven-gravity-gateway Sonarqube Results

src/plugin/retail.js#L13

Unexpected empty function 'Retail'.

Retail.prototype.setUpOnce = function() {
window.document.addEventListener('keydown', function(e) {
if (shouldPreventKeyDefaultBehavior(e.key)) {
e.preventDefault();
logger.out('debug', '[GGP] Plugin Retail: Preventing key default behavior.', {
key: e.key
});
}
});
};

Retail.prototype.onLoad = function(slave, loadData) {
loadData.data.settings.preventKeys.forEach(function(key) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If preventKeys is not sent for some reason this will throw error. @thedev966

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dikaso It's possible case? Okay, I'll add some check in this next task I'm on.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. It is not required to set preventKeys for a tenant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, we will always set preventKeys, by default empty array, and override settings per tenant when needed. forEach shouldn't throw any error..

preventKeysList.push(key);
});
};

module.exports = Retail;
24 changes: 24 additions & 0 deletions test/plugin-retail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var assert = require('assert'),

Check failure on line 1 in test/plugin-retail.js

View check run for this annotation

SonarQubePR NSoft / seven-gravity-gateway Sonarqube Results

test/plugin-retail.js#L1

Unexpected var, use let or const instead.
sinon = require('sinon'),
Gateway = require('../src/slave_gateway'),
Retail = require('../plugin-retail'),
retailPlugin = new Retail();


describe('Retail', function() {
var slaveInstance;

Check failure on line 9 in test/plugin-retail.js

View check run for this annotation

SonarQubePR NSoft / seven-gravity-gateway Sonarqube Results

test/plugin-retail.js#L9

Unexpected var, use let or const instead.

beforeEach(function () {
slaveInstance = Gateway();
});

afterEach(function () {
sinon.restore();
});

it('should attach document keydown listener on init', function() {
var spy = sinon.spy(window.document, 'addEventListener');

Check failure on line 20 in test/plugin-retail.js

View check run for this annotation

SonarQubePR NSoft / seven-gravity-gateway Sonarqube Results

test/plugin-retail.js#L20

Unexpected var, use let or const instead.
retailPlugin.setUpOnce(slaveInstance);
assert.equal(spy.called, true);
});
});
4 changes: 3 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = [
'slave': './slave.js',
'plugin-storage': './plugin-storage.js',
'plugin-scan': './plugin-barcode-scan.js',
'plugin-retail': './plugin-retail.js'
},
plugins: [
new Clean(['dist']),
Expand All @@ -31,7 +32,8 @@ module.exports = [
'master': './master.js',
'slave': './slave.js',
'plugin-storage': './plugin-storage.js',
'plugin-scan': './plugin-barcode-scan.js'
'plugin-scan': './plugin-barcode-scan.js',
'plugin-retail': './plugin-retail.js'
},
plugins: [
new Uglify({
Expand Down
Loading