This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1033641 - [Vertical Homescreen] [Collections] [SCR] Ability to cr…
…eate collection groups offline
- Loading branch information
1 parent
a8bd1ac
commit 30afdf9
Showing
4 changed files
with
176 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
'use strict'; | ||
|
||
/* global Promise */ | ||
|
||
require('/js/common.js'); | ||
require('/js/objects.js'); | ||
require('/js/collection_icon.js'); | ||
require('/shared/test/unit/mocks/mock_collections_database.js'); | ||
require('/shared/test/unit/mocks/mock_navigator_moz_set_message_handler.js'); | ||
|
||
var mocksForCollection = new MocksHelper(['CollectionsDatabase']).init(); | ||
|
||
suite('create', function() { | ||
mocksForCollection.attachTestHelpers(); | ||
|
||
var realSetMessageHandler; | ||
var realL10n; | ||
|
||
var activity = { | ||
source: { | ||
name: 'create-collection', | ||
data: { | ||
maxIconSize: 60 | ||
} | ||
}, | ||
postResult: () => {} | ||
}; | ||
|
||
var mockL10n = { | ||
get: key => key | ||
}; | ||
|
||
var mockEme = { | ||
init: () => Promise.resolve(), | ||
log: console.log.bind(console), | ||
api: { | ||
Categories: { | ||
list: function() {} | ||
} | ||
} | ||
}; | ||
|
||
var mockSuggestions = { | ||
load: (categories) => Promise.resolve([categories[0].categoryId]) | ||
}; | ||
|
||
suiteSetup(function() { | ||
realL10n = navigator.mozL10n; | ||
navigator.mozL10n = mockL10n; | ||
|
||
realSetMessageHandler = navigator.mozSetMessageHandler; | ||
navigator.mozSetMessageHandler = window.MockNavigatormozSetMessageHandler; | ||
navigator.mozSetMessageHandler.mSetup(); | ||
}); | ||
|
||
suiteTeardown(function() { | ||
navigator.mozL10n = realL10n; | ||
navigator.mozSetMessageHandler = realSetMessageHandler; | ||
}); | ||
|
||
setup(function(done) { | ||
loadBodyHTML('/create.html'); | ||
|
||
window.eme = mockEme; | ||
window.Suggestions = mockSuggestions; | ||
|
||
require('/js/create_collection.js', function() { | ||
done(); | ||
}); | ||
}); | ||
|
||
test('alerts a network error message when offline', function(done) { | ||
var alertStub = this.sinon.stub(window, 'alert'); | ||
this.sinon.stub(mockEme.api.Categories, 'list') | ||
.returns(Promise.reject('network error')); | ||
|
||
navigator.mozSetMessageHandler.mTrigger('activity', activity); | ||
|
||
setTimeout(() => { | ||
assert.isTrue(alertStub.calledOnce); | ||
done(); | ||
}, 10); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters