Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

systemtagscollectionSpec.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * ownCloud
  3. *
  4. * @author Vincent Petry
  5. * @copyright 2016 Vincent Petry <pvince81@owncloud.com>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  9. * License as published by the Free Software Foundation; either
  10. * version 3 of the License, or any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public
  18. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. describe('OC.SystemTags.SystemTagsCollection tests', function() {
  22. var collection;
  23. beforeEach(function() {
  24. collection = new OC.SystemTags.SystemTagsCollection();
  25. });
  26. it('fetches only once, until reset', function() {
  27. var syncStub = sinon.stub(collection, 'sync');
  28. var callback = sinon.stub();
  29. var callback2 = sinon.stub();
  30. var callback3 = sinon.stub();
  31. var eventHandler = sinon.stub();
  32. collection.on('sync', eventHandler);
  33. collection.fetch({
  34. success: callback
  35. });
  36. expect(callback.notCalled).toEqual(true);
  37. expect(syncStub.calledOnce).toEqual(true);
  38. expect(eventHandler.notCalled).toEqual(true);
  39. syncStub.yieldTo('success', collection);
  40. expect(callback.calledOnce).toEqual(true);
  41. expect(callback.firstCall.args[0]).toEqual(collection);
  42. expect(eventHandler.calledOnce).toEqual(true);
  43. expect(eventHandler.firstCall.args[0]).toEqual(collection);
  44. collection.fetch({
  45. success: callback2
  46. });
  47. expect(eventHandler.calledTwice).toEqual(true);
  48. expect(eventHandler.secondCall.args[0]).toEqual(collection);
  49. // not re-called
  50. expect(syncStub.calledOnce).toEqual(true);
  51. expect(callback.calledOnce).toEqual(true);
  52. expect(callback2.calledOnce).toEqual(true);
  53. expect(callback2.firstCall.args[0]).toEqual(collection);
  54. expect(collection.fetched).toEqual(true);
  55. collection.reset();
  56. expect(collection.fetched).toEqual(false);
  57. collection.fetch({
  58. success: callback3
  59. });
  60. expect(syncStub.calledTwice).toEqual(true);
  61. syncStub.yieldTo('success', collection);
  62. expect(callback3.calledOnce).toEqual(true);
  63. expect(callback3.firstCall.args[0]).toEqual(collection);
  64. syncStub.restore();
  65. });
  66. });