How to use chooser.start method in qawolf

Best JavaScript code snippet using qawolf

EditPost.js

Source:EditPost.js Github

copy

Full Screen

1import React from 'react';2import Icon from '@mdi/react';3import { mdiRhombusSplit, mdiSend } from '@mdi/js';4import { Link } from "react-router-dom";5import TextChooser from './TextChooser'6import TimeChooser from './TimeChooser';7import TagChooser from './TagChooser';8import PeopleChooser from './PeopleChooser'9import LocationChooser from './LocationMap'10import Post from './Post';11import {TextField, Snackbar} from '@material-ui/core';12import Alert from '@material-ui/lab/Alert';13import * as requests from './requests'14const BACKEND_IP = process.env.REACT_APP_BACKEND_API ? process.env.REACT_APP_BACKEND_API : '3.67.83.253';15class EditPost extends React.Component{16 /**17 * This component represents the Edit Post page of the application.18 * Story title and text, locations, time, tags and images of a post can be edited on this page.19 * @param {*} props 20 */21 constructor(props){22 super(props);23 console.log(window.location.href);24 const regex = /id=/g;25 const url = window.location.href;26 const idx = url.search(regex);27 const id = parseInt(url.slice(idx+3));28 console.log(url.slice(idx+3));29 this.refStory = React.createRef();30 this.refLocation = React.createRef();31 this.refTime = React.createRef();32 this.refTags = React.createRef();33 this.allRefs = [this.refStory, this.refLocation, this.refTime, this.refTags];34 this.state = {35 id: id,36 selected : "Story",37 postData: {38 textChooser: {title : " ", body: " "},39 locationChooser: [],40 timeChooser: {41 startYear: null,42 endYear: null,43 startMonth: null,44 endMonth: null,45 startDay: null,46 endDay: null,47 startTime: null,48 endTime: null,49 },50 tagChooser: {selectedTags: []},51 owner:"USER",52 imageComponent: null53 }54 };55 this.handleChildObjectSend = this.handleChildObjectSend.bind(this);56 this.select = this.select.bind(this);57 this.sendToBackend = this.sendToBackend.bind(this);58 this.handleSuccessClose = this.handleSuccessClose.bind(this);59 this.handleInfoClose = this.handleInfoClose.bind(this);60 this.prepareObjectToSend = this.prepareObjectToSend.bind(this);61 }62 componentDidMount(){63 //fetch(`http://${backendIP}/api/post/get/${this.state.id}`).64 requests.get_jwt(`/api/post/get/${this.state.id}`,{}).then(resp => resp.json()).then(65 data => {66 this.setState(state=>{return {67 ...state,68 postData: {69 ...state.postData,70 owner: data.owner71 }72 }});73 this.refLocation.current.getEditInfo(data);74 data.locations = data.locations.map( (obj, i) => obj[0]);75 console.log(data);76 this.refStory.current.getEditInfo(data);77 this.refTags.current.getEditInfo(data);78 79 this.refTime.current.getEditInfo(data);80 }81 );82 }83 handleChildObjectSend(whichComponent, childObj){84 const infoDict = {85 "textChooser": "Story text Content",86 "locationChooser": "Location Content",87 "timeChooser": "Time Content",88 "peopleChooser": "People Content",89 "tagChooser": "Tag Content",90 "imageComponent": "Image Content"91 };92 this.setState(state => {93 //let newObj = JSON.parse(JSON.stringify(state));94 let newObj = {...state};95 newObj.postData[whichComponent] = childObj;96 //problem code97 if(whichComponent == 'locationChooser')98 newObj.postData[whichComponent] = childObj;99 //problem code100 newObj['addedInformation'] = true;101 newObj['whichInfo'] = infoDict[whichComponent];102 return newObj;103 });104 105 }106 select(obj){107 this.setState(state => {108 //let newObj = JSON.parse(JSON.stringify(state));109 //newObj['selected'] = obj;110 return {111 ...state,112 selected: obj113 };114 });115 }116 handleSuccessClose(){117 this.setState(state => {118 //let newObj = JSON.parse(JSON.stringify(state));119 //newObj['success'] = false;120 return {121 ...state,122 success: null123 };124 });125 }126 handleInfoClose(){127 this.setState(state => {128 //let newObj = JSON.parse(JSON.stringify(state));129 //newObj['addedInformation'] = false;130 return {131 ...state,132 addedInformation: false133 };134 });135 }136 prepareObjectToSend(){137 /*138 if(this.state.postData["timeChooser"]["startDate"] == null){139 140 return ({141 title: this.state.postData["textChooser"]["title"],142 story: this.state.postData["textChooser"]["body"],143 owner: this.state.postData["owner"],144 locations: this.state.postData["locationChooser"],145 storyDate: (new Date()).toISOString(),146 editDate: (new Date()).toISOString(),147 postDate: (new Date()).toISOString(),148 tags: this.state.postData["tagChooser"]["selectedTags"],149 //images: this.state.postData['imageComponent'],150 preview: this.state.postData['imageComponent']151 });152 }*/153 let obj = {154 title: this.state.postData["textChooser"]["title"],155 story: this.state.postData["textChooser"]["body"],156 owner: this.state.postData["owner"],157 locations: this.state.postData["locationChooser"],158 startYear: this.state.postData["timeChooser"]["startYear"],159 endYear: this.state.postData["timeChooser"]["endYear"] , 160 startMonth: this.state.postData["timeChooser"]["startMonth"],161 endMonth: this.state.postData["timeChooser"]["endMonth"] , 162 startDay: this.state.postData["timeChooser"]["startDay"],163 endDay: this.state.postData["timeChooser"]["endDay"] , 164 startTime: this.state.postData["timeChooser"]["startTime"],165 endTime: this.state.postData["timeChooser"]["endTime"] , 166 //storyDate: this.state.postData["timeChooser"]["startDate"] + "T" +this.state.postData["timeChooser"]["startTime"] + ":0.0Z" ,167 //editDate: this.state.postData["timeChooser"]["startDate"] + "T" +this.state.postData["timeChooser"]["startTime"] + ":0.0Z",168 //postDate: this.state.postData["timeChooser"]["startDate"] + "T" +this.state.postData["timeChooser"]["startTime"] + ":0.0Z",169 tags: this.state.postData["tagChooser"]["selectedTags"],170 //images: this.state.postData['imageComponent'],171 preview: this.state.postData['imageComponent']172 };173 let objectToSend = {};174 for(let key in obj){175 if(obj[key])176 objectToSend[key] = obj[key];177 }178 return (objectToSend);179 }180 sendToBackend(){181 // send this.state.postData to backend182 183 const objectToSend = this.prepareObjectToSend();184 const getFormData = object => Object.keys(object).reduce((formData, key) => {185 if ( key.includes('Year')){186 formData.append('year', object[key]);187 }else if (key.includes('Month')){188 formData.append('month', object[key]);189 }else if (key.includes('Day')){190 formData.append('day', object[key]);191 }192 else if(key == 'locations' )193 for(let el in object[key])194 formData.append(key, JSON.stringify(object[key][el]));195 else if(key == 'tags')196 for(let el in object[key])197 formData.append(key, object[key][el]);198 else199 formData.append(key, object[key]);200 return formData;201 }, new FormData());202 203 204 let formData = getFormData(objectToSend);205 console.log(formData.getAll('tags'));206 let at_least_one = 0;207 for(const key in objectToSend.preview){208 if(objectToSend.preview[key] instanceof File){209 at_least_one = 1;210 formData.append('images', objectToSend.preview[key]);211 }212 }213 if(!at_least_one)214 formData.set('images', []);215 216 if(formData.getAll('tags').length == 0)217 formData.set('tags', [])218 if(formData.getAll('locations').length == 0)219 formData.set('locations', []);220 221 fetch(`http://${BACKEND_IP}:8000/api/post/put/${this.state.id}`, {222 method: 'PUT',223 headers: {224 'Authorization': `JWT ${localStorage.getItem('access')}`225 },226 body: formData227 }).then(res => {228 if(res.status != 200){229 console.log("ERROR" + res.data);230 this.setState(state => {231 return {232 ...state,233 success: false,234 creationError: `Response Status: ${res.status} \n` + JSON.stringify(res)235 };236 });237 }else {238 console.log("Post SUCCESS.")239 //http://35.158.95.81:8000/api/post/delete/<int:id>240 241 this.setState(state => {242 return {243 ...state,244 success: true245 };246 });247 }248 })249 .catch(err => {250 this.setState(state => {251 return {252 ...state,253 success: false,254 creationError: err255 };256 });257 console.log("ERRRor" + err);258 });259 260 261 }262 render(){263 return(264 <header className="App-header">265 <div class = "row2 someSpacing">266 <div class = "inputArea">267 <div class = {(this.state['selected'] != 'Story')? "hide": ""}><TextChooser ref = {this.refStory} parentHandler = {this.handleChildObjectSend}/> </div>268 <div class = {(this.state['selected'] != 'Location')? "hide": ""}><LocationChooser ref = {this.refLocation} parentHandler = {this.handleChildObjectSend}/></div>269 <div class = {(this.state['selected'] != 'Time')? "hide": ""}><TimeChooser ref = {this.refTime} parentHandler = {this.handleChildObjectSend}/></div>270 <div class = {(this.state['selected'] != 'People')? "hide": ""}><PeopleChooser parentHandler = {this.handleChildObjectSend}/></div>271 <div class = {(this.state['selected'] != 'Tags')? "hide": ""}><TagChooser ref = {this.refTags} parentHandler = {this.handleChildObjectSend}/></div>272 <div class = {(this.state['selected'] != 'Images')? "hide": ""}><ImageComponent parentHandler = {this.handleChildObjectSend}/></div>273 {this.state['selected'] == 'Preview' && <div ><PostPreviewComponent key = {this.state.postData.owner} postObject = {this.prepareObjectToSend()} parentHandler = {this.handleChildObjectSend}/></div>}274 275 </div>276 <div class = "buttons col">277 <button class = "createPostBtn" onClick = {() => {this.select('Story')}}>Story</button>278 <button class = "createPostBtn" onClick = {() => {this.select('Location')}}>Location</button>279 <button class = "createPostBtn" onClick = {() => {this.select('Time')}}>Time</button>280 {/*<button class = "createPostBtn" onClick = {() => {this.select('People')}}>People</button>*/}281 <button class = "createPostBtn" onClick = {() => {this.select('Tags')}}>Tags</button>282 <button class = "createPostBtn" onClick = {() => {this.select('Images')}}>Images</button>283 <button class = "createPostBtn" onClick = {() => {284 this.refStory.current.sendParent();285 this.refLocation.current.sendParent();286 this.refTime.current.sendParent();287 this.refTags.current.sendParent();288 289 this.select('Preview');290 }}>Preview</button>291 292 {/*<TextField id="userNameField" label="Enter Your Name" variant="filled" focused 293 onChange = {(e) => this.setState(state => {294 let postData = state.postData;295 return {296 ...state,297 postData: {298 ...postData,299 owner: e.target.value300 }301 };302 303 })}/>*/}304 </div>305 306 {/*307 <Snackbar open={this.state.addedInformation} autoHideDuration={1000} onClose={this.handleInfoClose} >308 <Alert onClose={this.handleInfoClose} severity="success" sx={{ width: '100%' }}>309 Information about {this.state.whichInfo} is added to your post.310 </Alert>311 </Snackbar>312 */}313 <Snackbar open={this.state.success == false} autoHideDuration={5000} onClose={this.handleSuccessClose} >314 <Alert onClose={this.handleSuccessClose} severity="error" sx={{ width: '100%' }}>315 Your post could not be created. See below for the error message:316 {this.state.creationError}317 Note: The post title and body fields in the Story tab should not be empty.318 </Alert>319 </Snackbar>320 <Snackbar open={this.state.success} autoHideDuration={5000} onClose={this.handleSuccessClose} >321 <Alert onClose={this.handleSuccessClose} severity="success" sx={{ width: '100%' }}>322 Your post is successfully created.323 </Alert>324 </Snackbar>325 326 <Link to= {`/editPost?id=${this.state.id}`} variant = "v6">327 <Icon onClick = {() =>{328 this.refStory.current.sendParent();329 this.refLocation.current.sendParent();330 this.refTime.current.sendParent();331 this.refTags.current.sendParent();332 setTimeout( this.sendToBackend, 10);333 }334 } class = "circle homePageCreatePostButton" path={mdiSend}335 title="Post"336 size={2}337 color="black"338 />339 </Link>340 341 342 </div>343 </header>344 );345 }346}347class ImageComponent extends React.Component{348 constructor(props){349 super(props);350 this.handleFileChange = this.handleFileChange.bind(this);351 }352 handleFileChange(e){353 this.props.parentHandler('imageComponent',e.target.files);354 }355 render(){356 return(357 <div>358 <p>Please select suitable images for the post using the button below.</p>359 <input 360 type="file" id="file" 361 accept=".jpg, .png"362 multiple363 onChange={this.handleFileChange}364 />365 </div>366 );367 }368}369class PostPreviewComponent extends React.Component{370 constructor(props){371 super(props);372 this.state = {373 value: props374 };375 }376 static getDerivedStateFromProps(props, current_state) {377 if (current_state.value !== props) {378 return {379 value: props380 }381 }382 return null383 }384 render(){385 return(386 <div>387 <Post {...this.props.postObject} ></Post>388 </div>389 );390 }391}...

Full Screen

Full Screen

CreatePost.js

Source:CreatePost.js Github

copy

Full Screen

1import React from 'react';2import Icon from '@mdi/react';3import { mdiRhombusSplit, mdiSend } from '@mdi/js';4import { Link } from "react-router-dom";5import TextChooser from './TextChooser'6import TimeChooser from './TimeChooser';7import TagChooser from './TagChooser';8import PeopleChooser from './PeopleChooser'9//import LocationChooser from './LocationChooser'10import LocationChooser from './LocationMap'11import Post from './Post';12import {TextField, Snackbar} from '@material-ui/core';13import Alert from '@material-ui/lab/Alert';14import * as requests from './requests';15const BACKEND_IP = process.env.REACT_APP_BACKEND_API ? process.env.REACT_APP_BACKEND_API : '3.67.83.253';16class CreatePost extends React.Component{17 /**18 * This component represents the Create Post page of the application.19 * Story title and text, locations, time, tags and images can be added to a post to be created on this page.20 * @param {*} props 21 */22 constructor(props){23 super(props);24 25 this.refStory = React.createRef();26 this.refLocation = React.createRef();27 this.refTime = React.createRef();28 this.refTags = React.createRef();29 this.allRefs = [this.refStory, this.refLocation, this.refTime, this.refTags];30 this.state = {31 selected : "Story",32 postData: {33 textChooser: {title : " ", body: " "},34 locationChooser: [],35 timeChooser: {startDate : "", startTime: ""},36 tagChooser: {selectedTags: []},37 owner:"USER",38 imageComponent: null39 }40 };41 this.handleChildObjectSend = this.handleChildObjectSend.bind(this);42 this.select = this.select.bind(this);43 this.sendToBackend = this.sendToBackend.bind(this);44 this.handleSuccessClose = this.handleSuccessClose.bind(this);45 this.handleInfoClose = this.handleInfoClose.bind(this);46 this.prepareObjectToSend = this.prepareObjectToSend.bind(this);47 }48 /**49 * Get information from the children components50 * @param {*} whichComponent 51 * @param {*} childObj 52 */53 handleChildObjectSend(whichComponent, childObj){54 const infoDict = {55 "textChooser": "Story text Content",56 "locationChooser": "Location Content",57 "timeChooser": "Time Content",58 "peopleChooser": "People Content",59 "tagChooser": "Tag Content",60 "imageComponent": "Image Content"61 };62 this.setState(state => {63 //let newObj = JSON.parse(JSON.stringify(state));64 let newObj = {...state};65 newObj.postData[whichComponent] = childObj;66 //problem code67 if(whichComponent == 'locationChooser')68 newObj.postData[whichComponent] = childObj;69 //problem code70 newObj['addedInformation'] = true;71 newObj['whichInfo'] = infoDict[whichComponent];72 return newObj;73 });74 75 }76 select(obj){77 this.setState(state => {78 //let newObj = JSON.parse(JSON.stringify(state));79 //newObj['selected'] = obj;80 return {81 ...state,82 selected: obj83 };84 });85 }86 handleSuccessClose(){87 this.setState(state => {88 //let newObj = JSON.parse(JSON.stringify(state));89 //newObj['success'] = false;90 return {91 ...state,92 success: null93 };94 });95 }96 handleInfoClose(){97 this.setState(state => {98 //let newObj = JSON.parse(JSON.stringify(state));99 //newObj['addedInformation'] = false;100 return {101 ...state,102 addedInformation: false103 };104 });105 }106 /**107 * Prepare the object that is going to be posted to the backend API.108 * @returns 109 */110 prepareObjectToSend(){111 /*112 if(this.state.postData["timeChooser"]["startDate"] == null){113 114 return ({115 title: this.state.postData["textChooser"]["title"],116 story: this.state.postData["textChooser"]["body"],117 owner: this.state.postData["owner"],118 locations: this.state.postData["locationChooser"],119 storyDate: (new Date()).toISOString(),120 editDate: (new Date()).toISOString(),121 postDate: (new Date()).toISOString(),122 tags: this.state.postData["tagChooser"]["selectedTags"],123 //images: this.state.postData['imageComponent'],124 preview: this.state.postData['imageComponent']125 });126 }*/127 let obj = {128 title: this.state.postData["textChooser"]["title"],129 story: this.state.postData["textChooser"]["body"],130 owner: this.state.postData["owner"],131 locations: this.state.postData["locationChooser"],132 startYear: this.state.postData["timeChooser"]["startYear"],133 endYear: this.state.postData["timeChooser"]["endYear"] , 134 startMonth: this.state.postData["timeChooser"]["startMonth"],135 endMonth: this.state.postData["timeChooser"]["endMonth"] , 136 startDay: this.state.postData["timeChooser"]["startDay"],137 endDay: this.state.postData["timeChooser"]["endDay"] , 138 startTime: this.state.postData["timeChooser"]["startTime"],139 endTime: this.state.postData["timeChooser"]["endTime"] , 140 //storyDate: this.state.postData["timeChooser"]["startDate"] + "T" +this.state.postData["timeChooser"]["startTime"] + ":0.0Z" ,141 //editDate: this.state.postData["timeChooser"]["startDate"] + "T" +this.state.postData["timeChooser"]["startTime"] + ":0.0Z",142 //postDate: this.state.postData["timeChooser"]["startDate"] + "T" +this.state.postData["timeChooser"]["startTime"] + ":0.0Z",143 tags: this.state.postData["tagChooser"]["selectedTags"],144 //images: this.state.postData['imageComponent'],145 preview: this.state.postData['imageComponent']146 };147 let objectToSend = {};148 for(let key in obj){149 if(obj[key])150 objectToSend[key] = obj[key];151 }152 return (objectToSend);153 }154 /**155 * Prepare and send the prepared post using a FormData object to the backend.156 */157 sendToBackend(){158 // send this.state.postData to backend159 160 const objectToSend = this.prepareObjectToSend();161 const getFormData = object => Object.keys(object).reduce((formData, key) => {162 if ( key.includes('Year')){163 formData.append('year', object[key]);164 }else if (key.includes('Month')){165 formData.append('month', object[key]);166 }else if (key.includes('Day')){167 formData.append('day', object[key]);168 }169 else if(key == 'locations' )170 for(let el in object[key])171 formData.append(key, JSON.stringify(object[key][el]));172 else if(key == 'tags')173 for(let el in object[key])174 formData.append(key, object[key][el]);175 else176 formData.append(key, object[key]);177 return formData;178 }, new FormData());179 let formData = getFormData(objectToSend);180 let at_least_one = 0;181 for(const key in objectToSend.preview){182 if(objectToSend.preview[key] instanceof File){183 at_least_one = 1;184 formData.append('images', objectToSend.preview[key]);185 }186 }187 if(!at_least_one)188 formData.set('images', []);189 if(formData.getAll('tags').length == 0)190 formData.set('tags', [])191 if(formData.getAll('locations').length == 0)192 formData.set('locations', []);193 //formData.set('locations', formData.getAll('locations') || []);194 //formData.set('tags', formData.getAll('tags') || []);195 //requests.post_jwt(`/api/post/create`, formData)196 fetch(`http://${BACKEND_IP}:8000/api/post/create`, {197 method: 'POST',198 headers: {199 'Authorization': `JWT ${localStorage.getItem('access')}`200 },201 body: formData202 }).then(res => {203 if(res.status != 200){204 console.log("ERROR" + res.data);205 this.setState(state => {206 return {207 ...state,208 success: false,209 creationError: `Response Status: ${res.status} \n` + JSON.stringify(res)210 };211 });212 }else {213 console.log("Post SUCCESS.")214 this.setState(state => {215 return {216 ...state,217 success: true218 };219 });220 }221 })222 .catch(err => {223 this.setState(state => {224 return {225 ...state,226 success: false,227 creationError: err228 };229 });230 console.log("ERRRor" + err);231 });232 233 234 }235 render(){236 return(237 <header className="App-header">238 <div class = "row2 someSpacing">239 <div class = "inputArea">240 <div class = {(this.state['selected'] != 'Story')? "hide": ""}><TextChooser ref = {this.refStory} parentHandler = {this.handleChildObjectSend}/> </div>241 <div class = {(this.state['selected'] != 'Location')? "hide": ""}><LocationChooser ref = {this.refLocation} parentHandler = {this.handleChildObjectSend}/></div>242 <div class = {(this.state['selected'] != 'Time')? "hide": ""}><TimeChooser ref = {this.refTime} parentHandler = {this.handleChildObjectSend}/></div>243 <div class = {(this.state['selected'] != 'People')? "hide": ""}><PeopleChooser parentHandler = {this.handleChildObjectSend}/></div>244 <div class = {(this.state['selected'] != 'Tags')? "hide": ""}><TagChooser ref = {this.refTags} parentHandler = {this.handleChildObjectSend}/></div>245 <div class = {(this.state['selected'] != 'Images')? "hide": ""}><ImageComponent parentHandler = {this.handleChildObjectSend}/></div>246 {this.state['selected'] == 'Preview' && <div ><PostPreviewComponent key = {this.state.postData.owner} postObject = {this.prepareObjectToSend()} parentHandler = {this.handleChildObjectSend}/></div>}247 248 </div>249 <div class = "buttons col">250 <button class = "createPostBtn" onClick = {() => {this.select('Story')}}>Story</button>251 <button class = "createPostBtn" onClick = {() => {this.select('Location')}}>Location</button>252 <button class = "createPostBtn" onClick = {() => {this.select('Time')}}>Time</button>253 {/*<button class = "createPostBtn" onClick = {() => {this.select('People')}}>People</button>*/}254 <button class = "createPostBtn" onClick = {() => {this.select('Tags')}}>Tags</button>255 <button class = "createPostBtn" onClick = {() => {this.select('Images')}}>Images</button>256 <button class = "createPostBtn" onClick = {() => {257 this.refStory.current.sendParent();258 this.refLocation.current.sendParent();259 this.refTime.current.sendParent();260 this.refTags.current.sendParent();261 262 this.select('Preview');263 }}>Preview</button>264 265 {/*<TextField id="userNameField" label="Enter Your Name" variant="filled" focused 266 onChange = {(e) => this.setState(state => {267 let postData = state.postData;268 return {269 ...state,270 postData: {271 ...postData,272 owner: e.target.value273 }274 };275 276 })}/>*/}277 </div>278 279 {/*280 <Snackbar open={this.state.addedInformation} autoHideDuration={1000} onClose={this.handleInfoClose} >281 <Alert onClose={this.handleInfoClose} severity="success" sx={{ width: '100%' }}>282 Information about {this.state.whichInfo} is added to your post.283 </Alert>284 </Snackbar>285 */}286 <Snackbar open={this.state.success == false} autoHideDuration={1000} onClose={this.handleSuccessClose} >287 <Alert onClose={this.handleSuccessClose} severity="error" sx={{ width: '100%' }}>288 Your post could not be created. See below for the error message:289 {this.state.creationError}290 Note: The post title and body fields in the Story tab should not be empty.291 </Alert>292 </Snackbar>293 <Snackbar open={this.state.success} autoHideDuration={1000} onClose={this.handleSuccessClose} >294 <Alert onClose={this.handleSuccessClose} severity="success" sx={{ width: '100%' }}>295 Your post is successfully created.296 </Alert>297 </Snackbar>298 299 <Link to= "/createPost" variant = "v6">300 <Icon onClick = {() =>{301 this.refStory.current.sendParent();302 this.refLocation.current.sendParent();303 this.refTime.current.sendParent();304 this.refTags.current.sendParent();305 setTimeout( this.sendToBackend, 10);306 }307 } class = "circle homePageCreatePostButton" path={mdiSend}308 title="Post"309 size={2}310 color="black"311 />312 </Link>313 314 315 </div>316 </header>317 );318 }319}320class ImageComponent extends React.Component{321 constructor(props){322 super(props);323 this.handleFileChange = this.handleFileChange.bind(this);324 }325 handleFileChange(e){326 this.props.parentHandler('imageComponent',e.target.files);327 }328 render(){329 return(330 <div>331 <p>Please select suitable images for the post using the button below.</p>332 <input 333 type="file" id="file" 334 accept=".jpg, .png"335 multiple336 onChange={this.handleFileChange}337 />338 </div>339 );340 }341}342/**343 * A component that enables the user to preview the post on a Post component before sending it to the backend.344 */345class PostPreviewComponent extends React.Component{346 constructor(props){347 super(props);348 this.state = {349 value: props350 };351 }352 static getDerivedStateFromProps(props, current_state) {353 if (current_state.value !== props) {354 return {355 value: props356 }357 }358 return null359 }360 render(){361 return(362 <div>363 <Post {...this.props.postObject} ></Post>364 </div>365 );366 }367}...

Full Screen

Full Screen

game_chooser-tests.js

Source:game_chooser-tests.js Github

copy

Full Screen

...30 'name_is_game_chooser': function ( suite ) {31 suite.assertSame( 'game_chooser', suite.game_chooser.name );32 },33 'number_is_positive': function ( suite ) {34 suite.game_chooser.start(function (instance) {35 suite.assertTrue( instance.get_next_number() > 0 );36 });37 },38 'number_is_less_than_exponent': function ( suite ) {39 suite.game_chooser.start(function (instance) {40 suite.assertTrue( instance.get_next_number() < Math.pow( 10, instance.number_range_exponent ) );41 });42 },43 'range_is_less_than_max': function ( suite ) {44 suite.game_chooser.start(function (instance) {45 suite.assertTrue( instance.number_range_exponent <= instance.number_range_max_exponent );46 });47 },48 'language_is_valid': function ( suite ) {49 suite.game_chooser.start(function (instance) {50 suite.assertTrue( Object.keys(instance.languages).indexOf( instance.language ) > -1 );51 });52 }53 }54 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chooser } = require("qawolf");2(async () => {3 const browser = await chooser.start();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.fill("input[name=\"q\"]", "qawolf");7 await page.press("input[name=\"q\"]", "Enter");8 await page.click("text=QA Wolf: End-to-end browser testing for developers");9 await page.click("text=Documentation");10 await page.click("text=API");11 await page.click("text=Browser");12 await page.click("text=BrowserContext");13 await page.click("tex

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chooser } = require("qawolf");2(async () => {3 const browser = await chooser.start();4 const page = await browser.newPage();5 await page.type("#lst-ib", "hello world");6 await page.click("#tsf > div.tsf-p > div.jsb > center > input[type='submit']:nth-child(1)");7 await page.waitForSelector("#resultStats");8 await page.click("#rso > div:nth-child(1) > div > div > div > div > h3 > a");9 await page.waitForSelector("#firstHeading");10 await page.waitFor(3000);11 await browser.close();12})();13const { chooser } = require("qawolf");14(async () => {15 const browser = await chooser.start();16 const page = await browser.newPage();17 await page.type("#lst-ib", "hello world");18 await page.click("#tsf > div.tsf-p > div.jsb > center > input[type='submit']:nth-child(1)");19 await page.waitForSelector("#resultStats");20 await page.click("#rso > div:nth-child(1) > div > div > div > div > h3 > a");21 await page.waitForSelector("#firstHeading");22 await page.waitFor(3000);23 await browser.close();24})();25const { chooser } = require("qawolf");26(async () => {27 const browser = await chooser.start();28 const page = await browser.newPage();29 await page.type("#lst-ib", "hello world");30 await page.click("#tsf > div.tsf-p > div.jsb > center > input[type='submit']:nth-child(1)");31 await page.waitForSelector("#resultStats");32 await page.click("#rso > div:nth-child(1) > div > div > div > div > h3 > a");33 await page.waitForSelector("#firstHeading");34 await page.waitFor(3000);35 await browser.close();36})();37const { chooser } = require("q

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch } = require('qawolf');2const context = browser.context();3await context.close();4const { chromium } = require('playwright');5const browser = await chromium.launch({ headless: false });6const context = await browser.newContext();7await context.close();8const puppeteer = require('puppeteer');9const browser = await puppeteer.launch({ headless: false });10const context = await browser.createIncognitoBrowserContext();11await context.close();

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require('qawolf');2const { chromium } = require('playwright');3const { join } = require('path');4const main = async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.setViewportSize({ width: 1280, height: 800 });9 await page.waitForTimeout(5000);10 await page.click('#main > div.w3-example > form > input[type="file"]');11 await qawolf.start(page);12 await browser.close();13};14main();15const qawolf = require('qawolf');16const { chromium } = require('playwright');17const { join } = require('path');18const main = async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.setViewportSize({ width: 1280, height: 800 });23 await page.waitForTimeout(5000);24 await page.click('#main > div.w3-example > form > input[type="file"]');25 await qawolf.start(page);26 await browser.close();27};28main();

Full Screen

Using AI Code Generation

copy

Full Screen

1const filePath = await page.evaluate(() => {2 return document.querySelector('input[type="file"]').files[0].path;3});4const chooser = await page.input('input[type="file"]');5await chooser.start();6await chooser.stop();7const filePath = await page.evaluate(() => {8 return document.querySelector('input[type="file"]').files[0].path;9});10await page.setInputValue('input[type="file"]', filePath);11const chooser = await page.input('input[type="file"]');12await chooser.start();13await chooser.stop();14const chooser = await page.input('input[type="file"]');15await chooser.start();16await chooser.stop();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful