-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show the shorter version of the empty annotations/notes message when … #611
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,17 @@ var angular = require('angular'); | |
var util = require('../../directive/test/util'); | ||
|
||
describe('selectionTabs', function () { | ||
var fakeSession = { | ||
state: { | ||
preferences: { | ||
show_sidebar_tutorial: false, | ||
}, | ||
}, | ||
}; | ||
var fakeSettings = { | ||
enableExperimentalNewNoteButton: false, | ||
}; | ||
|
||
before(function () { | ||
angular.module('app', []) | ||
.component('selectionTabs', require('../selection-tabs')); | ||
|
@@ -15,13 +26,11 @@ describe('selectionTabs', function () { | |
var fakeFeatures = { | ||
flagEnabled: sinon.stub().returns(true), | ||
}; | ||
var fakeSettings = { | ||
enableExperimentalNewNoteButton: true, | ||
}; | ||
|
||
angular.mock.module('app', { | ||
annotationUI: fakeAnnotationUI, | ||
features: fakeFeatures, | ||
session: fakeSession, | ||
settings: fakeSettings, | ||
}); | ||
}); | ||
|
@@ -33,7 +42,6 @@ describe('selectionTabs', function () { | |
totalAnnotations: '123', | ||
totalNotes: '456', | ||
}); | ||
|
||
var tabs = elem[0].querySelectorAll('a'); | ||
|
||
assert.include(tabs[0].textContent, 'Annotations'); | ||
|
@@ -48,8 +56,8 @@ describe('selectionTabs', function () { | |
totalAnnotations: '123', | ||
totalNotes: '456', | ||
}); | ||
|
||
var tabs = elem[0].querySelectorAll('a'); | ||
|
||
assert.isTrue(tabs[0].classList.contains('is-selected')); | ||
}); | ||
|
||
|
@@ -59,8 +67,8 @@ describe('selectionTabs', function () { | |
totalAnnotations: '123', | ||
totalNotes: '456', | ||
}); | ||
|
||
var tabs = elem[0].querySelectorAll('a'); | ||
|
||
assert.isTrue(tabs[1].classList.contains('is-selected')); | ||
}); | ||
|
||
|
@@ -70,6 +78,7 @@ describe('selectionTabs', function () { | |
totalAnnotations: '123', | ||
totalNotes: '456', | ||
}); | ||
|
||
assert.isFalse(elem[0].querySelectorAll('.selection-tabs')[0].classList.contains('selection-tabs--theme-clean')); | ||
}); | ||
|
||
|
@@ -87,28 +96,108 @@ describe('selectionTabs', function () { | |
totalAnnotations: '123', | ||
totalNotes: '456', | ||
}); | ||
|
||
assert.isTrue(elem[0].querySelectorAll('.selection-tabs')[0].classList.contains('selection-tabs--theme-clean')); | ||
}); | ||
|
||
it('should display the new note button when the notes tab is active', function () { | ||
it('should not display the new new note button when the annotations tab is active', function () { | ||
var elem = util.createDirective(document, 'selectionTabs', { | ||
selectedTab: 'note', | ||
selectedTab: 'annotation', | ||
totalAnnotations: '123', | ||
totalNotes: '456', | ||
}); | ||
var newNoteElem = elem[0].querySelectorAll('new-note-btn'); | ||
assert.equal(newNoteElem.length, 1); | ||
|
||
assert.equal(newNoteElem.length, 0); | ||
}); | ||
|
||
it('should not display the new new note button when the annotations tab is active', function () { | ||
it('should not display the new note button when the notes tab is active and the new note button is disabled', function () { | ||
var elem = util.createDirective(document, 'selectionTabs', { | ||
selectedTab: 'annotation', | ||
selectedTab: 'note', | ||
totalAnnotations: '123', | ||
totalNotes: '456', | ||
}); | ||
|
||
var newNoteElem = elem[0].querySelectorAll('new-note-btn'); | ||
|
||
assert.equal(newNoteElem.length, 0); | ||
}); | ||
|
||
it('should display the new note button when the notes tab is active and the new note button is enabled', function () { | ||
fakeSettings.enableExperimentalNewNoteButton = true; | ||
var elem = util.createDirective(document, 'selectionTabs', { | ||
selectedTab: 'note', | ||
totalAnnotations: '123', | ||
totalNotes: '456', | ||
}); | ||
var newNoteElem = elem[0].querySelectorAll('new-note-btn'); | ||
|
||
assert.equal(newNoteElem.length, 1); | ||
}); | ||
|
||
it('should display the longer version of the no notes message when there are no notes', function () { | ||
fakeSession.state.preferences.show_sidebar_tutorial = false; | ||
fakeSettings.enableExperimentalNewNoteButton = false; | ||
|
||
var elem = util.createDirective(document, 'selectionTabs', { | ||
selectedTab: 'note', | ||
totalAnnotations: '10', | ||
totalNotes: 0, | ||
}); | ||
var unavailableMsg = elem[0].querySelector('.annotation-unavailable-message__label'); | ||
var unavailableTutorial = elem[0].querySelector('.annotation-unavailable-message__tutorial'); | ||
var noteIcon = unavailableTutorial.querySelector('i'); | ||
|
||
assert.include(unavailableMsg.textContent, 'There are no page notes in this group.'); | ||
assert.include(unavailableTutorial.textContent, 'Create one by clicking the'); | ||
assert.isTrue(noteIcon.classList.contains('h-icon-note')); | ||
}); | ||
|
||
it('should display the longer version of the no annotations message when there are no annotations', function () { | ||
fakeSession.state.preferences.show_sidebar_tutorial = false; | ||
fakeSettings.enableExperimentalNewNoteButton = false; | ||
|
||
var elem = util.createDirective(document, 'selectionTabs', { | ||
selectedTab: 'annotation', | ||
totalAnnotations: 0, | ||
totalNotes: '10', | ||
}); | ||
var unavailableMsg = elem[0].querySelector('.annotation-unavailable-message__label'); | ||
var unavailableTutorial = elem[0].querySelector('.annotation-unavailable-message__tutorial'); | ||
var noteIcon = unavailableTutorial.querySelector('i'); | ||
|
||
assert.include(unavailableMsg.textContent, 'There are no annotations in this group.'); | ||
assert.include(unavailableTutorial.textContent, 'Create one by selecting some text and clicking the'); | ||
assert.isTrue(noteIcon.classList.contains('h-icon-annotate')); | ||
}); | ||
|
||
context('when the sidebar tutorial is displayed', function () { | ||
fakeSession.state.preferences.show_sidebar_tutorial = true; | ||
|
||
it('should display the shorter version of the no notes message when there are no notes', function () { | ||
var elem = util.createDirective(document, 'selectionTabs', { | ||
selectedTab: 'note', | ||
totalAnnotations: '10', | ||
totalNotes: 0, | ||
}); | ||
var msg = elem[0].querySelector('.annotation-unavailable-message__label'); | ||
|
||
assert.include(msg.textContent, 'There are no page notes in this group.'); | ||
assert.notInclude(msg.textContent, 'Create one by clicking the'); | ||
assert.notInclude(msg.textContent, 'Create one by selecting some text and clicking the'); | ||
}); | ||
|
||
it('should display the shorter version of the no annotations message when there are no annotations', function () { | ||
var elem = util.createDirective(document, 'selectionTabs', { | ||
selectedTab: 'annotation', | ||
totalAnnotations: 0, | ||
totalNotes: '10', | ||
}); | ||
var msg = elem[0].querySelector('.annotation-unavailable-message__label'); | ||
|
||
assert.include(msg.textContent, 'There are no annotations in this group.'); | ||
assert.notInclude(msg.textContent, 'Create one by clicking the'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this line is a mistake as well, since "Create one by clicking the" is only shown in the notes tab. Just as a suggestion, it might save a few lines and make the tests more readable to extract out the logic for querying the DOM into a helper function which returns some value to indicate the displayed message that you can then test for. Alternatively if the template "logic" is very simple (eg. hiding/showing different elements depending on some controller methods which return a boolean) you can might be able to get away with just testing the controller method's output in different cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed this on Slack. This is a check to make sure that the annotations-related message is not showing. |
||
assert.notInclude(msg.textContent, 'Create one by selecting some text and clicking the'); | ||
}); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Returns true if the sidebar tutorial has to be shown to a user for a given session. | ||
*/ | ||
function shouldShowSidebarTutorial(sessionState) { | ||
if (sessionState.preferences.show_sidebar_tutorial) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
module.exports = { | ||
shouldShowSidebarTutorial: shouldShowSidebarTutorial, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
var sessionUtil = require('../session-util'); | ||
|
||
describe('sessionUtil.shouldShowSidebarTutorial', function () { | ||
it('shows sidebar tutorial if the settings object has the show_sidebar_tutorial key set', function () { | ||
var sessionState = { | ||
preferences: { | ||
show_sidebar_tutorial: true, | ||
}, | ||
}; | ||
|
||
assert.isTrue(sessionUtil.shouldShowSidebarTutorial(sessionState)); | ||
}); | ||
|
||
it('hides sidebar tutorial if the settings object does not have the show_sidebar_tutorial key set', function () { | ||
var sessionState = { | ||
preferences: { | ||
show_sidebar_tutorial: false, | ||
}, | ||
}; | ||
|
||
assert.isFalse(sessionUtil.shouldShowSidebarTutorial(sessionState)); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line was included by mistake? You never need to select text to create a note.