summaryrefslogtreecommitdiff
path: root/spec/javascripts/subbable_resource_spec.js.es6
diff options
context:
space:
mode:
authorBryce Johnson <bryce@gitlab.com>2016-11-18 16:49:40 +0100
committerBryce Johnson <bryce@gitlab.com>2016-11-18 16:49:40 +0100
commit9c67b320a7adacc3a777bf7dc2fabd0b9a31caa8 (patch)
treea1ca7ed2d6c09bbc333eca73633a7e64ab0684ff /spec/javascripts/subbable_resource_spec.js.es6
parent50b95f31396e37900e4f3176a746bb668e10745c (diff)
downloadgitlab-ce-9c67b320a7adacc3a777bf7dc2fabd0b9a31caa8.tar.gz
Backport SmartInterval, PrettyTime, SubbableResource from EE.backport-tt
Diffstat (limited to 'spec/javascripts/subbable_resource_spec.js.es6')
-rw-r--r--spec/javascripts/subbable_resource_spec.js.es665
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/javascripts/subbable_resource_spec.js.es6 b/spec/javascripts/subbable_resource_spec.js.es6
new file mode 100644
index 00000000000..df395296791
--- /dev/null
+++ b/spec/javascripts/subbable_resource_spec.js.es6
@@ -0,0 +1,65 @@
+/* eslint-disable */
+//= vue
+//= vue-resource
+//= require jquery
+//= require subbable_resource
+
+/*
+* Test that each rest verb calls the publish and subscribe function and passes the correct value back
+*
+*
+* */
+((global) => {
+ describe('Subbable Resource', function () {
+ describe('PubSub', function () {
+ beforeEach(function () {
+ this.MockResource = new global.SubbableResource('https://example.com');
+ });
+ it('should successfully add a single subscriber', function () {
+ const callback = () => {};
+ this.MockResource.subscribe(callback);
+
+ expect(this.MockResource.subscribers.length).toBe(1);
+ expect(this.MockResource.subscribers[0]).toBe(callback);
+ });
+
+ it('should successfully add multiple subscribers', function () {
+ const callbackOne = () => {};
+ const callbackTwo = () => {};
+ const callbackThree = () => {};
+
+ this.MockResource.subscribe(callbackOne);
+ this.MockResource.subscribe(callbackTwo);
+ this.MockResource.subscribe(callbackThree);
+
+ expect(this.MockResource.subscribers.length).toBe(3);
+ });
+
+ it('should successfully publish an update to a single subscriber', function () {
+ const state = { myprop: 1 };
+
+ const callbacks = {
+ one: (data) => expect(data.myprop).toBe(2),
+ two: (data) => expect(data.myprop).toBe(2),
+ three: (data) => expect(data.myprop).toBe(2)
+ };
+
+ const spyOne = spyOn(callbacks, 'one');
+ const spyTwo = spyOn(callbacks, 'two');
+ const spyThree = spyOn(callbacks, 'three');
+
+ this.MockResource.subscribe(callbacks.one);
+ this.MockResource.subscribe(callbacks.two);
+ this.MockResource.subscribe(callbacks.three);
+
+ state.myprop++;
+
+ this.MockResource.publish(state);
+
+ expect(spyOne).toHaveBeenCalled();
+ expect(spyTwo).toHaveBeenCalled();
+ expect(spyThree).toHaveBeenCalled();
+ });
+ });
+ });
+})(window.gl || (window.gl = {}));