1
0

sharedbreadcrumviewSpec.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /**
  2. * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
  3. *
  4. * @author Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. describe('OCA.Sharing.ShareBreadCrumbView tests', function() {
  23. var BreadCrumb = OCA.Files.BreadCrumb;
  24. var SharedBreadCrum = OCA.Sharing.ShareBreadCrumbView;
  25. describe('Rendering', function() {
  26. var bc;
  27. var sbc;
  28. var shareTab;
  29. beforeEach(function() {
  30. bc = new BreadCrumb({
  31. getCrumbUrl: function(part, index) {
  32. // for testing purposes
  33. return part.dir + '#' + index;
  34. }
  35. });
  36. shareTab = new OCA.Sharing.ShareTabView();
  37. sbc = new SharedBreadCrum({
  38. shareTab: shareTab
  39. });
  40. bc.addDetailView(sbc);
  41. });
  42. afterEach(function() {
  43. bc = null;
  44. sbc = null;
  45. shareModel = null;
  46. });
  47. it('Do not render in root', function() {
  48. var dirInfo = new OC.Files.FileInfo({
  49. id: 42,
  50. path: '/',
  51. type: 'dir',
  52. name: ''
  53. });
  54. bc.setDirectoryInfo(dirInfo);
  55. bc.setDirectory('');
  56. bc.render();
  57. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  58. expect(bc.$el.find('.icon-shared').length).toEqual(0);
  59. expect(bc.$el.find('.shared').length).toEqual(0);
  60. expect(bc.$el.find('.icon-public').length).toEqual(0);
  61. });
  62. it('Render in dir', function() {
  63. var dirInfo = new OC.Files.FileInfo({
  64. id: 42,
  65. path: '/foo',
  66. type: 'dir'
  67. });
  68. bc.setDirectoryInfo(dirInfo);
  69. bc.setDirectory('/foo');
  70. bc.render();
  71. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  72. expect(bc.$el.find('.icon-shared').length).toEqual(1);
  73. expect(bc.$el.find('.shared').length).toEqual(0);
  74. expect(bc.$el.find('.icon-public').length).toEqual(0);
  75. });
  76. it('Render shared if dir is shared with user', function() {
  77. var dirInfo = new OC.Files.FileInfo({
  78. id: 42,
  79. path: '/foo',
  80. type: 'dir',
  81. shareTypes: [OC.Share.SHARE_TYPE_USER]
  82. });
  83. bc.setDirectoryInfo(dirInfo);
  84. bc.setDirectory('/foo');
  85. bc.render();
  86. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  87. expect(bc.$el.find('.icon-shared').length).toEqual(1);
  88. expect(bc.$el.find('.shared').length).toEqual(1);
  89. expect(bc.$el.find('.icon-public').length).toEqual(0);
  90. });
  91. it('Render shared if dir is shared with group', function() {
  92. var dirInfo = new OC.Files.FileInfo({
  93. id: 42,
  94. path: '/foo',
  95. type: 'dir',
  96. shareTypes: [OC.Share.SHARE_TYPE_GROUP]
  97. });
  98. bc.setDirectoryInfo(dirInfo);
  99. bc.setDirectory('/foo');
  100. bc.render();
  101. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  102. expect(bc.$el.find('.icon-shared').length).toEqual(1);
  103. expect(bc.$el.find('.shared').length).toEqual(1);
  104. expect(bc.$el.find('.icon-public').length).toEqual(0);
  105. });
  106. it('Render shared if dir is shared by link', function() {
  107. var dirInfo = new OC.Files.FileInfo({
  108. id: 42,
  109. path: '/foo',
  110. type: 'dir',
  111. shareTypes: [OC.Share.SHARE_TYPE_LINK]
  112. });
  113. bc.setDirectoryInfo(dirInfo);
  114. bc.setDirectory('/foo');
  115. bc.render();
  116. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  117. expect(bc.$el.find('.icon-shared').length).toEqual(0);
  118. expect(bc.$el.find('.shared').length).toEqual(1);
  119. expect(bc.$el.find('.icon-public').length).toEqual(1);
  120. });
  121. it('Render shared if dir is shared by circle', function() {
  122. var dirInfo = new OC.Files.FileInfo({
  123. id: 42,
  124. path: '/foo',
  125. type: 'dir',
  126. shareTypes: [OC.Share.SHARE_TYPE_CIRCLE]
  127. });
  128. bc.setDirectoryInfo(dirInfo);
  129. bc.setDirectory('/foo');
  130. bc.render();
  131. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  132. expect(bc.$el.find('.icon-shared').length).toEqual(1);
  133. expect(bc.$el.find('.shared').length).toEqual(1);
  134. expect(bc.$el.find('.icon-public').length).toEqual(0);
  135. });
  136. it('Render shared if dir is shared with remote', function() {
  137. var dirInfo = new OC.Files.FileInfo({
  138. id: 42,
  139. path: '/foo',
  140. type: 'dir',
  141. shareTypes: [OC.Share.SHARE_TYPE_REMOTE]
  142. });
  143. bc.setDirectoryInfo(dirInfo);
  144. bc.setDirectory('/foo');
  145. bc.render();
  146. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  147. expect(bc.$el.find('.icon-shared').length).toEqual(1);
  148. expect(bc.$el.find('.shared').length).toEqual(1);
  149. expect(bc.$el.find('.icon-public').length).toEqual(0);
  150. });
  151. it('Render link shared if at least one is a link share', function() {
  152. var dirInfo = new OC.Files.FileInfo({
  153. id: 42,
  154. path: '/foo',
  155. type: 'dir',
  156. shareTypes: [
  157. OC.Share.SHARE_TYPE_USER,
  158. OC.Share.SHARE_TYPE_GROUP,
  159. OC.Share.SHARE_TYPE_LINK,
  160. OC.Share.SHARE_TYPE_EMAIL,
  161. OC.Share.SHARE_TYPE_REMOTE,
  162. OC.Share.SHARE_TYPE_CIRCLE
  163. ]
  164. });
  165. bc.setDirectoryInfo(dirInfo);
  166. bc.setDirectory('/foo');
  167. bc.render();
  168. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  169. expect(bc.$el.find('.icon-shared').length).toEqual(0);
  170. expect(bc.$el.find('.shared').length).toEqual(1);
  171. expect(bc.$el.find('.icon-public').length).toEqual(1);
  172. });
  173. it('Remove shared status from user share', function() {
  174. var dirInfo = new OC.Files.FileInfo({
  175. id: 42,
  176. path: '/foo',
  177. type: 'dir',
  178. shareTypes: [OC.Share.SHARE_TYPE_USER]
  179. });
  180. bc.setDirectory('/foo');
  181. bc.setDirectoryInfo(dirInfo);
  182. bc.render();
  183. var mock = sinon.createStubInstance(OCA.Files.FileList);
  184. mock.showDetailsView = function() { };
  185. OCA.Files.App.fileList = mock;
  186. var spy = sinon.spy(mock, 'showDetailsView');
  187. bc.$el.find('.icon-shared').click();
  188. expect(spy.calledOnce).toEqual(true);
  189. var model = sinon.createStubInstance(OC.Share.ShareItemModel);
  190. model.getSharesWithCurrentItem = function() { return [] };
  191. model.hasLinkShares = function() { return false; };
  192. shareTab.trigger('sharesChanged', model);
  193. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  194. expect(bc.$el.find('.icon-shared').length).toEqual(1);
  195. expect(bc.$el.find('.shared').length).toEqual(0);
  196. expect(bc.$el.find('.icon-public').length).toEqual(0);
  197. });
  198. it('Add link share to user share', function() {
  199. var dirInfo = new OC.Files.FileInfo({
  200. id: 42,
  201. path: '/foo',
  202. type: 'dir',
  203. shareTypes: [OC.Share.SHARE_TYPE_USER]
  204. });
  205. bc.setDirectory('/foo');
  206. bc.setDirectoryInfo(dirInfo);
  207. bc.render();
  208. var mock = sinon.createStubInstance(OCA.Files.FileList);
  209. mock.showDetailsView = function() { };
  210. OCA.Files.App.fileList = mock;
  211. var spy = sinon.spy(mock, 'showDetailsView');
  212. bc.$el.find('.icon-shared').click();
  213. expect(spy.calledOnce).toEqual(true);
  214. var model = sinon.createStubInstance(OC.Share.ShareItemModel);
  215. model.getSharesWithCurrentItem = function() { return [
  216. {share_type: OC.Share.SHARE_TYPE_USER}
  217. ] };
  218. model.hasLinkShares = function() { return true; };
  219. shareTab.trigger('sharesChanged', model);
  220. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  221. expect(bc.$el.find('.icon-shared').length).toEqual(0);
  222. expect(bc.$el.find('.shared').length).toEqual(1);
  223. expect(bc.$el.find('.icon-public').length).toEqual(1);
  224. });
  225. });
  226. });