-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
105 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Button, CardActions, Input } from '@hypothesis/frontend-shared'; | ||
|
||
import { useSidebarStore } from '../../store'; | ||
import LoadingSpinner from './LoadingSpinner'; | ||
|
||
/** | ||
* Render content for "export" tab panel | ||
*/ | ||
export default function ExportAnnotations() { | ||
const store = useSidebarStore(); | ||
const group = store.focusedGroup(); | ||
const exportReady = group && !store.isLoading(); | ||
const annotations = store.allAnnotations(); | ||
|
||
if (!exportReady) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
// TODO: Handle 0 annotations | ||
return ( | ||
<> | ||
<p> | ||
Export <strong>{annotations.length} annotations</strong> in a file | ||
named: | ||
</p> | ||
<Input id="export-filename" value="filename-tbd-export.json" /> | ||
<CardActions> | ||
<Button variant="primary" disabled> | ||
Export | ||
</Button> | ||
</CardActions> | ||
</> | ||
); | ||
} |
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
68 changes: 68 additions & 0 deletions
68
src/sidebar/components/ShareDialog/test/ExportAnnotations-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { mount } from 'enzyme'; | ||
|
||
import { checkAccessibility } from '../../../../test-util/accessibility'; | ||
import { mockImportedComponents } from '../../../../test-util/mock-imported-components'; | ||
import ExportAnnotations from '../ExportAnnotations'; | ||
import { $imports } from '../ExportAnnotations'; | ||
|
||
describe('ExportAnnotations', () => { | ||
let fakeStore; | ||
|
||
const fakePrivateGroup = { | ||
type: 'private', | ||
name: 'Test Private Group', | ||
id: 'testprivate', | ||
}; | ||
|
||
const createComponent = props => mount(<ExportAnnotations {...props} />); | ||
|
||
beforeEach(() => { | ||
fakeStore = { | ||
allAnnotations: sinon.stub().returns(0), | ||
focusedGroup: sinon.stub().returns(fakePrivateGroup), | ||
isLoading: sinon.stub().returns(false), | ||
}; | ||
|
||
$imports.$mock(mockImportedComponents()); | ||
|
||
$imports.$mock({ | ||
'../../store': { useSidebarStore: () => fakeStore }, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
$imports.$restore(); | ||
}); | ||
|
||
context('export annotations not ready', () => { | ||
it('renders a loading spinner if there is no focused group', () => { | ||
fakeStore.focusedGroup.returns(null); | ||
|
||
const wrapper = createComponent(); | ||
|
||
assert.isTrue(wrapper.find('LoadingSpinner').exists()); | ||
}); | ||
|
||
it('renders a loading spinner if annotations are loading', () => { | ||
fakeStore.isLoading.returns(true); | ||
|
||
const wrapper = createComponent(); | ||
|
||
assert.isTrue(wrapper.find('LoadingSpinner').exists()); | ||
}); | ||
}); | ||
|
||
it('provides a filename field', () => { | ||
// TODO expand as component logic is implemented | ||
const wrapper = createComponent(); | ||
|
||
assert.isTrue(wrapper.find('Input').exists()); | ||
}); | ||
|
||
it( | ||
'should pass a11y checks', | ||
checkAccessibility({ | ||
content: () => createComponent(), | ||
}) | ||
); | ||
}); |
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