Skip to content

Instantly share code, notes, and snippets.

@ralfting
Last active April 21, 2021 21:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralfting/17764277e56f77e54204bd0cdf2192da to your computer and use it in GitHub Desktop.
Save ralfting/17764277e56f77e54204bd0cdf2192da to your computer and use it in GitHub Desktop.
describe('EditFieldContainer', () => {
let utils;
describe('user has permission to edit', () => {
beforeEach(() => {
utils = render(
<div data-testId="outside">
<MockedProvider mocks={{}} addTypename={false}>
<EditFieldContainer {...props} />
</MockedProvider>
</div>
);
});
it('doesn\'t show input in initial state', () => {
expect(utils.container.querySelector('input')).toBeFalsy();
})
it('shows edit field when click', () => {
fireEvent.click(utils.getByTestId('edit-field-container-id'));
expect(utils.container.querySelector('input')).toBeTruthy();
});
it('returns a ready-only when click outside', () => {
fireEvent.click(utils.getByTestId('edit-field-container-id'));
fireEvent.mouseDown(utils.getByTestId('outside'));
expect(utils.container.querySelector('input')).toBeFalsy();
});
});
describe('user has not permission to edit', () => {
it('edit button is hidden', () => {
const { container } = render(
<MockedProvider mocks={{}} addTypename={false}>
<EditFieldContainer {...props} permissions={{ edit: false }} />
</MockedProvider>
);
expect(container.querySelector('[data-testid="edit-field-container-id"]')).toBeNull();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment