adastra-ui-comment
Version:
Testing locally 1) in this file - `npm i` install dependencies - `npm run build` or `npm run tsc` to build your module 2) in childApp - in package.json under dependencies add ui-astra-assets with file:(relativePathToRepo) - "ui-astra-a
87 lines • 2.73 kB
JavaScript
import { CommentsSection, } from 'CommentSection';
describe('CommentSection', () => {
const commentProps = {
comments: [],
users: [],
threadId: '',
};
const state = {
users: [],
comments: [],
focused: false,
newNotificaitonValue: '',
userSearch: false,
};
let props;
beforeAll(() => {
props = Object.assign({}, commentProps);
props.setThreadId = jest.fn();
props.createComment = jest.fn();
props.fetchUsers = jest.fn();
});
afterAll(() => {
});
it('should render the component', () => {
});
it('should create comment after hitting enter', () => {
const firstEvent = {
keyCode: 13,
};
const comments = new CommentsSection(props);
comments['checkEnter'](firstEvent);
expect(props.createComment)
.toHaveBeenCalledWith({
comment_text: '',
thread_id: 'courseCode_termCode',
source_url: '/',
thread_name: 'subject courseNumber',
});
});
it('should grab users after typing @', () => {
const secondEvent = {
target: {
value: '@',
},
};
const comments = new CommentsSection(props);
comments.state = state;
comments.setState = jest.fn();
comments['updateComment'](secondEvent);
expect(comments.setState)
.toHaveBeenCalledWith({
newNotificaitonValue: '@',
});
expect(props.fetchUsers)
.toHaveBeenCalled();
});
it('should update message value on change', () => {
const firstEvent = {
target: {
value: 'something',
},
};
const comments = new CommentsSection(props);
comments.setState = jest.fn();
comments['updateComment'](firstEvent);
expect(comments.setState)
.toHaveBeenCalledWith({
newNotificaitonValue: 'something',
});
});
it('should handleBlur', () => {
const comments = new CommentsSection(props);
comments.setState = jest.fn();
comments.handleBlur();
expect(comments.setState).toBeCalledWith({ focused: false });
});
it('should scrollDown', () => {
document.getElementById = jest.fn().mockReturnValue({ offsetTop: 1 });
const comments = new CommentsSection(props);
comments.setState = jest.fn();
comments.scrollDown();
expect(comments.setState).toBeCalledWith({ focused: true });
});
it('should map dispatch actions to properties', () => {
});
});
//# sourceMappingURL=index.test.js.map