Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavBar Component Testing + Snapshots and localStorage Mock #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions client/src/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var localStorageMock = (function () {
var store = {};
return {
getItem: function (key) {
return store[key];
},
setItem: function (key, value) {
store[key] = value.toString();
},
clear: function () {
store = {};
},
removeItem: function (key) {
delete store[key];
}
};
})();
Object.defineProperty(window, 'localStorage', {
value: localStorageMock
});
169 changes: 169 additions & 0 deletions client/tests/__snapshots__/navbar.component.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<NavBar /> Unit Tests renders correctly 1`] = `
<div>
<div
class="pusher"
>
<div
class="ui menu asd borderless"
>
<a
class="item openbtn"
href="#!"
onClick={[Function]}
>
<i
class="icon content"
/>
</a>
<img
alt="Nodecloud logo"
class="nav-logo"
onClick={[Function]}
src="../media/nodecloudlogo.png"
/>
<a
class="item"
href="#!"
onClick={[Function]}
>

Node Cloud
</a>
<div
class="right menu"
>
<div
aria-expanded={false}
className="ui inline dropdown"
onBlur={[Function]}
onChange={[Function]}
onClick={[Function]}
onFocus={[Function]}
onMouseDown={[Function]}
role="listbox"
style={
Object {
"padding": 12,
}
}
tabIndex={0}
>
<div
aria-atomic={true}
aria-live="polite"
className="default text"
role="alert"
>
Select Provider
</div>
<i
aria-hidden="true"
className="dropdown icon"
onClick={[Function]}
/>
<div
className="menu transition"
>
<div
aria-checked={false}
aria-selected={true}
className="selected item"
onClick={[Function]}
role="option"
style={
Object {
"pointerEvents": "all",
}
}
>
<img
className="ui avatar image"
src="../media/aws.png"
/>
<span
className="text"
>
Amazon Web Services
</span>
</div>
<div
aria-checked={false}
aria-selected={false}
className="item"
onClick={[Function]}
role="option"
style={
Object {
"pointerEvents": "all",
}
}
>
<img
className="ui avatar image"
src="../media/azure.png"
/>
<span
className="text"
>
Azure
</span>
</div>
<div
aria-checked={false}
aria-selected={false}
className="item"
onClick={[Function]}
role="option"
style={
Object {
"pointerEvents": "all",
}
}
>
<img
className="ui avatar image"
src="../media/gcp.png"
/>
<span
className="text"
>
Google Cloud Platform
</span>
</div>
</div>
</div>
<div
class="ui dropdown item"
>
test

<i
class="dropdown icon"
/>
<div
class="menu"
>
<a
class="item"
href="#!"
>
Help
</a>
<a
class="item"
href="#!"
>
Logout
</a>
</div>
</div>
<div
class="item"
/>
</div>
</div>
</div>
</div>
`;
21 changes: 21 additions & 0 deletions client/tests/navbar.component.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import TestRenderer from "react-test-renderer";
import SideBar from "../src/_components/NavBar";
import React from "react";

describe("<NavBar /> Unit Tests", () => {
it("renders correctly", () => {
var testFunction = jest.fn();
const testUser = {
username: 'test'
}
const testUserString = JSON.stringify(testUser);
localStorage.setItem('user', testUserString);
var component = TestRenderer.create( <
SideBar handleShowSidebar = {
testFunction
}
/>
);
expect(component).toMatchSnapshot();
});
});