Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion final/client/src/components/__tests__/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ describe('Button', () => {
afterEach(cleanup);

it('renders without error', () => {
render(<Button>Hello World</Button>);
const wrapper = render(<Button>Hello World</Button>);
});
});
33 changes: 22 additions & 11 deletions final/client/src/containers/__tests__/action-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,39 @@ import React from 'react';
import { renderApollo, cleanup } from '../../test-utils';
import ActionButton from '../action-button';
import { cartItemsVar } from '../../cache';
import {render, shallow} from "../../enzyme";
import Button from "../../components/button";
import {ApolloProvider, useApolloClient} from "@apollo/client";

describe('action button', () => {
// automatically unmount and cleanup DOM after the test is finished.
afterEach(cleanup);

it('renders without error', () => {
const { getByTestId } = renderApollo(<ActionButton />);
expect(getByTestId('action-button')).toBeTruthy();
render(<ActionButton/>);
});

it('shows correct label', () => {
const { getByText, container } = renderApollo(<ActionButton />);
getByText(/add to cart/i);
it('empty cart correct label', () => {
const wrapper = render(<ActionButton/>);
const button = wrapper.find('div button');

expect(wrapper.find('div button').text()).toBe('Add to Cart');
});

it('populated cart correct label', () => {

// rerender with different props to same container
cartItemsVar(['1']);
renderApollo(<ActionButton id="1" />, { container });
getByText(/remove from cart/i);
cartItemsVar([]);
const wrapper = render(<ActionButton id="1"/>);
const button = wrapper.find('div button');

// rerender with different props to same container
renderApollo(<ActionButton isBooked={true} />, { container });
expect(button.text()).toBe('Remove from Cart');
});

it('booked trip correct label', () => {
const { getByText, container } = renderApollo(<ActionButton />);

renderApollo(<ActionButton isBooked={true}/>, { container });
getByText(/cancel this trip/i);
});

});