Skip to content

Commit

Permalink
add unit tests for delete component
Browse files Browse the repository at this point in the history
  • Loading branch information
saleem-hadad committed Apr 19, 2022
1 parent e340361 commit 4c9efc7
Show file tree
Hide file tree
Showing 8 changed files with 86,093 additions and 8 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"autoprefixer": "^10.2.4",
"axios": "^0.21",
"babel-jest": "^27.5.1",
"intersection-observer": "^0.12.0",
"jest": "^27.5.1",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
Expand Down
2,055 changes: 2,054 additions & 1 deletion public/css/app.css

Large diffs are not rendered by default.

83,999 changes: 83,997 additions & 2 deletions public/js/app.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=d568a6eec836e363b080",
"/css/app.css": "/css/app.css?id=cc6bd40c496f6f04d2c0"
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css"
}
4 changes: 2 additions & 2 deletions resources/js/Components/Global/Delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Dialog, Transition } from '@headlessui/react'
import { ExclamationIcon } from '@heroicons/react/outline'

export default function Delete({item, resource, onClose, onDelete}) {
const cancelButtonRef = useRef(null)
const cancelButtonRef = useRef()

const deleteItem = () => {
Api.delete({id: item.id, resource: resource})
Expand Down Expand Up @@ -50,7 +50,7 @@ export default function Delete({item, resource, onClose, onDelete}) {
Delete Resource
</Dialog.Title>
<div className="mt-2">
<p className="text-sm text-gray-500">
<p data-testid="delete-warning" className="text-sm text-gray-500">
Are you sure you want to delete this resource?
</p>
</div>
Expand Down
31 changes: 31 additions & 0 deletions resources/js/Components/Global/__tests__/Delete.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react'
import { cleanup, screen, render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import 'intersection-observer';

import Delete from '../Delete';

afterEach(cleanup);

it('If item not passed then delete popup will not be shown', () => {
render(<Delete />);

expect(screen.queryByTestId('delete-warning')).toBeNull
});

it('If item passed then delete popup will be shown', () => {
render(<Delete item={{id: 1}} onClose={() => {}} />);

expect(screen.getByTestId('delete-warning')).toBeVisible()
expect(screen.getByText('Delete')).toBeVisible()
expect(screen.getByText('Cancel')).toBeVisible()
});

it('If cancel is pressed then onClose is triggered', () => {
const callback = jest.fn();
render(<Delete item={{id: 1}} onClose={callback} />);

fireEvent.click(screen.getByText('Cancel'))

expect(callback).toHaveBeenCalled()
});
1 change: 0 additions & 1 deletion resources/js/Pages/Brand/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export default function Edit({categories, brand, onClose, onUpdate}) {
Update
</button>
}

</div>
</div>
}
Expand Down

0 comments on commit 4c9efc7

Please sign in to comment.