Skip to content

Commit 876d6ec

Browse files
skjnldsvdanxuliu
authored andcommitted
Fixed jsunit
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 0a70544 commit 876d6ec

File tree

5 files changed

+75
-69
lines changed

5 files changed

+75
-69
lines changed

core/js/tests/specHelper.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ window.oc_appconfig = {
103103
window.oc_defaults = {
104104
docPlaceholderUrl: 'https://docs.example.org/PLACEHOLDER'
105105
};
106+
window.oc_capabilities = {
107+
}
106108

107109
/* jshint camelcase: true */
108110

core/js/tests/specs/sharedialoglinkshareview.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ describe('OC.Share.ShareDialogLinkShareView', function () {
8181
// Needed to render the view
8282
configModel.isShareWithLinkAllowed.returns(true);
8383

84-
// Setting the share also triggers the rendering
8584
shareModel.set({
86-
linkShare: {
87-
isLinkShare: true,
88-
}
85+
linkShares: [{
86+
id: 123
87+
}]
8988
});
89+
view.render();
9090

9191
$hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
9292
$workingIcon = $hideDownloadCheckbox.prev('.icon-loading-small');
@@ -119,11 +119,12 @@ describe('OC.Share.ShareDialogLinkShareView', function () {
119119

120120
it('checkbox is checked when the setting is enabled', function () {
121121
shareModel.set({
122-
linkShare: {
123-
isLinkShare: true,
122+
linkShares: [{
123+
id: 123,
124124
hideDownload: true
125-
}
125+
}]
126126
});
127+
view.render();
127128

128129
$hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
129130

@@ -141,16 +142,17 @@ describe('OC.Share.ShareDialogLinkShareView', function () {
141142
$hideDownloadCheckbox.change();
142143

143144
expect($workingIcon.hasClass('hidden')).toBeFalsy();
144-
expect(shareModel.saveLinkShare.withArgs({ hideDownload: true }).calledOnce).toBeTruthy();
145+
expect(shareModel.saveLinkShare.withArgs({ hideDownload: true, cid: 123 }).calledOnce).toBeTruthy();
145146
});
146147

147148
it('disables the setting if clicked when checked', function () {
148149
shareModel.set({
149-
linkShare: {
150-
isLinkShare: true,
150+
linkShares: [{
151+
id: 123,
151152
hideDownload: true
152-
}
153+
}]
153154
});
155+
view.render();
154156

155157
$hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
156158
$workingIcon = $hideDownloadCheckbox.prev('.icon-loading-small');
@@ -161,7 +163,7 @@ describe('OC.Share.ShareDialogLinkShareView', function () {
161163
$hideDownloadCheckbox.change();
162164

163165
expect($workingIcon.hasClass('hidden')).toBeFalsy();
164-
expect(shareModel.saveLinkShare.withArgs({ hideDownload: false }).calledOnce).toBeTruthy();
166+
expect(shareModel.saveLinkShare.withArgs({ hideDownload: false, cid: 123 }).calledOnce).toBeTruthy();
165167
});
166168

167169
});
@@ -176,13 +178,13 @@ describe('OC.Share.ShareDialogLinkShareView', function () {
176178
// Needed to render the view
177179
configModel.isShareWithLinkAllowed.returns(true);
178180

179-
// Setting the share also triggers the rendering
180181
shareModel.set({
181-
linkShare: {
182-
isLinkShare: true,
182+
linkShares: [{
183+
id: 123,
183184
password: 'password'
184-
}
185+
}]
185186
});
187+
view.render();
186188

187189
var $passwordDiv = view.$el.find('#linkPass');
188190
$passwordText = view.$el.find('.linkPassText');
@@ -202,28 +204,28 @@ describe('OC.Share.ShareDialogLinkShareView', function () {
202204
});
203205

204206
it('shows the working icon when called', function () {
205-
view.onPasswordEntered();
207+
view.onPasswordEntered({target: view.$el.find('.linkPassText')});
206208

207209
expect($workingIcon.hasClass('hidden')).toBeFalsy();
208-
expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword' }).calledOnce).toBeTruthy();
210+
expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword', cid: 123 }).calledOnce).toBeTruthy();
209211
});
210212

211213
it('hides the working icon when saving the password succeeds', function () {
212-
view.onPasswordEntered();
214+
view.onPasswordEntered({target: view.$el.find('.linkPassText')});
213215

214216
expect($workingIcon.hasClass('hidden')).toBeFalsy();
215-
expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword' }).calledOnce).toBeTruthy();
217+
expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword', cid: 123 }).calledOnce).toBeTruthy();
216218

217219
shareModel.saveLinkShare.yieldTo("complete", [shareModel]);
218220

219221
expect($workingIcon.hasClass('hidden')).toBeTruthy();
220222
});
221223

222224
it('hides the working icon when saving the password fails', function () {
223-
view.onPasswordEntered();
225+
view.onPasswordEntered({target: view.$el.find('.linkPassText')});
224226

225227
expect($workingIcon.hasClass('hidden')).toBeFalsy();
226-
expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword' }).calledOnce).toBeTruthy();
228+
expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword', cid: 123 }).calledOnce).toBeTruthy();
227229

228230
shareModel.saveLinkShare.yieldTo("complete", [shareModel]);
229231
shareModel.saveLinkShare.yieldTo("error", [shareModel, "The error message"]);

core/js/tests/specs/sharedialogshareelistview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('OC.Share.ShareDialogShareeListView', function () {
7373
$('#testArea').append(listView.$el);
7474

7575
shareModel.set({
76-
linkShare: {isLinkShare: false}
76+
linkShares: []
7777
});
7878

7979
oldCurrentUser = OC.currentUser;

core/js/tests/specs/sharedialogviewSpec.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('OC.Share.ShareDialogView', function() {
8989
// triggers rendering
9090
shareModel.set({
9191
shares: [],
92-
linkShare: {isLinkShare: false}
92+
linkShares: []
9393
});
9494

9595
autocompleteStub = sinon.stub($.fn, 'autocomplete').callsFake(function() {
@@ -130,8 +130,10 @@ describe('OC.Share.ShareDialogView', function() {
130130
it('update password on focus out', function() {
131131
$('#allowShareWithLink').val('yes');
132132

133-
dialog.model.set('linkShare', {
134-
isLinkShare: true
133+
dialog.model.set({
134+
linkShares: [{
135+
id: 123
136+
}]
135137
});
136138
dialog.render();
137139

@@ -143,20 +145,20 @@ describe('OC.Share.ShareDialogView', function() {
143145

144146
expect(saveLinkShareStub.calledOnce).toEqual(true);
145147
expect(saveLinkShareStub.firstCall.args[0]).toEqual({
148+
cid: 123,
146149
password: 'foo'
147150
});
148151
});
149152
it('update password on enter', function() {
150153
$('#allowShareWithLink').val('yes');
151154

152-
dialog.model.set('linkShare', {
153-
isLinkShare: true
155+
dialog.model.set({
156+
linkShares: [{
157+
id: 123
158+
}]
154159
});
155160
dialog.render();
156161

157-
// Toggle linkshare
158-
dialog.$el.find('.linkCheckbox').click();
159-
160162
// Enable password and enter password
161163
dialog.$el.find('[name=showPassword]').click();
162164
dialog.$el.find('.linkPassText').focus();
@@ -165,47 +167,48 @@ describe('OC.Share.ShareDialogView', function() {
165167

166168
expect(saveLinkShareStub.calledOnce).toEqual(true);
167169
expect(saveLinkShareStub.firstCall.args[0]).toEqual({
170+
cid: 123,
168171
password: 'foo'
169172
});
170173
});
171-
it('shows share with link checkbox when allowed', function() {
174+
it('shows add share with link button when allowed', function() {
172175
$('#allowShareWithLink').val('yes');
173176

174177
dialog.render();
175178

176-
expect(dialog.$el.find('.linkCheckbox').length).toEqual(1);
179+
expect(dialog.$el.find('.new-share').length).toEqual(1);
177180
});
178-
it('does not show share with link checkbox when not allowed', function() {
181+
it('does not show add share with link button when not allowed', function() {
179182
$('#allowShareWithLink').val('no');
180183

181184
dialog.render();
182185

183-
expect(dialog.$el.find('.linkCheckbox').length).toEqual(0);
186+
expect(dialog.$el.find('.new-share').length).toEqual(0);
184187
expect(dialog.$el.find('.shareWithField').length).toEqual(1);
185188
});
186189
it('shows populated link share when a link share exists', function() {
187190
// this is how the OC.Share class does it...
188191
var link = parent.location.protocol + '//' + location.host +
189-
OC.generateUrl('/s/') + 'tehtoken';
190-
shareModel.set('linkShare', {
191-
isLinkShare: true,
192-
token: 'tehtoken',
193-
link: link,
194-
expiration: '',
195-
permissions: OC.PERMISSION_READ,
196-
stime: 1403884258,
192+
OC.generateUrl('/s/') + 'thetoken';
193+
shareModel.set({
194+
linkShares: [{
195+
id: 123,
196+
url: link
197+
}]
197198
});
198199

199200
dialog.render();
200201

201-
expect(dialog.$el.find('.linkCheckbox').prop('checked')).toEqual(true);
202+
expect(dialog.$el.find('.share-menu .icon-more').length).toEqual(1);
202203
expect(dialog.$el.find('.linkText').val()).toEqual(link);
203204
});
204205
it('autofocus link text when clicked', function() {
205206
$('#allowShareWithLink').val('yes');
206207

207-
dialog.model.set('linkShare', {
208-
isLinkShare: true
208+
dialog.model.set({
209+
linkShares: [{
210+
id: 123
211+
}]
209212
});
210213
dialog.render();
211214

core/js/tests/specs/shareitemmodelSpec.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ describe('OC.Share.ShareItemModel', function() {
185185
expect(shares[0].share_with).toEqual('user1');
186186
expect(shares[0].share_with_displayname).toEqual('User One');
187187

188-
var linkShare = model.get('linkShare');
189-
expect(linkShare.isLinkShare).toEqual(true);
188+
var linkShares = model.get('linkShares');
189+
expect(linkShares.length).toEqual(1);
190+
var linkShare = linkShares[0];
190191
expect(linkShare.hideDownload).toEqual(true);
191192

192193
// TODO: check more attributes
@@ -268,8 +269,8 @@ describe('OC.Share.ShareItemModel', function() {
268269
// remaining share appears in this list
269270
expect(shares.length).toEqual(1);
270271

271-
var linkShare = model.get('linkShare');
272-
expect(linkShare.isLinkShare).toEqual(false);
272+
var linkShares = model.get('linkShares');
273+
expect(linkShares.length).toEqual(0);
273274
});
274275
it('parses correct link share when a nested link share exists along with parent one', function() {
275276
/* jshint camelcase: false */
@@ -321,8 +322,9 @@ describe('OC.Share.ShareItemModel', function() {
321322
// the parent share remains in the list
322323
expect(shares.length).toEqual(1);
323324

324-
var linkShare = model.get('linkShare');
325-
expect(linkShare.isLinkShare).toEqual(true);
325+
var linkShares = model.get('linkShares');
326+
expect(linkShares.length).toEqual(1);
327+
var linkShare = linkShares[0];
326328
expect(linkShare.token).toEqual('tehtoken');
327329
expect(linkShare.hideDownload).toEqual(false);
328330

@@ -575,9 +577,8 @@ describe('OC.Share.ShareItemModel', function() {
575577

576578
it('creates a new share if no link share exists', function() {
577579
model.set({
578-
linkShare: {
579-
isLinkShare: false
580-
}
580+
linkShares: [
581+
]
581582
});
582583

583584
model.saveLinkShare();
@@ -600,9 +601,8 @@ describe('OC.Share.ShareItemModel', function() {
600601
defaultExpireDate: 7
601602
});
602603
model.set({
603-
linkShare: {
604-
isLinkShare: false
605-
}
604+
linkShares: [
605+
]
606606
});
607607

608608
model.saveLinkShare();
@@ -621,34 +621,33 @@ describe('OC.Share.ShareItemModel', function() {
621621
});
622622
it('updates link share if it exists', function() {
623623
model.set({
624-
linkShare: {
625-
isLinkShare: true,
624+
linkShares: [{
626625
id: 123
627-
}
626+
}]
628627
});
629628

630629
model.saveLinkShare({
630+
cid: 123,
631631
password: 'test'
632632
});
633633

634634
expect(addShareStub.notCalled).toEqual(true);
635635
expect(updateShareStub.calledOnce).toEqual(true);
636636
expect(updateShareStub.firstCall.args[0]).toEqual(123);
637637
expect(updateShareStub.firstCall.args[1]).toEqual({
638+
cid: 123,
638639
password: 'test'
639640
});
640641
});
641642
it('forwards error message on add', function() {
642643
var errorStub = sinon.stub();
643644
model.set({
644-
linkShare: {
645-
isLinkShare: false
646-
}
645+
linkShares: [
646+
]
647647
}, {
648648
});
649649

650650
model.saveLinkShare({
651-
password: 'test'
652651
}, {
653652
error: errorStub
654653
});
@@ -661,14 +660,14 @@ describe('OC.Share.ShareItemModel', function() {
661660
it('forwards error message on update', function() {
662661
var errorStub = sinon.stub();
663662
model.set({
664-
linkShare: {
665-
isLinkShare: true,
666-
id: '123'
667-
}
663+
linkShares: [{
664+
id: 123
665+
}]
668666
}, {
669667
});
670668

671669
model.saveLinkShare({
670+
cid: 123,
672671
password: 'test'
673672
}, {
674673
error: errorStub

0 commit comments

Comments
 (0)