diff --git a/src/pages/CategoryPage/CategoryPage.test.js b/src/pages/CategoryPage/CategoryPage.test.js
index 21a48f0..9a50b09 100644
--- a/src/pages/CategoryPage/CategoryPage.test.js
+++ b/src/pages/CategoryPage/CategoryPage.test.js
@@ -39,7 +39,7 @@ describe('', function () {
let message;
global.console.log = jest.fn((m) => {
message = m;
- })
+ });
const wrapper = shallow();
diff --git a/src/pages/HomePage/HomePage.css b/src/pages/HomePage/HomePage.css
index d4450a5..1b4b6a5 100644
--- a/src/pages/HomePage/HomePage.css
+++ b/src/pages/HomePage/HomePage.css
@@ -8,7 +8,7 @@
width: 10%;
}
-.searchform{
+.searchform {
margin-top: 25px;
float: right;
}
diff --git a/src/pages/HomePage/HomePage.test.js b/src/pages/HomePage/HomePage.test.js
index 6157971..02bbf18 100644
--- a/src/pages/HomePage/HomePage.test.js
+++ b/src/pages/HomePage/HomePage.test.js
@@ -11,6 +11,11 @@ function prepareFetchApi(response) {
return (jest.fn().mockImplementation(() => mockFetchPromise));
}
+function prepareFailingFetchApi() {
+ const mockFetchPromise = Promise.reject("myreason");
+ return (jest.fn().mockImplementation(() => mockFetchPromise));
+}
+
describe('', function () {
it('renders without crashing ', function () {
const wrapper = shallow();
@@ -58,11 +63,11 @@ describe('', function () {
});
it('test search field', done => {
- global.fetch = prepareFetchApi([{},{}]);
+ global.fetch = prepareFetchApi([{}, {}]);
const wrapper = shallow();
- wrapper.find('[data-testid="searchtextfield"]').simulate('change', { target: { value: 'testvalue' } });
+ wrapper.find('[data-testid="searchtextfield"]').simulate('change', {target: {value: 'testvalue'}});
wrapper.find('[data-testid="searchbtnsubmit"]').simulate("click");
process.nextTick(() => {
@@ -73,4 +78,43 @@ describe('', function () {
done();
});
});
+
+ it('test form submit', done => {
+ global.fetch = prepareFetchApi([{}, {}]);
+
+ const wrapper = shallow();
+
+ const fakeEvent = {preventDefault: () => console.log('preventDefault')};
+ wrapper.find(".searchform").simulate('submit', fakeEvent);
+
+ expect(wrapper.state().selectionnr).toBe(0);
+
+ process.nextTick(() => {
+ // state to be set correctly with response
+ expect(wrapper.state().selectionnr).toBe(2);
+
+ global.fetch.mockClear();
+ done();
+ });
+ });
+
+ it('test no backend connection behaviour', done => {
+ // this test assumes a console.log within every connection fail
+ global.fetch = prepareFailingFetchApi();
+
+ let count = 0;
+ global.console.log = jest.fn((m) => {
+ count++;
+ });
+
+ const wrapper = shallow();
+
+ process.nextTick(() => {
+ // state to be set correctly with response
+ expect(global.fetch).toBeCalledTimes(2);
+
+ global.fetch.mockClear();
+ done();
+ });
+ });
});