Front end of the Slack clone application.

test.customdriver.js 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* global describe:true, expect:true, it:true, dummyStorageDriver:true */
  2. describe('When Custom Drivers are used', function() {
  3. 'use strict';
  4. var errorMessage = 'Custom driver not compliant; see ' +
  5. 'https://mozilla.github.io/localForage/#definedriver';
  6. var nameErrorMessage = function(driverName) {
  7. return 'Custom driver name already in use: ' + driverName;
  8. };
  9. it('fails to define a no-name custom driver', function(done) {
  10. localforage.defineDriver({
  11. _initStorage: function() {},
  12. iterate: function() {},
  13. getItem: function() {},
  14. setItem: function() {},
  15. removeItem: function() {},
  16. clear: function() {},
  17. length: function() {},
  18. key: function() {},
  19. keys: function() {}
  20. }, null, function(err) {
  21. expect(err).to.be.an(Error);
  22. expect(err.message).to.be(errorMessage);
  23. done();
  24. });
  25. });
  26. it('fails to define a no-name custom driver [promise]', function(done) {
  27. localforage.defineDriver({
  28. _initStorage: function() {},
  29. iterate: function() {},
  30. getItem: function() {},
  31. setItem: function() {},
  32. removeItem: function() {},
  33. clear: function() {},
  34. length: function() {},
  35. key: function() {},
  36. keys: function() {}
  37. }).then(null, function(err) {
  38. expect(err).to.be.an(Error);
  39. expect(err.message).to.be(errorMessage);
  40. done();
  41. });
  42. });
  43. it('fails to define a custom driver with overlapping driver name',
  44. function(done) {
  45. localforage.defineDriver({
  46. _driver: localforage.INDEXEDDB,
  47. _initStorage: function() {},
  48. iterate: function() {},
  49. getItem: function() {},
  50. setItem: function() {},
  51. removeItem: function() {},
  52. clear: function() {},
  53. length: function() {},
  54. key: function() {},
  55. keys: function() {}
  56. }, null, function(err) {
  57. expect(err).to.be.an(Error);
  58. expect(err.message).to.be(nameErrorMessage(localforage.INDEXEDDB));
  59. done();
  60. });
  61. });
  62. it('fails to define a custom driver with overlapping driver name [promise]',
  63. function(done) {
  64. localforage.defineDriver({
  65. _driver: localforage.INDEXEDDB,
  66. _initStorage: function() {},
  67. iterate: function() {},
  68. getItem: function() {},
  69. setItem: function() {},
  70. removeItem: function() {},
  71. clear: function() {},
  72. length: function() {},
  73. key: function() {},
  74. keys: function() {}
  75. }).then(null, function(err) {
  76. expect(err).to.be.an(Error);
  77. expect(err.message).to.be(nameErrorMessage(localforage.INDEXEDDB));
  78. done();
  79. });
  80. });
  81. it('fails to define a custom driver with missing methods', function(done) {
  82. localforage.defineDriver({
  83. _driver: 'missingMethodsDriver',
  84. _initStorage: function() {},
  85. iterate: function() {},
  86. getItem: function() {},
  87. setItem: function() {},
  88. removeItem: function() {},
  89. clear: function() {}
  90. }, null, function(err) {
  91. expect(err).to.be.an(Error);
  92. expect(err.message).to.be(errorMessage);
  93. done();
  94. });
  95. });
  96. it('fails to define a custom driver with missing methods [promise]',
  97. function(done) {
  98. localforage.defineDriver({
  99. _driver: 'missingMethodsDriver',
  100. _initStorage: function() {},
  101. iterate: function() {},
  102. getItem: function() {},
  103. setItem: function() {},
  104. removeItem: function() {},
  105. clear: function() {}
  106. }).then(null, function(err) {
  107. expect(err).to.be.an(Error);
  108. expect(err.message).to.be(errorMessage);
  109. done();
  110. });
  111. });
  112. it('defines a compliant custom driver', function(done) {
  113. localforage.defineDriver(dummyStorageDriver, function() {
  114. done();
  115. });
  116. });
  117. it('defines a compliant custom driver [promise]', function(done) {
  118. localforage.defineDriver(dummyStorageDriver).then(function() {
  119. done();
  120. });
  121. });
  122. it('sets a custom driver', function(done) {
  123. localforage.defineDriver(dummyStorageDriver, function() {
  124. localforage.setDriver(dummyStorageDriver._driver, function() {
  125. expect(localforage.driver()).to.be(dummyStorageDriver._driver);
  126. done();
  127. });
  128. });
  129. });
  130. it('sets a custom driver [promise]', function(done) {
  131. localforage.defineDriver(dummyStorageDriver).then(function() {
  132. return localforage.setDriver(dummyStorageDriver._driver);
  133. }).then(function() {
  134. expect(localforage.driver()).to.be(dummyStorageDriver._driver);
  135. done();
  136. });
  137. });
  138. it('sets and uses a custom driver', function(done) {
  139. localforage.defineDriver(dummyStorageDriver, function() {
  140. localforage.setDriver(dummyStorageDriver._driver, function(err) {
  141. expect(err).to.be(undefined);
  142. localforage.setItem('testCallbackKey', 'testCallbackValue',
  143. function(err) {
  144. expect(err).to.be(null);
  145. localforage.getItem('testCallbackKey',
  146. function(err, value) {
  147. expect(err).to.be(null);
  148. expect(value).to.be('testCallbackValue');
  149. done();
  150. });
  151. });
  152. });
  153. });
  154. });
  155. it('sets and uses a custom driver [promise]', function(done) {
  156. localforage.defineDriver(dummyStorageDriver).then(function() {
  157. return localforage.setDriver(dummyStorageDriver._driver);
  158. }).then(function() {
  159. return localforage.setItem('testPromiseKey', 'testPromiseValue');
  160. }).then(function() {
  161. return localforage.getItem('testPromiseKey');
  162. }).then(function(value) {
  163. expect(value).to.be('testPromiseValue');
  164. done();
  165. });
  166. });
  167. });