-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: increase coverage to 100% (#91)
* feat: improve tests * feat: increase coverage to 100% * fix: add typscript parser * feat: add codecov report Co-authored-by: Adrián Insua Yañez <[email protected]>
- Loading branch information
1 parent
1cba82b
commit c566240
Showing
39 changed files
with
2,460 additions
and
232 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,110 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import App from './App'; | ||
import { setup } from './global/utils/tests/store.mock'; | ||
import { getMockProvider } from './global/utils/tests/store.mock'; | ||
import * as service from './service/neo.service'; | ||
import actions from './global/utils/store/actions'; | ||
import { Cookies } from 'react-cookie'; | ||
import { cleanup } from '@testing-library/react'; | ||
import { Simulate } from 'react-dom/test-utils'; | ||
|
||
jest.mock('./components/comander/Comander.js', () => { | ||
return function MockComander() { | ||
return <div></div> | ||
} | ||
}); | ||
|
||
service.doLogout = jest.fn(); | ||
service.getQuery = jest.fn(); | ||
|
||
describe('App test suite', () => { | ||
beforeAll(() => { | ||
let rendered; | ||
|
||
beforeEach(() => { | ||
const cookies = new Cookies(); | ||
cookies.set('neo4jDash.sess', { sessionId: 'test' }); | ||
({ rendered } = getMockProvider(<App/>, { user: { loggedIn: false } })); | ||
}) | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
cleanup(); | ||
}); | ||
|
||
test("renders App if user is logged in", async () => { | ||
const { findByTestId } = rendered; | ||
|
||
const linkElement = await findByTestId("app"); | ||
expect(linkElement).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('App user loggedIn test suite', () => { | ||
let rendered; | ||
let store; | ||
let act; | ||
|
||
beforeEach(() => { | ||
({ rendered, store, act } = getMockProvider(<App/>, { user: { loggedIn: true }})); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
cleanup(); | ||
}); | ||
|
||
test("renders App if user is logged in", async () => { | ||
const { getByTestId } = rendered; | ||
const appElement = getByTestId('app'); | ||
expect(appElement).toBeDefined(); | ||
}); | ||
|
||
test("trigger logout if user click logout button", async () => { | ||
const { findByTestId } = rendered; | ||
act(() => { | ||
store.dispatch(actions.user.logOut()); | ||
}) | ||
const linkElement = await findByTestId("login"); | ||
expect(linkElement).toBeDefined(); | ||
}) | ||
}); | ||
|
||
describe("App user not logged test suite", () => { | ||
let rendered; | ||
|
||
beforeEach(() => { | ||
({ rendered } = getMockProvider(<App/>, { theme: {}, user: { loggedIn: false } })); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
cleanup(); | ||
}); | ||
|
||
test('renders login button if user is not logged in', () => { | ||
const { MockProvider } = setup({ theme: {}, user: { loggedIn: false } }); | ||
const { getByText } = render(<MockProvider><App /></MockProvider>); | ||
test("renders login button if user is not logged in", async () => { | ||
const { getByText } = rendered; | ||
const linkElement = getByText("Login"); | ||
expect(linkElement).toBeDefined(); | ||
}); | ||
}) | ||
}); | ||
|
||
describe("App sidebar test suite", () => { | ||
let rendered; | ||
|
||
beforeEach(() => { | ||
({ rendered } = getMockProvider(<App/>, { theme: {}, user: { loggedIn: true } })); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
cleanup(); | ||
}) | ||
|
||
test("sidebar render test", async () => { | ||
const { getByTestId, findByTestId } = rendered; | ||
const trigger = getByTestId('menu-trigger'); | ||
Simulate.click(trigger); | ||
const element = await findByTestId('sidebar'); | ||
expect(element).toBeDefined(); | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.