Skip to content

Commit

Permalink
chore: Remove duplicated tests (#2686)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-boris authored Sep 10, 2024
1 parent 9c17527 commit a78c2ff
Showing 1 changed file with 4 additions and 125 deletions.
129 changes: 4 additions & 125 deletions src/flashbar/__tests__/flashbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,10 @@ describe('Analytics', () => {
);
});

it('sends a render metric when items are provided', () => {
it('sends a render metric when stacked items are provided', () => {
createFlashbarWrapper(
<Flashbar
{...{ stackItems: true }}
stackItems={true}
items={[
{ type: 'error', header: 'Error', content: 'There was an error' },
{ type: 'success', header: 'Success', content: 'Everything went fine' },
Expand Down Expand Up @@ -522,7 +522,7 @@ describe('Analytics', () => {
it('sends an expand metric when collapsed', () => {
const wrapper = createFlashbarWrapper(
<Flashbar
{...{ stackItems: true }}
stackItems={true}
items={[
{ type: 'error', header: 'Error', content: 'There was an error' },
{ type: 'success', header: 'Success', content: 'Everything went fine' },
Expand All @@ -548,7 +548,7 @@ describe('Analytics', () => {
it('sends a collapse metric when collapsed', () => {
const wrapper = createFlashbarWrapper(
<Flashbar
{...{ stackItems: true }}
stackItems={true}
items={[
{ type: 'error', header: 'Error', content: 'There was an error' },
{ type: 'success', header: 'Success', content: 'Everything went fine' },
Expand All @@ -570,75 +570,6 @@ describe('Analytics', () => {
})
);
});
});

describe('Analytics', () => {
beforeEach(() => {
window.panorama = () => {};
jest.spyOn(window, 'panorama');
});
it('does not send a metric when an empty array is provided', () => {
createFlashbarWrapper(<Flashbar items={[]} />);
expect(window.panorama).toBeCalledTimes(0);
});

it('sends a render metric when items are provided', () => {
createFlashbarWrapper(
<Flashbar
items={[
{ type: 'error', header: 'Error', content: 'There was an error' },
{ type: 'success', header: 'Success', content: 'Everything went fine' },
]}
/>
);

expect(window.panorama).toBeCalledTimes(1);
expect(window.panorama).toHaveBeenCalledWith(
'trackCustomEvent',
expect.objectContaining({
eventContext: 'csa_flashbar',
eventType: 'render',
eventValue: '2',
eventDetail: expect.any(String),
timestamp: expect.any(Number),
})
);
});

it('sends a render metric when items are provided', () => {
createFlashbarWrapper(
<Flashbar
{...{ stackItems: true }}
items={[
{ type: 'error', header: 'Error', content: 'There was an error' },
{ type: 'success', header: 'Success', content: 'Everything went fine' },
]}
/>
);

expect(window.panorama).toBeCalledTimes(1);
expect(window.panorama).toHaveBeenCalledWith(
'trackCustomEvent',
expect.objectContaining({
eventContext: 'csa_flashbar',
eventType: 'render',
eventValue: '2',
eventDetail: expect.any(String),
timestamp: expect.any(Number),
})
);
});

it('does not send duplicate render metrics on multiple renders', () => {
const items: FlashbarProps['items'] = [
{ type: 'error', header: 'Error', content: 'There was an error' },
{ type: 'success', header: 'Success', content: 'Everything went fine' },
];

const { rerender } = reactRender(<Flashbar items={items} />);
rerender(<Flashbar items={items} />);
expect(window.panorama).toBeCalledTimes(1);
});

it('sends a dismiss metric when a flash item is dismissed', () => {
const wrapper = createFlashbarWrapper(
Expand All @@ -659,58 +590,6 @@ describe('Analytics', () => {
);
});

it('sends an expand metric when collapsed', () => {
const wrapper = createFlashbarWrapper(
<Flashbar
{...{ stackItems: true }}
items={[
{ type: 'error', header: 'Error', content: 'There was an error' },
{ type: 'success', header: 'Success', content: 'Everything went fine' },
]}
/>
);
window.panorama?.mockClear(); // clear render event

wrapper.find(toggleButtonSelector)!.click();

expect(window.panorama).toBeCalledTimes(1);
expect(window.panorama).toHaveBeenCalledWith(
'trackCustomEvent',
expect.objectContaining({
eventContext: 'csa_flashbar',
eventType: 'expand',
eventValue: '2',
timestamp: expect.any(Number),
})
);
});

it('sends a collapse metric when collapsed', () => {
const wrapper = createFlashbarWrapper(
<Flashbar
{...{ stackItems: true }}
items={[
{ type: 'error', header: 'Error', content: 'There was an error' },
{ type: 'success', header: 'Success', content: 'Everything went fine' },
]}
/>
);
wrapper.find(toggleButtonSelector)!.click(); // expand
window.panorama?.mockClear(); // clear previous events

wrapper.find(toggleButtonSelector)!.click(); // collapse
expect(window.panorama).toBeCalledTimes(1);
expect(window.panorama).toHaveBeenCalledWith(
'trackCustomEvent',
expect.objectContaining({
eventContext: 'csa_flashbar',
eventType: 'collapse',
eventValue: '2',
timestamp: expect.any(Number),
})
);
});

describe('analytics', () => {
test(`adds ${DATA_ATTR_ANALYTICS_FLASHBAR} attribute with the flashbar type`, () => {
const { container } = reactRender(<Flashbar items={[{ id: '0', type: 'success' }]} />);
Expand Down

0 comments on commit a78c2ff

Please sign in to comment.