Best JavaScript code snippet using devicefarmer-stf
GroupForm.jsx
Source:GroupForm.jsx
1import React, { useState, useEffect } from 'react'2import { Dialog, DialogTitle, DialogContent, Box, Grid, Typography, TextField, Select, Chip, MenuItem, DialogActions, Button } from '@mui/material'3import { LoadingButton } from '@mui/lab'4import { useTheme } from '@mui/material/styles'5import UsersService from '../services/UsersService'6export const GroupForm = (props) => {7 const { initGroup, isOpen, closeModal, submit } = props8 const theme = useTheme()9 const [users, setUsers] = useState([])10 const [groupName, setGroupName] = useState('')11 const [selectedAdmins, setSelectedAdmins] = useState([])12 const [selectedAdminIDs, setSelectedAdminIDs] = useState([])13 const [selectedGenerals, setSelectedGenerals] = useState([])14 const [selectedGeneralIDs, setSelectedGeneralIDs] = useState([])15 const [isLoading, setIsLoading] = useState(false)16 useEffect(() => {17 const func = async () => {18 const userList = await UsersService.getUsers()19 setUsers(userList)20 }21 func()22 initInputs()23 }, [initGroup])24 useEffect(() => {25 initInputs()26 }, [isOpen])27 const getItemStyle = (id, selectedIDs, theme) => {28 return {29 fontWeight:30 selectedIDs.indexOf(id) === -131 ? theme.typography.fontWeightRegular32 : theme.typography.fontWeightMedium33 }34 }35 const initInputs = () => {36 setGroupName(initGroup? initGroup.name : '')37 setSelectedAdmins(initGroup? initGroup.adminUsers : [])38 setSelectedAdminIDs(initGroup? initGroup.adminUsers.map(user => user.id) : [])39 setSelectedGenerals(initGroup? initGroup.generalUsers : [])40 setSelectedGeneralIDs(initGroup? initGroup.generalUsers.map(user => user.id) : [])41 }42 const handleCloseModal = () => {43 closeModal()44 initInputs()45 setIsLoading(false)46 }47 const handleChangeGroupName = (event) => setGroupName(event.target.value)48 const handleSelectAdminChange = event => {49 const { target: { value } } = event50 const targetID = value.pop()51 const oldIDs = selectedAdminIDs.concat()52 let newIDs = []53 if(oldIDs.includes(targetID)) {54 newIDs = oldIDs.filter(id => id !== targetID)55 setSelectedAdminIDs(newIDs)56 } else {57 oldIDs.push(targetID)58 newIDs = oldIDs59 setSelectedAdminIDs(oldIDs)60 }61 const newSelectedAdmins = users.filter(user => newIDs.includes(user.id))62 setSelectedAdmins(newSelectedAdmins)63 }64 const handleSelectGeneralChange = event => {65 const { target: { value } } = event66 const targetID = value.pop()67 const oldIDs = selectedGeneralIDs.concat()68 let newIDs = []69 if(oldIDs.includes(targetID)) {70 newIDs = oldIDs.filter(id => id !== targetID)71 setSelectedGeneralIDs(newIDs)72 } else {73 oldIDs.push(targetID)74 newIDs = oldIDs75 setSelectedGeneralIDs(oldIDs)76 }77 const newSelectedGenerals = users.filter(user => newIDs.includes(user.id))78 setSelectedGenerals(newSelectedGenerals)79 }80 const handleSubmit = async () => {81 setIsLoading(true)82 await submit(groupName, selectedAdminIDs, selectedGeneralIDs)83 initInputs()84 setIsLoading(false)85 closeModal(false)86 }87 return (88 <Dialog89 onClose={handleCloseModal}90 open={isOpen}91 >92 <DialogTitle>æ°è¦é¨ç½²ä½æ</DialogTitle>93 <DialogContent dividers>94 <Box sx={{width: 500, height: 600}}>95 <Grid container alignItems='center'>96 <Grid item xs={4}>97 <Typography sx={{m: '30px', ml: '10px'}}>é¨ç½²å</Typography>98 </Grid>99 <Grid item xs={8}>100 <TextField sx={{textAlign: 'middle'}} onChange={handleChangeGroupName} value={groupName}/>101 </Grid>102 <Grid item xs={4}>103 <Typography sx={{m: '30px', ml: '10px'}}>æ¿èªè
</Typography>104 </Grid>105 <Grid item xs={8}>106 <Select107 multiple108 value={selectedAdmins.map(u => (u.last_name+u.first_name))}109 onChange={handleSelectAdminChange}110 renderValue={selected => (111 <Box>112 {selected.map(value => <Chip key={value} label={value}/>)}113 </Box>114 )}115 >116 {users?.map(u => (117 <MenuItem118 key={u.id}119 value={u.id}120 style={getItemStyle(u.id, selectedAdminIDs, theme)}121 >122 {u.last_name+u.first_name}123 </MenuItem>124 ))}125 </Select>126 </Grid>127 <Grid item xs={4}>128 <Typography sx={{m: '30px', ml: '10px'}}>ä¸è¬ç¤¾å¡</Typography>129 </Grid>130 <Grid item xs={8}>131 <Select132 multiple133 value={selectedGenerals.map(u => (u.last_name+u.first_name))}134 onChange={handleSelectGeneralChange}135 renderValue={selected => (136 <Box>137 {selected.map(value => <Chip key={value} label={value}/>)}138 </Box>139 )}140 >141 {users?.map(u => (142 <MenuItem143 key={u.id}144 value={u.id}145 style={getItemStyle(u.id, selectedGeneralIDs, theme)}146 >147 {u.last_name+u.first_name}148 </MenuItem>149 ))}150 </Select>151 </Grid>152 </Grid>153 </Box>154 </DialogContent>155 <DialogActions>156 {/* <Button variant='contained' onClick={handleSubmit}>ä½æ</Button> */}157 <LoadingButton variant='contained' onClick={handleSubmit} loading={isLoading}>ä½æ</LoadingButton>158 <Button onClick={handleCloseModal}>ãã£ã³ã»ã«</Button>159 </DialogActions>160 </Dialog>161 )...
unit-test-dom-operations.html.0.js
Source:unit-test-dom-operations.html.0.js
1var body = document.querySelector('body');2var anims = [body, body, body, body, body, body, body, body, body, body].map(function(element, idx) {3 return new Animation(element, { left: '100px' }, idx);4});5function initGroup() {6 return new AnimationGroup(anims.slice(0, 5));7}8function toOrdering(list) {9 return [].map.call(list, function(animation) { return animation.timing.duration; });10}11function assert_child_order(group, list, message) {12 assert_array_equals(toOrdering(group.children), list, message);13}14test(function() {15 var group = new AnimationGroup();16 group.append(anims[5]);17 assert_child_order(group, [5],18 'append on empty group should work');19 var group = initGroup();20 group.append(anims[5]);21 assert_child_order(group, [0, 1, 2, 3, 4, 5],22 'append should place element 5 at end of group');23 group.append(anims[6], anims[7], anims[8]);24 assert_child_order(group, [0, 1, 2, 3, 4, 5, 6, 7, 8],25 'append should place elements 6, 7, and 8 at end of group');26}, 'append');27test(function() {28 var group = new AnimationGroup();29 group.prepend(anims[5]);30 assert_child_order(group, [5],31 'prepend on empty group should work');32 var group = initGroup();33 group.prepend(anims[5]);34 assert_child_order(group, [5, 0, 1, 2, 3, 4],35 'prepend should place element 5 at beginning of group');36 group.prepend(anims[6], anims[7], anims[8]);37 assert_child_order(group, [6, 7, 8, 5, 0, 1, 2, 3, 4],38 'prepend should place elements 6, 7, and 8 at beginning of group');39}, 'prepend');40test(function() {41 var group = initGroup();42 assert_equals(group.firstChild, anims[0],43 'first child should be element 0');44 group.prepend(anims[8]);45 assert_equals(group.firstChild, anims[8],46 'first child after prepend should be prepended element');47}, 'firstChild');48test(function() {49 var group = initGroup();50 assert_equals(group.lastChild, anims[4],51 'last child should be element 4');52 group.append(anims[8]);53 assert_equals(group.lastChild, anims[8],54 'last child after append should be appended element');55}, 'lastChild');56test(function() {57 var group = initGroup();58 group.children[2].before(anims[5]);59 assert_child_order(group, [0, 1, 5, 2, 3, 4],60 'before should place element 5 before element 2');61 anims[3].before(anims[6], anims[7], anims[8]);62 assert_child_order(group, [0, 1, 5, 2, 6, 7, 8, 3, 4],63 'before should place elements 6, 7, and 8 before element 3');64 group.firstChild.before(anims[9]);65 assert_child_order(group, [9, 0, 1, 5, 2, 6, 7, 8, 3, 4],66 'before should place element 9 at beginning of list');67}, 'before');68test(function() {69 var group = initGroup();70 group.children[2].after(anims[5]);71 assert_child_order(group, [0, 1, 2, 5, 3, 4],72 'after should place element 5 after element 2');73 anims[3].after(anims[6], anims[7], anims[8]);74 assert_child_order(group, [0, 1, 2, 5, 3, 6, 7, 8, 4],75 'after should place elements 6, 7, and 8 after element 3');76 group.lastChild.after(anims[9]);77 assert_child_order(group, [0, 1, 2, 5, 3, 6, 7, 8, 4, 9],78 'after should place element 9 at end of list');79}, 'after');80test(function() {81 var group = initGroup();82 group.children[2].replace(anims[5]);83 assert_child_order(group, [0, 1, 5, 3, 4],84 'replace should replace element 2 with element 5');85 anims[3].replace(anims[6], anims[7], anims[8]);86 assert_child_order(group, [0, 1, 5, 6, 7, 8, 4],87 'replace should replace element 3 with elements 6, 7, and 8');88 group.firstChild.replace(anims[9]);89 assert_child_order(group, [9, 1, 5, 6, 7, 8, 4],90 'replace should replace element 0 with element 9');91 group.lastChild.replace(anims[0]);92 assert_child_order(group, [9, 1, 5, 6, 7, 8, 0],93 'replace should replace element 4 with element 0');94}, 'replace');95test(function() {96 var group = initGroup();97 group.children[2].remove();98 assert_child_order(group, [0, 1, 3, 4],99 'element 2 should be removed');100 group.firstChild.remove();101 assert_child_order(group, [1, 3, 4],102 'first child should be removed');103 group.lastChild.remove();104 assert_child_order(group, [1, 3],105 'last child should be removed');106}, 'remove');107test(function() {108 var group = initGroup();109 var group2 = new AnimationGroup();110 group2.append(group);111 var group3 = new AnimationSequence();112 group3.append(group);113 assert_throws("HierarchyRequestError",114 function() {115 group.append(group3);116 },117 'group3 should be in hierarchy of group');118 assert_throws("HierarchyRequestError",119 function() {120 group.append(group);121 },122 'group should be in its own hierarchy');...
App.js
Source:App.js
...30}31function mapDispatchToProps(dispatch) {32 return {33 initUser: user => dispatch(initUser(user)),34 initGroup: group => dispatch(initGroup(group)),35 initRank: rank => dispatch(initRank(rank)),36 initHolidays: holiday => dispatch(initHolidays(holiday)),37 initStatus: status => dispatch(initStatus(status)),38 initPost: post => dispatch(initPost(post)),39 initPerson: person => dispatch(initPerson(person)),40 }41}42export default connect(mapStateToProps, mapDispatchToProps)(App);43App.propTypes = {44 user: propTypes.object,45 initUser: propTypes.func,46 initRank: propTypes.func,47 initGroup: propTypes.func,48 initHolidays: propTypes.func,...
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2var device = new stf.Device(client);3var group = new stf.Group(client);4var groupID = 'test';5var deviceID = '1234';6device.initGroup(groupID, deviceID, function(err, res) {7 if(err) {8 console.log('error');9 } else {10 console.log('success');11 }12});13var stf = require('devicefarmer-stf-client');14var device = new stf.Device(client);15var group = new stf.Group(client);16var groupID = 'test';17var deviceID = '1234';18device.initGroup(groupID, deviceID, function(err, res) {19 if(err) {20 console.log('error');21 } else {22 console.log('success');23 }24});25var stf = require('devicefarmer-stf-client');26var device = new stf.Device(client);27var group = new stf.Group(client);28var groupID = 'test';29var deviceID = '1234';30device.initGroup(groupID, deviceID, function(err, res) {31 if(err) {32 console.log('error');33 } else {34 console.log('success');35 }36});37var stf = require('devicefarmer-stf-client');38var device = new stf.Device(client);39var group = new stf.Group(client);40var groupID = 'test';41var deviceID = '1234';42device.initGroup(groupID, deviceID, function(err, res) {43 if(err) {44 console.log('error');45 } else {46 console.log('success');47 }48});49var stf = require('devicefarmer-stf-client');
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2var group = stf.initGroup();3var devicefarmer = require('devicefarmer-stf');4var group = stf.initGroup();5var device = stf.addDevice();6var devicefarmer = require('devicefarmer-stf');7var group = stf.initGroup();8var device = stf.addDevice();9var devices = stf.getDevices();10var devicefarmer = require('devicefarmer-stf');11var group = stf.initGroup();12var device = stf.addDevice();13var devices = stf.getDevices();14var device = stf.getDevice(devices[0].serial);15var devicefarmer = require('devicefarmer-stf');16var group = stf.initGroup();17var device = stf.addDevice();18var devices = stf.getDevices();19var device = stf.getDevice(devices[0].serial);20var deviceInfo = stf.getDeviceInfo(device);21var devicefarmer = require('devicefarmer-stf');22var group = stf.initGroup();23var device = stf.addDevice();24var devices = stf.getDevices();25var device = stf.getDevice(devices[0].serial);
Using AI Code Generation
1var DeviceFarmer = require('devicefarmer-stf-client');2deviceFarmer.initGroup('testgroup', function(err, result) {3 if (err) {4 console.log(err);5 } else {6 console.log(result);7 }8});9var DeviceFarmer = require('devicefarmer-stf-client');10deviceFarmer.getGroup('testgroup', function(err, result) {11 if (err) {12 console.log(err);13 } else {14 console.log(result);15 }16});17var DeviceFarmer = require('devicefarmer-stf-client');18deviceFarmer.deleteGroup('testgroup', function(err, result) {19 if (err) {20 console.log(err);21 } else {22 console.log(result);23 }24});25var DeviceFarmer = require('devicefarmer-stf-client');26deviceFarmer.addDeviceToGroup('testgroup', 'device1', function(err, result) {27 if (err) {28 console.log(err);29 } else {30 console.log(result);31 }32});33var DeviceFarmer = require('devicefarmer-stf-client');34deviceFarmer.removeDeviceFromGroup('testgroup', 'device1', function(err, result) {35 if (err) {36 console.log(err);37 } else {38 console.log(result);39 }40});
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var Device = stf.Device;3var device = new Device();4device.initGroup();5console.log('done');6var stf = require('devicefarmer-stf');7var Device = stf.Device;8var device = new Device();9device.initGroup();10console.log('done');11var stf = require('devicefarmer-stf');12var Device = stf.Device;13var device = new Device();14device.initGroup();15console.log('done');16var stf = require('devicefarmer-stf');17var Device = stf.Device;18var device = new Device();19device.initGroup();20console.log('done');21var stf = require('devicefarmer-stf');22var Device = stf.Device;23var device = new Device();24device.initGroup();25console.log('done');26var stf = require('devicefarmer-stf');27var Device = stf.Device;28var device = new Device();29device.initGroup();30console.log('done');31var stf = require('devicefarmer-stf');32var Device = stf.Device;33var device = new Device();34device.initGroup();35console.log('done');36var stf = require('devicefarmer-stf');37var Device = stf.Device;38var device = new Device();39device.initGroup();40console.log('done');41var stf = require('devicefarmer-stf');42var Device = stf.Device;43var device = new Device();44device.initGroup();45console.log('done');
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var device = new stf.Device();3device.initGroup('test');4var stf = require('devicefarmer-stf');5var device = new stf.Device();6device.initGroup('test');7var stf = require('devicefarmer-stf');8var device = new stf.Device();9device.initGroup('test');10var stf = require('devicefarmer-stf');11var device = new stf.Device();12device.initGroup('test');13var stf = require('devicefarmer-stf');14var device = new stf.Device();15device.initGroup('test');16var stf = require('devicefarmer-stf');17var device = new stf.Device();18device.initGroup('test');
Using AI Code Generation
1var stf = require('devicefarmer-stf');2device.initGroup('testGroup').then(function (data) {3 console.log(data);4});5var stf = require('devicefarmer-stf');6device.initDevice('testDevice').then(function (data) {7 console.log(data);8});9var stf = require('devicefarmer-stf');10device.initDevice('testDevice').then(function (data) {11 console.log(data);12});13var stf = require('devicefarmer-stf');14device.getDevices().then(function (data) {15 console.log(data);16});17var stf = require('devicefarmer-stf');18device.getDevice('testDevice').then(function (data) {19 console.log(data);20});21var stf = require('devicefarmer-stf');22device.getGroups().then(function (data) {23 console.log(data);24});25var stf = require('devicefarmer-stf');26device.getGroup('testGroup').then(function (data) {27 console.log(data);28});29var stf = require('devicefarmer-stf');30device.getDevicesInGroup('testGroup').then(function (data) {31 console.log(data);32});33var stf = require('devicefarmer-stf');
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!