Commit bfcc3543 authored by Kyle Keating's avatar Kyle Keating

Improve test coverage

parent 7c2eea8e
......@@ -28,10 +28,11 @@ function SearchStatusBar({ rootThread }) {
selectedAnnotationMap,
selectedTab,
} = useStore(store => ({
directLinkedGroupFetchFailed: store.getState().directLinkedGroupFetchFailed,
filterQuery: store.getState().filterQuery,
selectedAnnotationMap: store.getState().selectedAnnotationMap,
selectedTab: store.getState().selectedTab,
directLinkedGroupFetchFailed: store.getRootState().directLinked
.directLinkedGroupFetchFailed,
filterQuery: store.getRootState().selection.filterQuery,
selectedAnnotationMap: store.getRootState().selection.selectedAnnotationMap,
selectedTab: store.getRootState().selection.selectedTab,
}));
const clearSelection = useStore(store => store.clearSelection);
const filterActive = !!filterQuery;
......
......@@ -70,7 +70,9 @@ Tab.propTypes = {
*/
function SelectionTabs({ isLoading, settings, session }) {
const selectedTab = useStore(store => store.getState().selectedTab);
const selectedTab = useStore(
store => store.getRootState().selection.selectedTab
);
const noteCount = useStore(store => store.noteCount());
const annotationCount = useStore(store => store.annotationCount());
const orphanCount = useStore(store => store.orphanCount());
......
......@@ -21,7 +21,10 @@ describe('SearchStatusBar', () => {
};
fakeStore = {
getState: sinon.stub(),
getRootState: sinon.stub(),
getRootState: sinon.stub().returns({
selection: {},
directLinked: {},
}),
annotationCount: sinon.stub().returns(1),
noteCount: sinon.stub().returns(0),
};
......@@ -92,9 +95,14 @@ describe('SearchStatusBar', () => {
fakeRootThread.thread.returns({
children: test.children,
});
fakeStore.getState.returns({
filterQuery: 'tag:foo',
selectedTab: 'annotation',
fakeStore.getRootState.returns({
selection: {
filterQuery: 'tag:foo',
selectedTab: 'annotation',
},
directLinked: {
directLinkedGroupFetchFailed: false,
},
});
fakeStore.annotationCount.returns(3);
......@@ -109,11 +117,13 @@ describe('SearchStatusBar', () => {
});
it('displays "Show all annotations" button when a direct-linked group fetch fails', () => {
fakeStore.getState.returns({
filterQuery: null,
directLinkedGroupFetchFailed: true,
selectedAnnotationMap: { annId: true },
selectedTab: 'annotation',
fakeStore.getRootState.returns({
selection: {
filterQuery: null,
selectedAnnotationMap: { annId: true },
selectedTab: 'annotation',
},
directLinked: {},
});
const wrapper = createComponent({});
......@@ -123,11 +133,15 @@ describe('SearchStatusBar', () => {
});
it('displays "Show all annotations" button when there are selected annotations', () => {
fakeStore.getState.returns({
filterQuery: null,
directLinkedGroupFetchFailed: false,
selectedAnnotationMap: { annId: true },
selectedTab: 'annotation',
fakeStore.getRootState.returns({
selection: {
filterQuery: null,
selectedAnnotationMap: { annId: true },
selectedTab: 'annotation',
},
directLinked: {
directLinkedGroupFetchFailed: false,
},
});
const wrapper = createComponent({});
......@@ -138,11 +152,15 @@ describe('SearchStatusBar', () => {
[null, {}].forEach(selectedAnnotationMap => {
it('does not display "Show all annotations" button when there are no selected annotations', () => {
fakeStore.getState.returns({
filterQuery: null,
directLinkedGroupFetchFailed: false,
selectedAnnotationMap: selectedAnnotationMap,
selectedTab: 'annotation',
fakeStore.getRootState.returns({
selection: {
filterQuery: null,
selectedAnnotationMap: selectedAnnotationMap,
selectedTab: 'annotation',
},
directLinked: {
directLinkedGroupFetchFailed: false,
},
});
const wrapper = createComponent({});
......@@ -187,11 +205,15 @@ describe('SearchStatusBar', () => {
},
].forEach(test => {
it(test.description, () => {
fakeStore.getState.returns({
filterQuery: null,
directLinkedGroupFetchFailed: false,
selectedAnnotationMap: { annId: true },
selectedTab: test.selectedTab,
fakeStore.getRootState.returns({
selection: {
filterQuery: null,
selectedAnnotationMap: { annId: true },
selectedTab: test.selectedTab,
},
directLinked: {
directLinkedGroupFetchFailed: false,
},
});
fakeStore.noteCount.returns(test.totalNotes);
fakeStore.annotationCount.returns(test.totalAnnotations);
......
......@@ -63,9 +63,11 @@ describe('SelectionTabs', function() {
noteCount: sinon.stub().returns(456),
orphanCount: sinon.stub().returns(0),
isWaitingToAnchorAnnotations: sinon.stub().returns(false),
getState: sinon
.stub()
.returns({ selectedTab: uiConstants.TAB_ANNOTATIONS }),
getRootState: sinon.stub().returns({
selection: {
selectedTab: uiConstants.TAB_ANNOTATIONS,
},
}),
};
});
......@@ -101,14 +103,18 @@ describe('SelectionTabs', function() {
});
it('should display notes tab as selected', function() {
fakeStore.getState.returns({ selectedTab: uiConstants.TAB_NOTES });
fakeStore.getRootState.returns({
selection: { selectedTab: uiConstants.TAB_NOTES },
});
const wrapper = createDeepComponent({});
const tabs = wrapper.find('a');
assert.isTrue(tabs.at(1).hasClass('is-selected'));
});
it('should display orphans tab as selected if there is 1 or more orphans', function() {
fakeStore.getState.returns({ selectedTab: uiConstants.TAB_ORPHANS });
fakeStore.getRootState.returns({
selection: { selectedTab: uiConstants.TAB_ORPHANS },
});
fakeStore.orphanCount.returns(1);
const wrapper = createDeepComponent({});
const tabs = wrapper.find('a');
......@@ -116,7 +122,9 @@ describe('SelectionTabs', function() {
});
it('should not display orphans tab if there are 0 orphans', function() {
fakeStore.getState.returns({ selectedTab: uiConstants.TAB_ORPHANS });
fakeStore.getRootState.returns({
selection: { selectedTab: uiConstants.TAB_ORPHANS },
});
const wrapper = createDeepComponent({});
const tabs = wrapper.find('a');
assert.equal(tabs.length, 2);
......@@ -139,14 +147,18 @@ describe('SelectionTabs', function() {
});
it('should not display the new-note-btn when the notes tab is active and the new-note-btn is disabled', function() {
fakeStore.getState.returns({ selectedTab: uiConstants.TAB_NOTES });
fakeStore.getRootState.returns({
selection: { selectedTab: uiConstants.TAB_NOTES },
});
const wrapper = createComponent({});
assert.equal(wrapper.find(NewNoteBtn).length, 0);
});
it('should display the new-note-btn when the notes tab is active and the new-note-btn is enabled', function() {
fakeSettings.enableExperimentalNewNoteButton = true;
fakeStore.getState.returns({ selectedTab: uiConstants.TAB_NOTES });
fakeStore.getRootState.returns({
selection: { selectedTab: uiConstants.TAB_NOTES },
});
const wrapper = createComponent({});
assert.equal(wrapper.find(NewNoteBtn).length, 1);
});
......@@ -160,7 +172,9 @@ describe('SelectionTabs', function() {
});
it('should not display a message when its loading notes count is 0', function() {
fakeStore.getState.returns({ selectedTab: uiConstants.TAB_NOTES });
fakeStore.getRootState.returns({
selection: { selectedTab: uiConstants.TAB_NOTES },
});
fakeStore.noteCount.returns(0);
const wrapper = createComponent({
isLoading: true,
......@@ -178,7 +192,9 @@ describe('SelectionTabs', function() {
});
it('should display the longer version of the no notes message when there are no notes', function() {
fakeStore.getState.returns({ selectedTab: uiConstants.TAB_NOTES });
fakeStore.getRootState.returns({
selection: { selectedTab: uiConstants.TAB_NOTES },
});
fakeStore.noteCount.returns(0);
const wrapper = createComponent({});
assert.include(
......@@ -189,7 +205,9 @@ describe('SelectionTabs', function() {
it('should display the prompt to create a note when there are no notes and enableExperimentalNewNoteButton is true', function() {
fakeSettings.enableExperimentalNewNoteButton = true;
fakeStore.getState.returns({ selectedTab: uiConstants.TAB_NOTES });
fakeStore.getRootState.returns({
selection: { selectedTab: uiConstants.TAB_NOTES },
});
fakeStore.noteCount.returns(0);
const wrapper = createComponent({});
assert.include(
......@@ -224,7 +242,9 @@ describe('SelectionTabs', function() {
context('when the sidebar tutorial is displayed', function() {
it('should display the shorter version of the no notes message when there are no notes', function() {
fakeSession.state.preferences.show_sidebar_tutorial = true;
fakeStore.getState.returns({ selectedTab: uiConstants.TAB_NOTES });
fakeStore.getRootState.returns({
selection: { selectedTab: uiConstants.TAB_NOTES },
});
fakeStore.noteCount.returns(0);
const wrapper = createComponent({});
......
......@@ -46,11 +46,7 @@ describe('rootThread', function() {
focusedAnnotationMap: null,
forceVisible: {},
highlighted: [],
selectedAnnotationMap: null,
session: {
features: {},
},
sortKey: 'Location',
sortKeysAvailable: ['Location'],
},
......@@ -301,6 +297,13 @@ describe('rootThread', function() {
// pages, since we show all types of annotations here
assert.notOk(threadFilterFn);
});
it('filter returns false when no annotations are provided', function() {
fakeBuildThread.reset();
rootThread.thread(fakeStore.state);
const threadFilterFn = fakeBuildThread.args[0][1].threadFilterFn;
assert.isFalse(threadFilterFn({}));
});
});
describe('when the filter query changes', function() {
......
......@@ -80,6 +80,17 @@ describe('store/modules/selection', () => {
});
});
describe('filterQuery', function() {
it('returns the filterQuery value when provided', function() {
store.setFilterQuery('tag:foo');
assert.equal(store.filterQuery(), 'tag:foo');
});
it('returns null when no filterQuery is present', function() {
assert.isNull(store.filterQuery());
});
});
describe('isAnnotationSelected', function() {
it('returns true if the id provided is selected', function() {
store.selectAnnotations([1]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment