add test to test savesettings
This commit is contained in:
		@@ -37,7 +37,7 @@ class GeneralSettings extends React.Component {
 | 
				
			|||||||
        return (
 | 
					        return (
 | 
				
			||||||
            <>
 | 
					            <>
 | 
				
			||||||
                <div className={style.GeneralForm}>
 | 
					                <div className={style.GeneralForm}>
 | 
				
			||||||
                    <Form onSubmit={(e) => {
 | 
					                    <Form data-testid='mainformsettings' onSubmit={(e) => {
 | 
				
			||||||
                        e.preventDefault();
 | 
					                        e.preventDefault();
 | 
				
			||||||
                        this.saveSettings();
 | 
					                        this.saveSettings();
 | 
				
			||||||
                    }}>
 | 
					                    }}>
 | 
				
			||||||
@@ -102,8 +102,10 @@ class GeneralSettings extends React.Component {
 | 
				
			|||||||
            .then((response) => response.json()
 | 
					            .then((response) => response.json()
 | 
				
			||||||
                .then((result) => {
 | 
					                .then((result) => {
 | 
				
			||||||
                    if (result.success) {
 | 
					                    if (result.success) {
 | 
				
			||||||
 | 
					                        console.log("successfully saved settings");
 | 
				
			||||||
                        // todo 2020-07-10: popup success
 | 
					                        // todo 2020-07-10: popup success
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        console.log("failed to save settings");
 | 
				
			||||||
                        // todo 2020-07-10: popup error
 | 
					                        // todo 2020-07-10: popup error
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }));
 | 
					                }));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,4 +24,22 @@ describe('<GeneralSettings/>', function () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        expect(wrapper.find("FormGroup").findWhere(it => it.props().controlId === "passwordfield")).toHaveLength(1);
 | 
					        expect(wrapper.find("FormGroup").findWhere(it => it.props().controlId === "passwordfield")).toHaveLength(1);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('test savesettings', done => {
 | 
				
			||||||
 | 
					        const wrapper = shallow(<GeneralSettings/>);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        global.fetch = prepareFetchApi({success: true});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        expect(global.fetch).toBeCalledTimes(0);
 | 
				
			||||||
 | 
					        wrapper.find("[data-testid='mainformsettings']").simulate("submit");
 | 
				
			||||||
 | 
					        expect(global.fetch).toBeCalledTimes(1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        process.nextTick(() => {
 | 
				
			||||||
 | 
					            // expect callback to have loaded correct tag
 | 
				
			||||||
 | 
					            expect(wrapper.state().selected).toBe("testname");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            global.fetch.mockClear();
 | 
				
			||||||
 | 
					            done();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user