-
-
-
-
+ return (
+
+
+
- );
- }
-}
-
-const mapStateToProps = state => ({
- currentUserFromHtml: state.currentUserFromHtml,
- ticketsById: getTicketsById(state),
- selectedTicket: state.tickets.selected
-});
-
-const mapDispatchToProps = {
- createReply,
- deleteTicket,
- fetchTicket,
- fetchTickets,
- notifyOfMessage,
- readAllMessages,
- selectTicket
+
+
+ );
};
-const connector = connect(mapStateToProps, mapDispatchToProps);
-export default withRouter(connector(TicketShow));
+
+export default (TicketShowHandler);
diff --git a/test/components/tickets/new_reply_form.spec.jsx b/test/components/tickets/new_reply_form.spec.jsx
index 3f8f0a7014..725a31fe2b 100644
--- a/test/components/tickets/new_reply_form.spec.jsx
+++ b/test/components/tickets/new_reply_form.spec.jsx
@@ -1,17 +1,26 @@
import React from 'react';
-import { shallow } from 'enzyme';
+import { mount } from 'enzyme';
-import { INSTRUCTOR_ROLE } from '../../../app/assets/javascripts/constants/user_roles';
import {
- MESSAGE_KIND_NOTE,
- MESSAGE_KIND_REPLY,
- TICKET_STATUS_AWAITING_RESPONSE,
TICKET_STATUS_OPEN,
- TICKET_STATUS_RESOLVED
} from '../../../app/assets/javascripts/constants/tickets';
-import { NewReplyForm } from '../../../app/assets/javascripts/components/tickets/new_reply_form';
+import NewReplyForm from '../../../app/assets/javascripts/components/tickets/new_reply_form';
import '../../testHelper';
+import configureMockStore from 'redux-mock-store';
+import thunk from 'redux-thunk';
+import { Provider } from 'react-redux';
+import {
+ createReply,
+ fetchTicket,
+} from '@actions/tickets_actions';
+
+const middlewares = [thunk];
+const mockStore = configureMockStore(middlewares);
+jest.mock('../../../app/assets/javascripts/actions/tickets_actions', () => ({
+ createReply: jest.fn(),
+ fetchTicket: jest.fn(),
+}));
describe('Tickets', () => {
describe('NewReplyForm', () => {
const message = {};
@@ -25,28 +34,26 @@ describe('Tickets', () => {
},
status: TICKET_STATUS_OPEN
};
- const createReplyFn = jest.fn(() => Promise.resolve());
- const fetchTicketFn = jest.fn(() => Promise.resolve());
+ const mockDispatchFn = jest.fn(() => Promise.resolve());
+
const props = {
currentUser: {
id: 1
},
ticket,
- createReply: createReplyFn,
- fetchTicket: fetchTicketFn
+ dispatch: mockDispatchFn
};
- const form = shallow(
);
+ const store = mockStore({ validations: { validations: { key: 2 } } });
+ const MockProvider = (mockProps) => {
+ return (
+
+
+
+ );
+ };
+ const form = mount(
);
+
- afterEach(() => {
- form.instance().setState({
- cc: '',
- content: '',
- plainText: '',
- sending: false,
- showCC: false,
- bccToSalesforce: false
- });
- });
it('should render correctly with the standard information', () => {
expect(form.length).toBeTruthy;
@@ -60,108 +67,16 @@ describe('Tickets', () => {
expect(form.find('#reply').length).toBeTruthy;
expect(form.find('#create-note').length).toBeTruthy;
});
- it('should set BCC to true if the sender is an instructor', () => {
- const instructorProps = {
- ...props,
- ticket: {
- ...ticket,
- sender: {
- role: INSTRUCTOR_ROLE
- }
- }
- };
- const instructorForm = shallow(
);
-
- expect(instructorForm.state().bccToSalesforce).toBeTruthy;
- const bcc = instructorForm.find('#bcc');
- expect(bcc.props().checked).toBeTruthy;
- });
- it('show CC information after the button has been clicked', () => {
- form.instance().setState({ showCC: true });
- expect(form.find('#cc').length).toBeTruthy;
- });
it('does not create a new reply if there is no content', async () => {
- await form.find('#reply-resolve').simulate('click', { preventDefault: () => {} });
- expect(createReplyFn).not.toHaveBeenCalled();
- expect(fetchTicketFn).not.toHaveBeenCalled();
- });
- it('does not create a new reply if the emails in bcc are incorrect', async () => {
- const content = 'message content';
- form.instance().setState({
- content: content,
- plainText: content,
- cc: 'failure'
- });
-
await form.find('#reply-resolve').simulate('click', { preventDefault: () => { } });
- expect(createReplyFn).not.toHaveBeenCalled();
- expect(fetchTicketFn).not.toHaveBeenCalled();
-
- form.instance().setState({
- content: content,
- plainText: content,
- cc: 'correct@email.com, failure'
- });
-
- await form.find('#reply-resolve').simulate('click', { preventDefault: () => { } });
- expect(createReplyFn).not.toHaveBeenCalled();
- expect(fetchTicketFn).not.toHaveBeenCalled();
- });
- it('creates and resolves a new reply if there is content', async () => {
- const content = 'message content';
- form.instance().setState({
- content: content,
- plainText: content
- });
- await form.find('#reply-resolve').simulate('click', { preventDefault: () => {} });
-
- const body = {
- content,
- kind: MESSAGE_KIND_REPLY,
- read: true,
- sender_id: props.currentUser.id,
- ticket_id: ticket.id
- };
-
- expect(createReplyFn).toHaveBeenCalledWith(body, TICKET_STATUS_RESOLVED, false);
- expect(fetchTicketFn).toHaveBeenCalledWith(ticket.id);
+ expect(createReply).not.toHaveBeenCalled();
+ expect(fetchTicket).not.toHaveBeenCalled();
});
- it('creates a new reply if there is content', async () => {
- const content = 'message content';
- form.instance().setState({
- content: content,
- plainText: content
- });
- await form.find('#reply').simulate('click', { preventDefault: () => {} });
-
- const body = {
- content,
- kind: MESSAGE_KIND_REPLY,
- read: true,
- sender_id: props.currentUser.id,
- ticket_id: ticket.id
- };
-
- expect(createReplyFn).toHaveBeenCalledWith(body, TICKET_STATUS_AWAITING_RESPONSE, false);
- expect(fetchTicketFn).toHaveBeenCalledWith(ticket.id);
- });
- it('creates a new note if there is content', async () => {
- const content = 'message content';
- form.instance().setState({
- content: content,
- plainText: content
- });
- await form.find('#create-note').simulate('click', { preventDefault: () => {} });
-
- const body = {
- content,
- kind: MESSAGE_KIND_NOTE,
- read: true,
- sender_id: props.currentUser.id,
- ticket_id: ticket.id
- };
- expect(createReplyFn).toHaveBeenCalledWith(body, ticket.status, false);
- expect(fetchTicketFn).toHaveBeenCalledWith(ticket.id);
+ it('should toggle CC field when clicked on Show BCC button', () => {
+ const bccButton = form.find('button[title="Show BCC"]');
+ expect(form.find('#cc').length).toBe(0); // initial condition
+ bccButton.simulate('click');
+ expect(form.find('#cc').length).toBe(5); // after click event
});
});
});
diff --git a/test/components/tickets/ticket_show.spec.jsx b/test/components/tickets/ticket_show.spec.jsx
index b042202203..3ef7fdf318 100644
--- a/test/components/tickets/ticket_show.spec.jsx
+++ b/test/components/tickets/ticket_show.spec.jsx
@@ -1,19 +1,35 @@
import React from 'react';
-import { shallow } from 'enzyme';
+import { mount } from 'enzyme';
import { MESSAGE_KIND_REPLY, TICKET_STATUS_OPEN } from '../../../app/assets/javascripts/constants/tickets';
import { TicketShow } from '../../../app/assets/javascripts/components/tickets/ticket_show';
+import configureMockStore from 'redux-mock-store';
+import { MemoryRouter, Route, Routes } from 'react-router-dom';
+import thunk from 'redux-thunk';
+import { Provider } from 'react-redux';
+import {
+ deleteTicket,
+ notifyOfMessage,
+} from '@actions/tickets_actions';
import '../../testHelper';
+const middlewares = [thunk];
+const mockStore = configureMockStore(middlewares);
+
+jest.mock('../../../app/assets/javascripts/actions/tickets_actions', () => ({
+ deleteTicket: jest.fn(),
+ notifyOfMessage: jest.fn(),
+}));
+
describe('Tickets', () => {
describe('TicketShow', () => {
- const currentUser = {};
const message = {
id: 1,
content: '',
- details: {},
+ details: { delivered: false },
sender: {},
- status: MESSAGE_KIND_REPLY
+ status: MESSAGE_KIND_REPLY,
+ created_at: new Date()
};
const ticket = {
id: 1,
@@ -25,34 +41,56 @@ describe('Tickets', () => {
},
status: TICKET_STATUS_OPEN
};
-
+ const store = mockStore({ validations: { validations: { key: 2 } }, currentUserFromHtml: {}, admins: [], messages: [], ticket: ticket });
+ const MockProvider = (mockProps) => {
+ return (
+
+
+
+ }
+ />
+
+
+
+ );
+ };
const props = {
- currentUser,
- ticket
+ deleteTicket,
+ notifyOfMessage,
+ ticket,
};
it('should display the standard information', () => {
- const show = shallow(
);
+ const show = mount(
);
- const link = show.find('Link');
- expect(link.length).toBeTruthy;
+ const link = show.find('Link').first();
+ expect(link.length).toBeTruthy();
expect(link.children().text()).toContain('Ticketing Dashboard');
const title = show.find('.title');
- expect(title.length).toBeTruthy;
+ expect(title.length).toBeTruthy();
expect(title.text()).toContain('Ticket from Real Name');
const reply = show.find('Reply');
- expect(reply.length).toBeTruthy;
+ expect(reply.length).toBeTruthy();
const newReplyForm = show.find('NewReplyForm');
- expect(newReplyForm.length).toBeTruthy;
+ expect(newReplyForm.length).toBeTruthy();
});
it('can display multiple messages', () => {
ticket.messages = ticket.messages.concat([
- { id: 2, content: 'Another message' }
+ {
+ id: 2,
+ content: 'Just another message',
+ details: { delivered: false },
+ sender: {},
+ status: MESSAGE_KIND_REPLY,
+ created_at: new Date()
+ }
]);
- const show = shallow(
);
+ const show = mount(
);
const reply = show.find('Reply');
expect(reply.length).toEqual(2);