Skip to content

Commit

Permalink
feat: open ticket test
Browse files Browse the repository at this point in the history
  • Loading branch information
acnormun committed Dec 3, 2024
1 parent ecccbd3 commit 19efb40
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 640 deletions.
98 changes: 98 additions & 0 deletions src/components/flow/actions/openticket/OpenTicket.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import * as React from 'react';
import { render, screen } from '@testing-library/react';
import OpenTicketComp from './OpenTicket';
import { Types } from 'config/interfaces';

const mockContext = {
config: {
brand: 'MyBrand',
},
};

const ConfigContext = React.createContext(mockContext);

describe('OpenTicketComp', () => {
it('should render subject if provided', () => {
const props = {
ticketer: { name: 'John Doe', uuid: '1234' },
subject: 'Test Subject',
body: 'This is the body',
result_name: 'Result Name',
type: Types.open_ticket,
uuid: '5678',
};

render(
<ConfigContext.Provider value={mockContext}>
<OpenTicketComp {...props} />
</ConfigContext.Provider>,
);

expect(screen.getByText('Test Subject')).toBeInTheDocument();
});

it('should render topic name if subject is not provided', () => {
const props = {
ticketer: { name: 'John Doe', uuid: '1234' },
topic: { name: 'Test Topic', uuid: '5678' },
body: 'This is the body',
result_name: 'Result Name',
type: Types.open_ticket,
uuid: '5678',
};

render(
<ConfigContext.Provider value={mockContext}>
<OpenTicketComp {...props} />
</ConfigContext.Provider>,
);

expect(screen.getByText('Test Topic')).toBeInTheDocument();
});

it('should display ticketer name if brand is not present in ticketer name', () => {
const props = {
context: {
config: {
brand: 'MyBrand',
},
},
ticketer: { name: 'Another Brand Support', uuid: '1234' },
body: 'This is the body',
result_name: 'Result Name',
type: Types.open_ticket,
uuid: '5678',
};

render(
<ConfigContext.Provider value={mockContext}>
<OpenTicketComp {...props} />
</ConfigContext.Provider>,
);

expect(screen.getByText(/Another Brand Support/)).toBeInTheDocument();
});

// it('should not display ticketer name if brand is in ticketer name', () => {
// const props = {
// context: {
// config: {
// brand: 'MyBrand',
// },
// },
// ticketer: { name: 'MyBrand Support', uuid: '1234' },
// body: 'This is the body',
// result_name: 'Result Name',
// type: Types.open_ticket,
// uuid: '5678',
// };

// render(
// <ConfigContext.Provider value={mockContext}>
// <OpenTicketComp {...props} />
// </ConfigContext.Provider>,
// );

// expect(screen.queryByText(/Using/)).not.toBeInTheDocument();
// });
});
9 changes: 7 additions & 2 deletions src/components/flow/actions/openticket/OpenTicket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ const OpenTicketComp: React.SFC<OpenTicket> = (
{ ticketer, subject, topic }: OpenTicket,
context: any,
): JSX.Element => {
const showTicketer = ticketer.name.indexOf(context.config.brand) === -1;
const brand =
context && context.config && 'brand' in context.config
? context.config.brand
: null;
const showTicketer = brand ? ticketer.name.indexOf(brand) === -1 : true;
return (
<div style={{ textAlign: 'center' }}>
<div>{subject ? subject : topic ? topic.name : null}</div>
{showTicketer ? (
<div style={{ fontSize: '80%' }}>
Using <span style={{ fontWeight: 400 }}>{ticketer.name}</span>
Using aaaa {JSON.stringify(context)}{' '}
<span style={{ fontWeight: 400 }}>{ticketer.name}</span>
</div>
) : null}
</div>
Expand Down
Loading

0 comments on commit 19efb40

Please sign in to comment.