This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23183 from crdlc/bug-1016228
Bug 1016228 - [Collections App] Rename Collections
- Loading branch information
Showing
14 changed files
with
302 additions
and
16 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
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
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,62 @@ | ||
'use strict'; | ||
|
||
/* global BaseCollection, Icon, GridIconRenderer */ | ||
/* exported CollectionEditor */ | ||
|
||
var CollectionEditor = { | ||
init: function (options) { | ||
this.collection = BaseCollection.create(options.data); | ||
|
||
this.onsaved = options.onsaved; | ||
this.oncancelled = options.oncancelled; | ||
|
||
this.collectionTitle = document.getElementById('collection-title'); | ||
this.collectionTitle.value = this.collection.name || ''; | ||
|
||
this.collectionIcon = document.getElementById('collection-icon'); | ||
this._renderIcon(); | ||
|
||
this.header = document.getElementById('header'); | ||
this.header.addEventListener('action', this.close.bind(this)); | ||
|
||
this.saveButton = document.getElementById('done-button'); | ||
this.saveListener = this.save.bind(this); | ||
this.saveButton.addEventListener('click', this.saveListener); | ||
|
||
this.form = document.querySelector('form'); | ||
this.form.addEventListener('input', this._checkDoneButton.bind(this)); | ||
|
||
this.clearButton = document.getElementById('collection-title-clear'); | ||
this.clearButton.addEventListener('touchstart', | ||
this._clearTitle.bind(this)); | ||
}, | ||
|
||
close: function() { | ||
this.oncancelled(); | ||
}, | ||
|
||
_renderIcon: function() { | ||
var icon = new Icon(this.collectionIcon, this.collection.icon); | ||
icon.render({ | ||
type: GridIconRenderer.TYPE.CLIP | ||
}); | ||
}, | ||
|
||
_clearTitle: function(event) { | ||
event.preventDefault(); | ||
this.collectionTitle.value = ''; | ||
this._checkDoneButton(); | ||
}, | ||
|
||
_checkDoneButton: function() { | ||
// If name field is blank, the “Done” button should be dimmed and inactive | ||
var title = this.collectionTitle.value.trim(); | ||
this.saveButton.disabled = title === ''; | ||
}, | ||
|
||
save: function() { | ||
this.saveButton.removeEventListener('click', this.saveListener); | ||
var newName = this.collectionTitle.value; | ||
this.collection.rename(newName).then(() => this.onsaved()); | ||
} | ||
}; |
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,28 @@ | ||
html, body { | ||
background-color: #f4f4f4; | ||
height: 100%; | ||
} | ||
|
||
body section { | ||
height: 100%; | ||
} | ||
|
||
form { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: calc(100% - 10rem); | ||
padding: 0 1.5rem; | ||
} | ||
|
||
form p { | ||
width: 100%; | ||
} | ||
|
||
#collection-icon { | ||
background-repeat: no-repeat; | ||
background-position: center center; | ||
display: block; | ||
margin-bottom: 2.4rem; | ||
} |
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,125 @@ | ||
'use strict'; | ||
|
||
/* global loadBodyHTML, CollectionEditor, Icon */ | ||
/* global require, suite, suiteTeardown, suiteSetup, test, assert, sinon */ | ||
|
||
require('/shared/test/unit/load_body_html_helper.js'); | ||
require('/shared/elements/gaia_grid/js/grid_icon_renderer.js'); | ||
require('/shared/js/homescreens/icon.js'); | ||
|
||
requireApp('collection/js/common.js'); | ||
requireApp('collection/js/objects.js'); | ||
requireApp('collection/js/update_collection.js'); | ||
|
||
suite('update_collection.js >', function() { | ||
|
||
var name = 'Enjoy', iconRenderStub; | ||
|
||
var collection = { | ||
id: 134, | ||
categoryId: 423, | ||
name: name | ||
}; | ||
|
||
suiteSetup(function() { | ||
loadBodyHTML('/update.html'); | ||
iconRenderStub = sinon.stub(Icon.prototype, 'render', noop); | ||
}); | ||
|
||
suiteTeardown(function() { | ||
document.body.innerHTML = ''; | ||
iconRenderStub.restore(); | ||
}); | ||
|
||
function noop() { | ||
// Do nothing | ||
} | ||
|
||
function dispatchInputEvent() { | ||
CollectionEditor.form.dispatchEvent(new CustomEvent('input')); | ||
} | ||
|
||
suite('UI initialized correctly >', function() { | ||
suiteSetup(function() { | ||
CollectionEditor.init({ | ||
data: collection | ||
}); | ||
}); | ||
|
||
test('The title was defined accordingly >', function() { | ||
assert.equal(CollectionEditor.collectionTitle.value, name); | ||
}); | ||
|
||
test('"done" button is disabled initially', function() { | ||
assert.isTrue(CollectionEditor.saveButton.disabled); | ||
}); | ||
}); | ||
|
||
suite('Checking "done" button >', function() { | ||
|
||
suiteSetup(function() { | ||
CollectionEditor.init({ | ||
data: collection | ||
}); | ||
}); | ||
|
||
test('Typing collection name ', function() { | ||
CollectionEditor.collectionTitle.value = 'Telefonica'; | ||
dispatchInputEvent(); | ||
assert.isFalse(CollectionEditor.saveButton.disabled); | ||
|
||
CollectionEditor.collectionTitle.value = ''; | ||
dispatchInputEvent(); | ||
assert.isTrue(CollectionEditor.saveButton.disabled); | ||
|
||
CollectionEditor.collectionTitle.value = name; | ||
dispatchInputEvent(); | ||
assert.isFalse(CollectionEditor.saveButton.disabled); | ||
}); | ||
|
||
}); | ||
|
||
suite('Checking "close" button >', function() { | ||
|
||
test('Cancelling after clicking "close" button ', function(done) { | ||
CollectionEditor.init({ | ||
data: collection, | ||
oncancelled: function() { | ||
this.oncancelled = noop; | ||
done(); | ||
} | ||
}); | ||
|
||
CollectionEditor.header.dispatchEvent(new CustomEvent('action')); | ||
}); | ||
|
||
}); | ||
|
||
suite('Saving collection with another name >', function() { | ||
var expectedName = 'Games'; | ||
|
||
test('Updated successfully ', function(done) { | ||
CollectionEditor.init({ | ||
data: collection, | ||
onsaved: function() { | ||
this.onsaved = noop; | ||
done(); | ||
} | ||
}); | ||
|
||
sinon.stub(CollectionEditor.collection, 'rename', function(name) { | ||
assert.equal(name, expectedName); | ||
return { | ||
then: function(resolve) { | ||
resolve(); | ||
} | ||
}; | ||
}); | ||
|
||
CollectionEditor.collectionTitle.value = expectedName; | ||
CollectionEditor.saveButton.click(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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
4 changes: 2 additions & 2 deletions
4
apps/bookmark/test/unit/icon_test.js → ...edtest/test/unit/homescreens/icon_test.js
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
Oops, something went wrong.