Best JavaScript code snippet using playwright-internal
constructCriteria.js
Source:constructCriteria.js
1import React from "react";2import { useState } from "react";3import { useEffect } from "react";4import Grid from "@material-ui/core/Grid";5import Controls from "./../../controls/Controls";6import Button from "@material-ui/core/Button";7import auth from "../../auth/auth-helper";8import Typography from "@material-ui/core/Typography";9import Icon from "@material-ui/core/Icon";10import { makeStyles } from "@material-ui/core/styles";11import { useCriteria, useCriteriaDispatch } from "../../contexts/CriteriaContext";12import { useAccess, } from "../../contexts/AccessContext";13import Popup from "../../components/shared/Popup";14import {myClassOptions,subjectOptions,ageRangeOptions,difficultyLevelOptions,categoryOptions} from "../../lookupOptions/CriteriaOptions"15import ApplyOptionsForm from "../../components/shared/ApplyOptionsForm"16import Notification from "../../components/shared/Notification";17const useStyles = makeStyles((theme) => ({18 root: {19 flexGrow: 1,20 marginTop: theme.spacing(2),21 margin: theme.spacing(2),22 },23 paper: {24 padding: theme.spacing(2),25 textAlign: "center",26 color: theme.palette.text.secondary,27 },28 error: {29 verticalAlign: "middle",30 },31 title: {32 marginTop: theme.spacing(2),33 color: theme.palette.openTitle,34 },35 textField: {36 marginLeft: theme.spacing(2),37 marginRight: theme.spacing(2),38 defaultValue: "Small",39 variant: "outlined",40 size: "small",41 },42 container: {43 paddingTop: theme.spacing(1),44 paddingBottom: theme.spacing(1),45 outerColumn: {46 borderRight: "1px solid grey",47 borderBottom: "1px solid grey",48 borderLeft: "1px solid grey"49 },50 centerColumn: {51 borderBottom: "1px solid grey"52 }53 },54 gridWrapper: {55 border: "1px solid grey",56 display: "grid",57 backgroundColor: "grey",58 gridRowGap: 1,59 gridColumnGap: 1,60 gridTemplateAreas: `61 "title title title"62 "a1 a2 a3"63 "b1 b2 b3"64 "c1 c2 c3"65 `,66 gridTemplateColumns: "repeat(3, minmax(0, 1fr))",67 "& > *": {68 backgroundColor: "white"69 }70 },71 submit: {72 marginLeft: theme.spacing(4),73 marginRight: theme.spacing(2),74 marginBottom: theme.spacing(2),75 direction: "column",76 position: "center",77 variant: "outlined",78 size: "small",79 },80 input: {81 display: "none",82 padding: "10px 14px",83 },84 filename: {85 marginLeft: "2px",86 },87}));88const Container = (props) => (89 <Grid container justify="space-around" {...props} />90);91const Item = (props) => <Grid item xs={12} {...props} />;92export default function ConstructCriteria(props) {93 const {94 selected,95 setSelected,96 updateConstructLineItem,97 constructLineItems,98 checkCurrentCriteria,99 okToUpdate,100 } = props;101 const classes = useStyles();102 const currentCriteria = useCriteria();103 const currentAccess = useAccess();104 const [openPopup, setOpenPopup] = useState(false);105 const [applyOptions, setApplyOptions] = useState({106 isUpdateListing: true,107 isUpdateSelectedRecords: false,108 isUpdateAllListedRecords: false,109 });110 const [notify, setNotify] = useState({111 isOpen: false,112 message: "",113 type: "",114 });115 const [values, setValues] = useState({116 myClass: currentCriteria.myClass ? currentCriteria.myClass : "", 117 category: currentCriteria.category ? currentCriteria.category : "", 118 subject: currentCriteria.subject ? currentCriteria.subject : "", 119 difficultyLevel: currentCriteria.difficultyLevel120 ? currentCriteria.difficultyLevel121 : 7, 122 ageRange: currentCriteria.ageRange ? currentCriteria.ageRange : 2, 123 topic: currentCriteria.topic ? currentCriteria.topic : "",124 });125 const [errors, setErrors] = useState({});126 const handleInputChange = e => {127 const name = e.target.name;128 const value = e.target.value;129 setValues({130 ...values,131 [name]: value132 })133 }134 useEffect(() => {135 const abortController = new AbortController();136 const signal = abortController.signal;137 console.log(138 "constructCriteria - inside useEffect() to reset values to currentCriteria = ", currentCriteria139 );140 141 if (currentCriteria != undefined && currentCriteria != null)142 {143 setValues({144 myClass: currentCriteria.myClass,145 category: currentCriteria.category,146 subject: currentCriteria.subject,147 difficultyLevel: currentCriteria.difficultyLevel,148 ageRange: currentCriteria.ageRange,149 topic: currentCriteria.topic,150 });151 }152 return function cleanup() {153 abortController.abort();154 };155 156 }, [currentCriteria]);157 useEffect(() => {158 const abortController = new AbortController();159 const signal = abortController.signal;160 console.log(161 "constructCriteria - after return from popup useEffect applyOptions.isUpdateListing = ", applyOptions.isUpdateListing );162 console.log(163 "constructCriteria - after return from popup useEffect applyOptions.isUpdateSelectedRecords = ", applyOptions.isUpdateSelectedRecords );164 console.log(165 "constructCriteria - after return from popup useEffect applyOptions.isUpdateAllListedRecords = ", applyOptions.isUpdateAllListedRecords );166 console.log("constructCriteria - after return from popup useEffect Criteria values = ", values );167 if (values != undefined && values != null )168 {169 if (170 ((values.myClass != null &&171 values.category != null &&172 values.subject != null &&173 values.difficultyLevel != null &&174 values.ageRange != null ) 175 &&176 (177 values.myClass.length != 0 &&178 values.category.length != 0 &&179 values.subject.length != 0 &&180 values.difficultyLevel.length != 0 &&181 values.ageRange.length != 0 ))182 )183 {184 if (applyOptions.isUpdateAllListedRecords === true)185 {186 console.log("constructCriteria - applyOptions.isUpdateAllListedRecords === true" );187 updateCriteriaOfAllConstructLineItemsInList();188 } else if (applyOptions.isUpdateSelectedRecords === true)189 {190 console.log("constructCriteria -applyOptions.isUpdateSelectedRecords === true" );191 updateCriteriaOfSelectedConstructLineItems();192 } 193 } else194 {195 if (applyOptions.isUpdateAllListedRecords === true || applyOptions.isUpdateSelectedRecords === true) 196 {197 setNotify({198 isOpen: true,199 message: "No Updates made - All Criteria must be defined to update Records!",200 type: "error",201 });202 }203 }204 }205 checkCurrentCriteria(values);206 console.log(207 "constructCriteria - after return from popup useEffect applyOptions.isUpdateListing = ", applyOptions.isUpdateListing );208 return function cleanup() {209 abortController.abort();210 };211 }, [applyOptions]);212 const findMatchingIndex = (search_id) => {213 var index = -1;214 console.log("constructCriteria - search_id = ", search_id);215 for (var i = 0; i < constructLineItems.length; i++) {216 console.log(217 "constructCriteria - constructLineItems[i]._id = ",218 constructLineItems[i]._id219 );220 if (constructLineItems[i]._id == search_id) {221 index = i;222 break;223 }224 }225 return index;226 };227 const updateCriteriaOfAllConstructLineItemsInList = () => {228 console.log(229 "updateCriteriaOfAllConstructLineItemsInList - Inside updateCriteriaOfAllConstructLineItemsInList + before loop to update records");230 console.log(231 "updateCriteriaOfSelectedConstructLineItems - constructLineItems = ", constructLineItems)232 const lastIndexToUpdate = constructLineItems.length -1;233 for (let i = 0; i < constructLineItems.length; i++) {234 updateConstructLineItem(i, false, lastIndexToUpdate, values, currentAccess);235 }236 };237 238 const updateCriteriaOfSelectedConstructLineItems = () =>239 {240 console.log(241 "updateCriteriaOfSelectedConstructLineItems - Inside updateCriteriaOfSelectedConstructLineItems + before loop to update records");242 console.log(243 "updateCriteriaOfSelectedConstructLineItems - selected = ", selected)244 const lastIndexToUpdate = selected.length-1;245 selected.forEach(id => 246 {247 console.log(id)248 let indexToUpdate = findMatchingIndex(id);249 if (indexToUpdate >=0)250 {251 updateConstructLineItem(indexToUpdate,false, lastIndexToUpdate, values, currentAccess);252 } 253 });254 setSelected([]);255 }256 const clickSubmit = () => {257 console.log(258 "constructCriteria - submit clicked before currentCriteria values = ",259 values260 );261 setOpenPopup(true);262 };263 return (264 <>265 <div className={classes.root}>266 <Container spacing={2} justify="center" className={classes.container}>267 <Item xs={12}>268 <div>Filter Criteria (Entry Tags)</div>269 </Item>270 <Item item xs={12} >271 <Controls.Select272 name="myClass"273 label="Class"274 classes={classes}275 value={values.myClass}276 onChange={handleInputChange}277 options={myClassOptions}278 error={errors.myClass}279 />280 </Item>281 <Item item xs={12} >282 <Controls.Select283 name="category"284 label="Category"285 value={values.category}286 onChange={handleInputChange}287 options={categoryOptions}288 error={errors.category}289 />290 </Item>291 <Item item xs={12} >292 <Controls.Select293 name="subject"294 label="Subject"295 value={values.subject}296 onChange={handleInputChange}297 options={subjectOptions}298 error={errors.subject}299 />300 </Item>301 <Item item xs={12} >302 <Controls.Select303 name="difficultyLevel"304 label="Difficulty Level"305 value={values.difficultyLevel}306 onChange={handleInputChange}307 options={difficultyLevelOptions}308 error={errors.difficultyLevel}309 />310 </Item>311 <Item item xs={12} >312 <Controls.Select313 name="ageRange"314 label="Age Range"315 value={values.ageRange}316 onChange={handleInputChange}317 options={ageRangeOptions}318 error={errors.ageRange}319 />320 </Item>321 <Item item xs={12}>322 <Controls.Input323 name="topic"324 label="Topic"325 value={values.topic}326 onChange={handleInputChange}327 error={errors.topic}328 />329 </Item>330 <Item xs={12}>331 <Button332 variant="contained"333 size="large"334 color="secondary"335 onClick={clickSubmit}336 className={classes.submit}337 disabled = {okToUpdate?false:true}338 >339 Apply Criteria340 </Button>341 342 </Item>343 <Item xs={12}>344 {values.error && (345 <Typography component="p" color="error">346 <Icon color="error" className={classes.error}>347 error348 </Icon>349 {values.error}350 </Typography>351 )}352 </Item>353 </Container>354 </div>355 <Popup356 title="Check boxes to indicate how to Apply new criteria - Disable options as pre-selected"357 openPopup={openPopup}358 setOpenPopup={setOpenPopup}359 >360 <ApplyOptionsForm361 applyOptions={applyOptions}362 setApplyOptions={setApplyOptions}363 openPopup={openPopup}364 setOpenPopup={setOpenPopup}365 />366 </Popup>367 <Notification notify={notify} setNotify={setNotify} />368 </>369 );...
frameworkCriteria.js
Source:frameworkCriteria.js
1import React from "react";2import { useState } from "react";3import { useEffect } from "react";4import Grid from "@material-ui/core/Grid";5import Controls from "./../../controls/Controls";6import Button from "@material-ui/core/Button";7import auth from "../../auth/auth-helper";8import Typography from "@material-ui/core/Typography";9import Icon from "@material-ui/core/Icon";10import { makeStyles } from "@material-ui/core/styles";11import { useCriteria } from "../../contexts/CriteriaContext";12import { useAccess, } from "../../contexts/AccessContext";13import Popup from "../../components/shared/Popup";14import {myClassOptions,subjectOptions,ageRangeOptions,difficultyLevelOptions,categoryOptions} from "../../lookupOptions/CriteriaOptions"15import ApplyOptionsForm from "../../components/shared/ApplyOptionsForm"16import Notification from "../../components/shared/Notification";17const useStyles = makeStyles((theme) => ({18 root: {19 flexGrow: 1,20 marginTop: theme.spacing(2),21 margin: theme.spacing(2),22 },23 error: {24 verticalAlign: "middle",25 },26 container: {27 paddingTop: theme.spacing(1),28 paddingBottom: theme.spacing(1),29 outerColumn: {30 borderRight: "1px solid grey",31 borderBottom: "1px solid grey",32 borderLeft: "1px solid grey"33 },34 centerColumn: {35 borderBottom: "1px solid grey"36 }37 },38 39 submit: {40 marginLeft: theme.spacing(4),41 marginRight: theme.spacing(2),42 marginBottom: theme.spacing(2),43 direction: "column",44 position: "center",45 variant: "outlined",46 size: "small",47 },48}));49const Container = (props) => (50 <Grid container justify="space-around" {...props} />51);52const Item = (props) => <Grid item xs={12} {...props} />;53export default function FrameworkCriteria(props) {54 const {55 selected,56 setSelected,57 updateFrameworkLineItem,58 frameworkLineItems,59 checkCurrentCriteria,60 okToUpdate,61 } = props;62 63 const classes = useStyles();64 const currentCriteria = useCriteria();65 const currentAccess = useAccess();66 const [openPopup, setOpenPopup] = useState(false);67 const [applyOptions, setApplyOptions] = useState({68 isUpdateListing: true,69 isUpdateSelectedRecords: false,70 isUpdateAllListedRecords: false,71 });72 const jwt = auth.isAuthenticated();73 const userId = jwt.user._id;74 const [notify, setNotify] = useState({75 isOpen: false,76 message: "",77 type: "",78 });79 const [values, setValues] = useState({80 myClass: currentCriteria.myClass ? currentCriteria.myClass : "Academic", //"Comedy",81 category: currentCriteria.category ? currentCriteria.category : "Mixed", //"Basic Reading",82 subject: currentCriteria.subject ? currentCriteria.subject : "Other", //"Reading",83 difficultyLevel: currentCriteria.difficultyLevel84 ? currentCriteria.difficultyLevel85 : 27, //"General",86 ageRange: currentCriteria.ageRange ? currentCriteria.ageRange : 6, //"All Ages",87 topic: currentCriteria.topic ? currentCriteria.topic : "",88 });89 const [errors, setErrors] = useState({});90 const handleInputChange = e => {91 const name = e.target.name;92 const value = e.target.value;93 setValues({94 ...values,95 [name]: value96 })97 }98 useEffect(() => {99 const abortController = new AbortController();100 const signal = abortController.signal;101 console.log(102 "frameworkCriteria - inside useEffect() to reset values to currentCriteria = ", currentCriteria103 );104 105 if (currentCriteria != undefined && currentCriteria != null)106 {107 setValues({108 myClass: currentCriteria.myClass,109 category: currentCriteria.category,110 subject: currentCriteria.subject,111 difficultyLevel: currentCriteria.difficultyLevel,112 ageRange: currentCriteria.ageRange,113 topic: currentCriteria.topic,114 });115 }116 return function cleanup() {117 abortController.abort();118 };119 120 }, [currentCriteria]);121 useEffect(() => {122 const abortController = new AbortController();123 const signal = abortController.signal;124 console.log(125 "frameworkCriteria - after return from popup useEffect applyOptions.isUpdateListing = ", applyOptions.isUpdateListing );126 console.log(127 "frameworkCriteria - after return from popup useEffect applyOptions.isUpdateSelectedRecords = ", applyOptions.isUpdateSelectedRecords );128 console.log(129 "frameworkCriteria - after return from popup useEffect applyOptions.isUpdateAllListedRecords = ", applyOptions.isUpdateAllListedRecords );130 console.log("frameworkCriteria - after return from popup useEffect Criteria values = ", values );131 if (values != undefined && values != null )132 {133 if (134 ((values.myClass != null &&135 values.category != null &&136 values.subject != null &&137 values.difficultyLevel != null &&138 values.ageRange != null ) 139 &&140 (141 values.myClass.length != 0 &&142 values.category.length != 0 &&143 values.subject.length != 0 &&144 values.difficultyLevel.length != 0 &&145 values.ageRange.length != 0 ))146 )147 {148 if (applyOptions.isUpdateAllListedRecords === true)149 {150 console.log("frameworkCriteria - applyOptions.isUpdateAllListedRecords === true" );151 updateCriteriaOfAllFrameworkLineItemsInList();152 } else if (applyOptions.isUpdateSelectedRecords === true)153 {154 console.log("frameworkCriteria -applyOptions.isUpdateSelectedRecords === true" );155 updateCriteriaOfSelectedFrameworkLineItems();156 } 157 } else158 {159 if (applyOptions.isUpdateAllListedRecords === true || applyOptions.isUpdateSelectedRecords === true) 160 {161 setNotify({162 isOpen: true,163 message: "No Updates made - All Criteria must be defined to update Records!",164 type: "error",165 });166 }167 }168 }169 checkCurrentCriteria(values);170 console.log(171 "frameworkCriteria - after return from popup useEffect applyOptions.isUpdateListing = ", applyOptions.isUpdateListing );172 return function cleanup() {173 abortController.abort();174 };175 }, [applyOptions]);176 const findMatchingIndex = (search_id) => {177 var index = -1;178 console.log("frameworkCriteria - search_id = ", search_id);179 for (var i = 0; i < frameworkLineItems.length; i++) {180 console.log(181 "frameworkCriteria - frameworkLineItems[i]._id = ",182 frameworkLineItems[i]._id183 );184 if (frameworkLineItems[i]._id == search_id) {185 index = i;186 break;187 }188 }189 return index;190 };191 const updateCriteriaOfAllFrameworkLineItemsInList = () => {192 console.log(193 "updateCriteriaOfAllFrameworkLineItemsInList - Inside updateCriteriaOfAllFrameworkLineItemsInList + before loop to update records");194 console.log(195 "updateCriteriaOfSelectedFrameworkLineItems - frameworkLineItems = ", frameworkLineItems)196 const lastIndexToUpdate = frameworkLineItems.length -1;197 for (let i = 0; i < frameworkLineItems.length; i++) {198 updateFrameworkLineItem(i, false, lastIndexToUpdate, values, currentAccess);199 }200 };201 202 const updateCriteriaOfSelectedFrameworkLineItems = () =>203 {204 console.log(205 "updateCriteriaOfSelectedFrameworkLineItems - Inside updateCriteriaOfSelectedFrameworkLineItems + before loop to update records");206 console.log(207 "updateCriteriaOfSelectedFrameworkLineItems - selected = ", selected)208 const lastIndexToUpdate = selected.length-1;209 selected.forEach(id => 210 {211 console.log(id)212 let indexToUpdate = findMatchingIndex(id);213 if (indexToUpdate >=0)214 {215 updateFrameworkLineItem(indexToUpdate,false, lastIndexToUpdate, values, currentAccess);216 } 217 });218 setSelected([]);219 }220 const clickSubmit = () => {221 console.log(222 "frameworkCriteria - submit clicked before currentCriteria values = ",223 values224 );225 setOpenPopup(true);226 };227 return (228 <>229 <div className={classes.root}>230 <Container spacing={2} justify="center" className={classes.container}>231 <Item xs={12}>232 <div>Filter Criteria (Entry Tags)</div>233 </Item>234 <Item item xs={12} >235 <Controls.Select236 name="myClass"237 label="Class"238 classes={classes}239 value={values.myClass}240 onChange={handleInputChange}241 options={myClassOptions}242 error={errors.myClass}243 />244 </Item>245 <Item item xs={12} >246 <Controls.Select247 name="category"248 label="Category"249 value={values.category}250 onChange={handleInputChange}251 options={categoryOptions}252 error={errors.category}253 />254 </Item>255 <Item item xs={12} >256 <Controls.Select257 name="subject"258 label="Subject"259 value={values.subject}260 onChange={handleInputChange}261 options={subjectOptions}262 error={errors.subject}263 />264 </Item>265 <Item item xs={12} >266 <Controls.Select267 name="difficultyLevel"268 label="Difficulty Level"269 value={values.difficultyLevel}270 onChange={handleInputChange}271 options={difficultyLevelOptions}272 error={errors.difficultyLevel}273 />274 </Item>275 <Item item xs={12} >276 <Controls.Select277 name="ageRange"278 label="Age Range"279 value={values.ageRange}280 onChange={handleInputChange}281 options={ageRangeOptions}282 error={errors.ageRange}283 />284 </Item>285 <Item item xs={12}>286 <Controls.Input287 name="topic"288 label="Topic"289 value={values.topic}290 onChange={handleInputChange}291 error={errors.topic}292 />293 </Item>294 <Item xs={12}> 295 <Controls.Button296 text="Apply Criteria"297 variant="contained"298 color = "secondary"299 onClick={clickSubmit}300 className={classes.submit}301 disabled = {okToUpdate?false:true}302 />303 </Item>304 <Item xs={12}>305 {values.error && (306 <Typography component="p" color="error">307 <Icon color="error" className={classes.error}>308 error309 </Icon>310 {values.error}311 </Typography>312 )}313 </Item>314 </Container>315 </div>316 <Popup317 title="Check boxes to indicate how to Apply new criteria - Disable options as pre-selected"318 openPopup={openPopup}319 setOpenPopup={setOpenPopup}320 >321 <ApplyOptionsForm322 applyOptions={applyOptions}323 setApplyOptions={setApplyOptions}324 openPopup={openPopup}325 setOpenPopup={setOpenPopup}326 />327 </Popup>328 <Notification notify={notify} setNotify={setNotify} />329 </>330 );...
frameworkAccess.js
Source:frameworkAccess.js
1import React from "react";2import { useState } from "react";3import { useEffect } from "react";4import Grid from "@material-ui/core/Grid";5import Button from "@material-ui/core/Button";6import Typography from "@material-ui/core/Typography";7import Icon from "@material-ui/core/Icon";8import FormControlLabel from "@material-ui/core/FormControlLabel";9import Checkbox from "@material-ui/core/Checkbox";10import { makeStyles } from "@material-ui/core/styles";11import { useAccess } from "../../contexts/AccessContext";12import Controls from "./../../controls/Controls";13import { useCriteria } from "../../contexts/CriteriaContext";14import Popup from "../../components/shared/Popup";15import ApplyOptionsForm from "../../components/shared/ApplyOptionsForm"16const useStyles = makeStyles((theme) => ({17 root: {18 flexGrow: 1,19 },20 paper: {21 padding: theme.spacing(2),22 textAlign: "center",23 color: theme.palette.text.secondary,24 },25 error: {26 verticalAlign: "middle",27 },28 title: {29 marginTop: theme.spacing(2),30 color: theme.palette.openTitle,31 },32 textField: {33 marginLeft: theme.spacing(2),34 marginRight: theme.spacing(2),35 defaultValue: "Small",36 variant: "outlined",37 size: "small",38 },39 container: {40 paddingTop: theme.spacing(1),41 paddingBottom: theme.spacing(1),42 outerColumn: {43 borderRight: "1px solid grey",44 borderBottom: "1px solid grey",45 borderLeft: "1px solid grey"46 },47 centerColumn: {48 borderBottom: "1px solid grey"49 }50 },51 gridWrapper: {52 border: "1px solid grey",53 display: "grid",54 backgroundColor: "grey",55 gridRowGap: 1,56 gridColumnGap: 1,57 gridTemplateAreas: `58 "title title title"59 "a1 a2 a3"60 "b1 b2 b3"61 "c1 c2 c3"62 `,63 gridTemplateColumns: "repeat(3, minmax(0, 1fr))",64 "& > *": {65 backgroundColor: "white"66 }67 },68 submit: {69 marginLeft: theme.spacing(4),70 marginRight: theme.spacing(2),71 marginBottom: theme.spacing(2),72 direction: "column",73 position: "center",74 variant: "outlined",75 size: "small",76 },77 input: {78 display: "none",79 },80 filename: {81 marginLeft: "2px",82 },83}));84const Container = (props) => (85 <Grid container justify="space-around" {...props} />86);87const Item = (props) => <Grid item xs={12} {...props} />;88export default function FrameworkAccess(props) {89 const {90 selected,91 setSelected,92 updateFrameworkLineItem,93 frameworkLineItems,94 groupsUserOwns,95 setGroupsUserOwns,96 okToUpdate,97 } = props;98 const classes = useStyles();99 const currentAccess = useAccess();100 const currentCriteria = useCriteria();101 const [openPopup, setOpenPopup] = useState(false);102 const [applyOptions, setApplyOptions] = useState({103 isUpdateListing: false,104 isUpdateSelectedRecords: false,105 isUpdateAllListedRecords: false,106 });107 const [values, setValues] = useState({108 keepPrivate: (currentAccess.keepPrivate != undefined && currentAccess.keepPrivate != null) ? currentAccess.keepPrivate : true,109 approvedForPublicUse: (currentAccess.approvedForPublicUse != undefined && currentAccess.approvedForPublicUse != null) ? currentAccess.approvedForPublicUse : false,110 group_id: currentAccess.group_id ? currentAccess.group_id : "",111 });112 console.log("frameworkAccess - right after values set ");113 const handleInputChange = e => {114 const name = e.target.name;115 const value = e.target.value;116 setValues({117 ...values,118 [name]: value119 })120 }121 useEffect(() => {122 const abortController = new AbortController();123 const signal = abortController.signal;124 console.log(125 "FrameworkAccess - inside useEffect()after currentAccess Set "126 );127 if (currentAccess != undefined && currentAccess != null)128 {129 setValues({130 keepPrivate: (currentAccess.keepPrivate != undefined && currentAccess.keepPrivate != null) ? currentAccess.keepPrivate : true,131 approvedForPublicUse: (currentAccess.approvedForPublicUse != undefined && currentAccess.approvedForPublicUse != null) ? currentAccess.approvedForPublicUse : false,132 group_id: currentAccess.group_id ? currentAccess.group_id : "",133 });134 } 135 return function cleanup() {136 abortController.abort();137 };138 }, [currentAccess]);139 useEffect(() => {140 const abortController = new AbortController();141 const signal = abortController.signal;142 console.log(143 "frameworkAccess - after return from popup useEffect applyOptions.isUpdateListing = ", applyOptions.isUpdateListing );144 console.log(145 "frameworkAccess - after return from popup useEffect applyOptions.isUpdateSelectedRecords = ", applyOptions.isUpdateSelectedRecords );146 console.log(147 "frameworkAccess - after return from popup useEffect applyOptions.isUpdateAllListedRecords = ", applyOptions.isUpdateAllListedRecords );148 if (applyOptions.isUpdateAllListedRecords === true)149 {150 console.log("frameworkAccess - applyOptions.isUpdateAllListedRecords === true" );151 updateAccessOfAllFrameworkLineItemsInList();152 } else if (applyOptions.isUpdateSelectedRecords === true)153 {154 console.log("frameworkAccess -applyOptions.isUpdateSelectedRecords === true" );155 updateAccessOfSelectedFrameworkLineItems();156 }157 158 return function cleanup() {159 abortController.abort();160 };161 }, [applyOptions]);162 const findMatchingIndex = (search_id) => {163 var index = -1;164 console.log("frameworkAccess - search_id = ", search_id);165 for (var i = 0; i < frameworkLineItems.length; i++) {166 console.log(167 "frameworkAccess - frameworkLineItems[i]._id = ",168 frameworkLineItems[i]._id169 );170 if (frameworkLineItems[i]._id == search_id) {171 index = i;172 break;173 }174 }175 return index;176 };177 const updateAccessOfAllFrameworkLineItemsInList = () => {178 console.log(179 "updateAccessOfCurrentStatement - Inside updateAccessOfAllFrameworkLineItemsInList + before loop to update records");180 const lastIndexToUpdate = frameworkLineItems.length -1;181 for (let i = 0; i < frameworkLineItems.length; i++) {182 updateFrameworkLineItem(i, false, lastIndexToUpdate, currentCriteria, values);183 }184 };185 186 const updateAccessOfSelectedFrameworkLineItems = () =>187 {188 console.log(189 "updateAccessOfSelectedFrameworkLineItems - Inside updateAccessOfSelectedFrameworkLineItems + before loop to update records");190 191 const lastIndexToUpdate = selected.length-1;192 selected.forEach(id => 193 {194 console.log(id)195 let indexToUpdate = findMatchingIndex(id);196 if (indexToUpdate >=0)197 {198 updateFrameworkLineItem(indexToUpdate, false, lastIndexToUpdate, currentCriteria, values);199 } 200 });201 setSelected([]);202 }203 const clickSubmit = () => {204 console.log(205 "frameworkAccess - submit clicked values before values = ",206 values207 );208 setOpenPopup(true);209 };210 return (211 <>212 <div className={classes.root}>213 <Container spacing={1} justify="center" className={classes.container}>214 <Item xs={12}>215 <div> Access Options</div>216 </Item>217 <Item xs={3}>218 <Button219 variant="contained"220 size="large"221 color="secondary"222 onClick={clickSubmit} 223 className={classes.submit} 224 disabled = {okToUpdate?false:true} 225 >226 Apply Access227 </Button>228 </Item>229 230 <Item xs={3}>231 <Controls.Checkbox232 name="keepPrivate"233 label="Keep Private"234 value={values.keepPrivate}235 onChange={handleInputChange}236 />237 </Item>238 <Item xs={3}>239 <Controls.Select240 name="group_id"241 label="Name of Group With Access"242 classes={classes}243 value={values.group_id}244 onChange={handleInputChange}245 options={groupsUserOwns}246 />247 </Item>248 <Item xs={3}>249 <FormControlLabel250 disabled251 control={252 <Checkbox253 checked={values.approvedPublicReadAccess}254 name="approvedPublicReadAccess"255 color="primary"256 />257 }258 label="Approved for Public Access"259 />260 </Item>261 <Item xs={12}>262 {values.error && (263 <Typography component="p" color="error">264 <Icon color="error" className={classes.error}>265 error266 </Icon>267 {values.error}268 </Typography>269 )}270 </Item>271 </Container>272 </div>273 <Popup274 title="Check boxes to indicate how to Apply new access - Disable options as pre-selected"275 openPopup={openPopup}276 setOpenPopup={setOpenPopup}277 >278 <ApplyOptionsForm279 applyOptions={applyOptions}280 setApplyOptions={setApplyOptions}281 openPopup={openPopup}282 setOpenPopup={setOpenPopup}283 />284 </Popup>285 </>286 );...
constructAccess.js
Source:constructAccess.js
1import React from "react";2import { useState } from "react";3import { useEffect } from "react";4import Grid from "@material-ui/core/Grid";5import Button from "@material-ui/core/Button";6import Typography from "@material-ui/core/Typography";7import Icon from "@material-ui/core/Icon";8import FormControlLabel from "@material-ui/core/FormControlLabel";9import Checkbox from "@material-ui/core/Checkbox";10import { makeStyles } from "@material-ui/core/styles";11import { useAccess } from "../../contexts/AccessContext";12import Controls from "./../../controls/Controls";13import { useCriteria } from "../../contexts/CriteriaContext";14import Popup from "../../components/shared/Popup";15import ApplyOptionsForm from "../../components/shared/ApplyOptionsForm"16const useStyles = makeStyles((theme) => ({17 root: {18 flexGrow: 1,19 },20 paper: {21 padding: theme.spacing(2),22 textAlign: "center",23 color: theme.palette.text.secondary,24 },25 error: {26 verticalAlign: "middle",27 },28 title: {29 marginTop: theme.spacing(2),30 color: theme.palette.openTitle,31 },32 textField: {33 marginLeft: theme.spacing(2),34 marginRight: theme.spacing(2),35 defaultValue: "Small",36 variant: "outlined",37 size: "small",38 },39 container: {40 paddingTop: theme.spacing(1),41 paddingBottom: theme.spacing(1),42 outerColumn: {43 borderRight: "1px solid grey",44 borderBottom: "1px solid grey",45 borderLeft: "1px solid grey"46 },47 centerColumn: {48 borderBottom: "1px solid grey"49 }50 },51 gridWrapper: {52 border: "1px solid grey",53 display: "grid",54 backgroundColor: "grey",55 gridRowGap: 1,56 gridColumnGap: 1,57 gridTemplateAreas: `58 "title title title"59 "a1 a2 a3"60 "b1 b2 b3"61 "c1 c2 c3"62 `,63 gridTemplateColumns: "repeat(3, minmax(0, 1fr))",64 "& > *": {65 backgroundColor: "white"66 }67 },68 submit: {69 marginLeft: theme.spacing(4),70 marginRight: theme.spacing(2),71 marginBottom: theme.spacing(2),72 direction: "column",73 position: "center",74 variant: "outlined",75 size: "small",76 },77 input: {78 display: "none",79 },80 filename: {81 marginLeft: "2px",82 },83}));84const Container = (props) => (85 <Grid container justify="space-around" {...props} />86);87const Item = (props) => <Grid item xs={12} {...props} />;88export default function ConstructAccess(props) {89 const {90 selected,91 setSelected,92 updateConstructLineItem,93 constructLineItems,94 groupsUserOwns,95 } = props;96 const classes = useStyles();97 const currentAccess = useAccess();98 const currentCriteria = useCriteria();99 const [openPopup, setOpenPopup] = useState(false);100 const [applyOptions, setApplyOptions] = useState({101 isUpdateListing: false,102 isUpdateSelectedRecords: false,103 isUpdateAllListedRecords: false,104 });105 const [values, setValues] = useState({106 keepPrivate: (currentAccess.keepPrivate != undefined && currentAccess.keepPrivate != null) ? currentAccess.keepPrivate : true,107 approvedForPublicUse: (currentAccess.approvedForPublicUse != undefined && currentAccess.approvedForPublicUse != null) ? currentAccess.approvedForPublicUse : false,108 group_id: currentAccess.group_id ? currentAccess.group_id : "",109 });110 console.log("constructAccess - right after values set ");111 const handleInputChange = e => {112 const name = e.target.name;113 const value = e.target.value;114 setValues({115 ...values,116 [name]: value117 })118 }119 useEffect(() => {120 const abortController = new AbortController();121 const signal = abortController.signal;122 console.log(123 "ConstructAccess - inside useEffect()after currentAccess Set "124 );125 if (currentAccess != undefined && currentAccess != null)126 {127 setValues({128 keepPrivate: (currentAccess.keepPrivate != undefined && currentAccess.keepPrivate != null) ? currentAccess.keepPrivate : true,129 approvedForPublicUse: (currentAccess.approvedForPublicUse != undefined && currentAccess.approvedForPublicUse != null) ? currentAccess.approvedForPublicUse : false,130 group_id: currentAccess.group_id ? currentAccess.group_id : "",131 });132 } 133 return function cleanup() {134 abortController.abort();135 };136 }, [currentAccess]);137 useEffect(() => {138 const abortController = new AbortController();139 const signal = abortController.signal;140 console.log(141 "constructAccess - after return from popup useEffect applyOptions.isUpdateListing = ", applyOptions.isUpdateListing );142 console.log(143 "constructAccess - after return from popup useEffect applyOptions.isUpdateSelectedRecords = ", applyOptions.isUpdateSelectedRecords );144 console.log(145 "constructAccess - after return from popup useEffect applyOptions.isUpdateAllListedRecords = ", applyOptions.isUpdateAllListedRecords );146 if (applyOptions.isUpdateAllListedRecords === true)147 {148 console.log("constructAccess - applyOptions.isUpdateAllListedRecords === true" );149 updateAccessOfAllConstructLineItemsInList();150 } else if (applyOptions.isUpdateSelectedRecords === true)151 {152 console.log("constructAccess -applyOptions.isUpdateSelectedRecords === true" );153 updateAccessOfSelectedConstructLineItems();154 }155 156 return function cleanup() {157 abortController.abort();158 };159 }, [applyOptions]);160 const findMatchingIndex = (search_id) => {161 var index = -1;162 console.log("constructAccess - search_id = ", search_id);163 for (var i = 0; i < constructLineItems.length; i++) {164 console.log(165 "constructAccess - constructLineItems[i]._id = ",166 constructLineItems[i]._id167 );168 if (constructLineItems[i]._id == search_id) {169 index = i;170 break;171 }172 }173 return index;174 };175 const updateAccessOfAllConstructLineItemsInList = () => {176 console.log(177 "updateAccessOfCurrentStatement - Inside updateAccessOfAllConstructLineItemsInList + before loop to update records");178 const lastIndexToUpdate = constructLineItems.length -1;179 for (let i = 0; i < constructLineItems.length; i++) {180 updateConstructLineItem(i, false, lastIndexToUpdate, currentCriteria, values);181 }182 };183 184 const updateAccessOfSelectedConstructLineItems = () =>185 {186 console.log(187 "updateAccessOfSelectedConstructLineItems - Inside updateAccessOfSelectedConstructLineItems + before loop to update records");188 189 const lastIndexToUpdate = selected.length-1;190 selected.forEach(id => 191 {192 console.log(id)193 let indexToUpdate = findMatchingIndex(id);194 if (indexToUpdate >=0)195 {196 updateConstructLineItem(indexToUpdate, false, lastIndexToUpdate, currentCriteria, values);197 } 198 });199 setSelected([]);200 }201 const clickSubmit = () => {202 console.log(203 "constructAccess - submit clicked values before values = ",204 values205 );206 setOpenPopup(true);207 };208 return (209 <>210 <div className={classes.root}>211 <Container spacing={1} justify="center" className={classes.container}>212 <Item xs={12}>213 <div> Access Options</div>214 </Item>215 <Item xs={3}>216 <Button217 variant="contained"218 size="large"219 color="secondary"220 onClick={clickSubmit} 221 className={classes.submit} 222 >223 Apply Access224 </Button>225 </Item>226 227 <Item xs={3}>228 <Controls.Checkbox229 name="keepPrivate"230 label="Keep Private"231 value={values.keepPrivate}232 onChange={handleInputChange}233 />234 </Item>235 <Item xs={3}>236 <Controls.Select237 name="group_id"238 label="Name of Group With Access"239 classes={classes}240 value={values.group_id}241 onChange={handleInputChange}242 options={groupsUserOwns}243 />244 </Item>245 <Item xs={3}>246 <FormControlLabel247 disabled248 control={249 <Checkbox250 checked={values.approvedPublicReadAccess}251 name="approvedPublicReadAccess"252 color="primary"253 />254 }255 label="Approved for Public Access"256 />257 </Item>258 <Item xs={12}>259 {values.error && (260 <Typography component="p" color="error">261 <Icon color="error" className={classes.error}>262 error263 </Icon>264 {values.error}265 </Typography>266 )}267 </Item>268 </Container>269 </div>270 <Popup271 title="Check boxes to indicate how to Apply new access - Disable options as pre-selected"272 openPopup={openPopup}273 setOpenPopup={setOpenPopup}274 >275 <ApplyOptionsForm276 applyOptions={applyOptions}277 setApplyOptions={setApplyOptions}278 openPopup={openPopup}279 setOpenPopup={setOpenPopup}280 />281 </Popup>282 </>283 );...
methods.js
Source:methods.js
1/*----------------------------------------*\2 bcksp.es - methods.js3 @author Evrard Vincent (vincent@ogre.be)4 @Date: 2018-05-18 16:18:035 @Last Modified time: 2020-03-12 13:11:156\*----------------------------------------*/7import { Meteor } from 'meteor/meteor';8import { 9 checkValidDevice,10 checkUserLoggedIn,11 checkValidEmail,12 checkValidPassword,13 checkString,14 checkValidLanguage15} from './../../utilities/validation.js';16import { config } from './../../startup/config.js';17import { getMainEmail } from './../../utilities/meteor.js';18import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';19export const UsersPing = new ValidatedMethod({20 name: 'Users.methods.ping',21 validate({device}) {22 checkUserLoggedIn();23 checkValidDevice(device);24 },25 mixins: [RateLimiterMixin],26 rateLimit: config.methods.rateLimit.low,27 applyOptions: {28 noRetry: true,29 },30 run({device}) {31 Meteor.users.update({32 _id : Meteor.userId()33 }, {34 $set : {35 "pingAt" : new Date()36 }37 });38 }39});40export const GetLoginTokenUser = new ValidatedMethod({41 name: 'Users.methods.login.token',42 validate({device}) {43 checkUserLoggedIn();44 checkValidDevice(device);45 },46 mixins: [RateLimiterMixin],47 rateLimit: config.methods.rateLimit.low,48 applyOptions: {49 noRetry: true,50 },51 run({device}) {52 LoginLinks.setDefaultExpirationInSeconds(15); // 15 seconds53 if (!this.isSimulation) {54 return {55 success : true,56 data : LoginLinks.generateAccessToken({_id : Meteor.userId() })57 };58 }59 }60});61export const HardDisconnect = new ValidatedMethod({62 name: 'Users.methods.hard.disconnect',63 validate() {64 },65 mixins: [RateLimiterMixin],66 rateLimit: config.methods.rateLimit.low,67 applyOptions: {68 noRetry: true,69 },70 run() {71 Meteor.users.update({ 72 _id : Meteor.userId()73 }, {74 $unset : {75 "services.accessTokens.tokens" : null,76 "services.resume.loginTokens" : null77 }78 });79 const T = i18n.createTranslator("methods.user.HardDisconnect.success");80 return {81 success : true,82 message : {83 title : T("title"),84 content : T("content"),85 }86 };87 }88});89export const ResetPassword = new ValidatedMethod({90 name: 'Users.methods.reset.password',91 validate({device, email}) {92 try{93 checkUserLoggedIn();94 }catch(error){95 checkValidDevice(device);96 checkValidEmail(email, true);97 }98 },99 mixins: [RateLimiterMixin],100 rateLimit: config.methods.rateLimit.low,101 applyOptions: {102 noRetry: true,103 },104 run({email}) {105 this.unblock();106 if (this.isSimulation)return;107 let user = Meteor.user() ||Â Meteor.users.findOne({"emails.address" : email});108 Accounts.sendResetPasswordEmail(user._id, getMainEmail(user.emails));109 const T = i18n.createTranslator("methods.user.resetPassword.success");110 return {111 success : true,112 message : {113 title : T("title"),114 content : T("content")115 }116 };117 }118});119export const UpdateEmail = new ValidatedMethod({120 name: 'Users.methods.update.email',121 validate({email}) {122 checkUserLoggedIn();123 checkValidEmail(email, false, "email");124 },125 mixins: [RateLimiterMixin],126 rateLimit: config.methods.rateLimit.low,127 applyOptions: {128 noRetry: true,129 },130 run({email}) {131 if (this.isSimulation)return;132 Accounts.addEmail(Meteor.userId(), email);133 Accounts.sendVerificationEmail(Meteor.userId(), email);134 const T = i18n.createTranslator("methods.user.updateEmail.success");135 return {136 success : true,137 message : {138 title : T("title"),139 content : T("content")140 }141 };142 }143});144export const CreateUser = new ValidatedMethod({145 name: 'customCreateUser',146 validate({email, password, device}) {147 checkValidDevice(device);148 checkValidEmail(email, false);149 checkValidPassword(password, password);150 },151 mixins: [RateLimiterMixin],152 rateLimit: config.methods.rateLimit.low,153 applyOptions: {154 noRetry: true,155 },156 run({email, password}) {157 if (this.isSimulation)return;158 return Accounts.CreateUser({159 email, 160 password161 });162 }163});164export const DestroyUser = new ValidatedMethod({165 name: 'Users.methods.delete.user',166 validate() {167 checkUserLoggedIn();168 },169 mixins: [RateLimiterMixin],170 rateLimit: config.methods.rateLimit.low,171 applyOptions: {172 noRetry: true,173 },174 run() {175 if (this.isSimulation)return;176 Meteor.users.remove(Meteor.userId());177 const T = i18n.createTranslator("methods.user.deleteAccount.success");178 return {179 success : true,180 message : {181 title : T("title"),182 content : T("content")183 }184 };185 }186});187export const Login = new ValidatedMethod({188 name: 'customLogin',189 validate({email, password}) {190 checkValidDevice(device);191 checkValidEmail(email, true);192 checkValidPassword(password);193 },194 mixins: [RateLimiterMixin],195 rateLimit: config.methods.rateLimit.mid,196 applyOptions: {197 noRetry: true,198 },199 run({email, password}) {200 if (this.isSimulation)return;201 return new Promise((resolve, reject)=>{202 let user = Meteor.users.findOne({"emails.address" : email})203 let result = Accounts._checkPassword(user, password);204 if(result.error){205 reject(result.error);206 }else{207 let stampedLoginToken = Accounts._generateStampedLoginToken()208 Accounts._insertLoginToken(user._id, stampedLoginToken);209 resolve(stampedLoginToken.token);210 }211 });212 }213});214export const SetUserLang = new ValidatedMethod({215 name: 'Users.methods.user.Language.Setter',216 validate({ lang }) {217 checkUserLoggedIn();218 checkValidLanguage(lang);219 },220 mixins: [RateLimiterMixin],221 rateLimit: config.methods.rateLimit.high,222 applyOptions: {223 noRetry: true,224 },225 run({ lang }) {226 this.unblock();227 Meteor.users.update({228 _id : Meteor.userId(),229 }, {230 $set : {231 lang : lang,232 updatedAt : new Date()233 }234 });235 const T = i18n.createTranslator("methods.user.language.success");236 return {237 success : true,238 message : {239 title : T("title"),240 content : T("content")241 }242 };243 }...
resolveArgs.test.js
Source:resolveArgs.test.js
...3const targetValues = ['web', 'webworker', 'node', 'async-node', 'node-webkit', 'electron-main', 'electron-renderer', 'electron-preload'];4const cli = new webpackCLI();5describe('BasicResolver', () => {6 it('should handle the output option', async () => {7 const result = await cli.applyOptions({ options: {} }, { outputPath: './bundle' });8 expect(result.options.output.path).toEqual(resolve('bundle'));9 });10 it('should handle the mode option [production]', async () => {11 const result = await cli.applyOptions({ options: {} }, { mode: 'production' });12 expect(result.options).toMatchObject({ mode: 'production' });13 expect(result.options.mode).toEqual('production');14 });15 it('should handle the mode option [development]', async () => {16 const result = await cli.applyOptions(17 { options: {} },18 {19 mode: 'development',20 },21 );22 expect(result.options).toMatchObject({ mode: 'development' });23 expect(result.options.mode).toEqual('development');24 });25 it('should handle the mode option [none]', async () => {26 const result = await cli.applyOptions(27 { options: {} },28 {29 mode: 'none',30 },31 );32 expect(result.options).toMatchObject({ mode: 'none' });33 expect(result.options.mode).toEqual('none');34 });35 it('should prefer supplied move flag over NODE_ENV', async () => {36 process.env.NODE_ENV = 'production';37 const result = await cli.applyOptions({ options: {} }, { mode: 'development' });38 expect(result.options).toMatchObject({ mode: 'development' });39 });40 it('should prefer supplied move flag over mode from config', async () => {41 const result = await cli.applyOptions({ options: { mode: 'development' } }, { mode: 'production' });42 expect(result.options).toMatchObject({ mode: 'production' });43 });44 it('should prefer mode form config over NODE_ENV', async () => {45 process.env.NODE_ENV = 'development';46 const result = await cli.applyOptions({ options: {} }, { mode: 'production' });47 expect(result.options).toMatchObject({ mode: 'production' });48 });49 it('should prefer mode form flag over NODE_ENV and config', async () => {50 process.env.NODE_ENV = 'development';51 const result = await cli.applyOptions({ options: {} }, {});52 expect(result.options).toMatchObject({ mode: 'development' });53 });54 targetValues.map((option) => {55 it(`should handle ${option} option`, async () => {56 const result = await cli.applyOptions({ options: {} }, { target: option });57 expect(result.options.target).toEqual(option);58 });59 });...
script.js
Source:script.js
1function witchselect(menu) {2 if (menu.id==="c2R1" || menu.id==="c2R2") {3 var target = document.getElementById("c3R1");4 var choice1 = document.getElementById("c2R1");5 var choice2 = document.getElementById("c2R2");6 applyoptions(target, choice1, choice2);7 }8 else if (menu.id==="c2R3" || menu.id==="c2R4") {9 var target = document.getElementById("c3R2");10 var choice1 = document.getElementById("c2R3");11 var choice2 = document.getElementById("c2R4");12 applyoptions(target, choice1, choice2);13 }14 else if (menu.id==="c8R1" || menu.id==="c8R2") {15 var target = document.getElementById("c7R1");16 var choice1 = document.getElementById("c8R1");17 var choice2 = document.getElementById("c8R2");18 applyoptions(target, choice1, choice2);19 }20 else if (menu.id==="c8R3" || menu.id==="c8R4") {21 var target = document.getElementById("c7R2");22 var choice1 = document.getElementById("c8R3");23 var choice2 = document.getElementById("c8R4");24 applyoptions(target, choice1, choice2);25 }26 else if (menu.id==="c3R1" || menu.id==="c3R2") {27 var target = document.getElementById("c4R1");28 var choice1 = document.getElementById("c3R1");29 var choice2 = document.getElementById("c3R2");30 applyoptions(target, choice1, choice2);31 }32 else if (menu.id==="c7R1" || menu.id==="c7R2") {33 var target = document.getElementById("c6R1");34 var choice1 = document.getElementById("c7R1");35 var choice2 = document.getElementById("c7R2");36 applyoptions(target, choice1, choice2);37 }38 else if (menu.id==="c4R1" || menu.id==="c6R1") {39 var target = document.getElementById("c5R1");40 var choice1 = document.getElementById("c4R1");41 var choice2 = document.getElementById("c6R1");42 applyoptions(target, choice1, choice2);43 }44}45function applyoptions(target, choice1, choice2) {46 target.innerHTML = "";47 if (choice1.value == "" || choice2.value == "") {48 target.setAttribute("disabled", "disabled");49 }50 else {51 var opt = document.createElement('option');52 opt.innerHTML = "Select";53 opt.value = "";54 target.appendChild(opt);55 opt = document.createElement('option');56 opt.innerHTML = choice1.value;57 target.appendChild(opt);58 opt = document.createElement('option');59 opt.innerHTML = choice2.value;60 target.appendChild(opt);61 target.removeAttribute("disabled");62 }63 witchselect(target);...
apply_options.test.js
Source:apply_options.test.js
1const test = require('ava')2const applyOptions = require('../lib/help/apply_options')3test('options.iat must be a boolean', (t) => {4 t.throws(() => applyOptions({ iat: 1 }, {}), {5 instanceOf: TypeError,6 message: 'options.iat must be a boolean',7 })8})9test('now not a Date object', (t) => {10 t.throws(() => applyOptions({ now: 1 }, {}), {11 instanceOf: TypeError,12 message: 'options.now must be a valid Date object',13 })14})15test('now not a valid Date object', (t) => {16 t.throws(() => applyOptions({ now: 'foo' }, {}), {17 instanceOf: TypeError,18 message: 'options.now must be a valid Date object',19 })20})21;['expiresIn', 'notBefore', 'audience', 'issuer', 'subject', 'kid', 'jti'].forEach((option) => {22 test(`options.${option} must be a string`, (t) => {23 t.throws(() => applyOptions({ [option]: 1 }, {}), {24 instanceOf: TypeError,25 message: `options.${option} must be a string`,26 })27 })28})29Object.entries({30 issuer: 'iss',31 audience: 'aud',32 kid: 'kid',33 jti: 'jti',34 subject: 'sub',35}).forEach(([option, claim]) => {36 test(`options.${option} puts a ${claim} in the payload`, (t) => {37 t.deepEqual(applyOptions({ [option]: 'value', iat: false }, {}), { [claim]: 'value' })38 })39})40test('defaults', (t) => {41 t.true('iat' in applyOptions({}, {}))42})43test('expiresIn', (t) => {44 t.true('exp' in applyOptions({ expiresIn: '1d' }, {}))45})46test('notBefore', (t) => {47 t.true('nbf' in applyOptions({ notBefore: '1d' }, {}))...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.applyOptions({ viewport: { width: 640, height: 480 } });7 await page.screenshot({ path: `example.png` });8 await browser.close();9})();10#### playwright.launch([options])11 - `headless` <[boolean]> Whether to run browser in headless mode. Defaults to `true` unless the `devtools` option is `true`. _**(Optional)**_12 - `slowMo` <[number]> Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on. Defaults to `0`. _**(Optional)**_13 - `devtools` <[boolean]> Whether to auto-open a DevTools panel for each tab. If this option is `true`, the `headless` option will be set `false`. _**(Optional)**_14 - `executablePath` <[string]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, Firefox or WebKit, use at your own risk. _**(Optional)**_15 - `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`. _**(Optional)**_16 - `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`. _**(Optional)**_
Using AI Code Generation
1const { chromium } = require('playwright');2const path = require('path');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.screenshot({ path: path.join(__dirname, 'example.png') });8 await browser.close();9})();10const { chromium } = require('playwright');11const path = require('path');12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 await page.screenshot({ path: path.join(__dirname, 'example.png') });17 await browser.close();18})();19const { chromium } = require('playwright');20const path = require('path');21(async () => {22 const browser = await chromium.launch();23 const context = await browser.newContext();24 const page = await context.newPage();25 await page.screenshot({ path: path.join(__dirname, 'example.png') });26 await browser.close();27})();28const { chromium } = require('playwright');29const path = require('path');30(async () => {31 const browser = await chromium.launch();32 const context = await browser.newContext();33 const page = await context.newPage();34 await page.screenshot({ path: path.join(__dirname, 'example.png') });35 await browser.close();36})();37const { chromium } = require('playwright');38const path = require('path');39(async () => {40 const browser = await chromium.launch();41 const context = await browser.newContext();42 const page = await context.newPage();43 await page.screenshot({ path: path.join(__dirname, 'example.png') });44 await browser.close();45})();46const { chromium } = require('playwright');47const path = require('path');48(async () => {
Using AI Code Generation
1const { Playwright } = require('playwright-core');2const { chromium } = require('playwright-chromium');3const { firefox } = require('playwright-firefox');4const { webkit } = require('playwright-webkit');5const { devices } = require('playwright-core/lib/server/deviceDescriptors');6const { getTestState } = require('playwright-core/lib/server/test');7const { assert } = require('console');8const { test } = require('playwright-core/lib/server/testRunner');9const { expect } = require('chai');10const { it } = test;11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36';16 const viewport = { width: 1280, height: 720 };17 await page.applyOptions({18 });19 expect(await page.evaluate(() => navigator.userAgent)).to.equal(userAgent);20 expect(await page.evaluate(() => window.innerWidth)).to.equal(viewport.width);21 expect(await page.evaluate(() => window.innerHeight)).to.equal(viewport.height);22 await browser.close();23})();
Using AI Code Generation
1const { applyOptions } = require('playwright/lib/server/frames');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.evaluate(async () => {8 const { applyOptions } = window['playwright/lib/server/frames'];9 await applyOptions({10 viewport: {11 },12 });13 });14 await page.screenshot({ path: `example.png` });15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.evaluate(async () => {23 const { applyOptions } = window['playwright/lib/server/frames'];24 await applyOptions({25 viewport: {26 },27 });28 });29 await page.screenshot({ path: `example2.png` });30 await browser.close();31})();
Using AI Code Generation
1const { Playwright } = require('playwright');2const { chromium } = Playwright;3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 await context._options.applyOptions({ viewport: { width: 1024, height: 768 } });7 const page = await context.newPage();8 await page.screenshot({ path: 'example.png' });9 await browser.close();10})();11[Apache 2.0](LICENSE)
Using AI Code Generation
1const { InternalApi } = require('playwright-core/lib/server/internalApi');2const { Playwright } = require('playwright-core');3const playwright = new Playwright();4const internalApi = new InternalApi(playwright);5const options = {headless: false};6internalApi.applyOptions(options);7const { InternalApi } = require('playwright-core/lib/server/internalApi');8const { Playwright } = require('playwright-core');9const playwright = new Playwright();10const internalApi = new InternalApi(playwright);11const options = {headless: false};12internalApi.launchServer(options);13const { InternalApi } = require('playwright-core/lib/server/internalApi');14const { Playwright } = require('playwright-core');15const playwright = new Playwright();16const internalApi = new InternalApi(playwright);17const options = {headless: false};18internalApi.launchBrowserServer(options);19const { InternalApi } = require('playwright-core/lib/server/internalApi');20const { Playwright } = require('playwright-core');21const playwright = new Playwright();22const internalApi = new InternalApi(playwright);23const options = {headless: false};24internalApi.launchBrowserApp(options);25const { InternalApi } = require('playwright-core/lib/server/internalApi');26const { Playwright } = require('playwright-core');27const playwright = new Playwright();28const internalApi = new InternalApi(playwright);29const options = {headless: false};30internalApi.launchBrowserApp(options);31const { InternalApi } = require('playwright-core/lib/server/internalApi');32const { Playwright } = require('playwright-core');33const playwright = new Playwright();34const internalApi = new InternalApi(playwright);35const options = {headless: false};
Using AI Code Generation
1const { applyOptions } = require('playwright/lib/server/browserType');2const options = {3};4const browser = await applyOptions(BrowserType, options);5const { applyOptions } = require('playwright/lib/server/browserType');6const options = {7};8const browser = await applyOptions(BrowserType, options);9const { applyOptions } = require('playwright/lib/server/browserType');10const options = {11};12const browser = await applyOptions(BrowserType.launch, options);
Using AI Code Generation
1const { Playwright } = require('@playwright/test');2const { WebKit } = Playwright;3const { WebKitBrowser } = WebKit;4const webkitBrowser = new WebKitBrowser();5webkitBrowser.applyOptions({6 viewport: { width: 100, height: 100 },7});8- [Playwright Test Reporter](
Using AI Code Generation
1const { chromium } = require('playwright');2const { applyOptions } = require('playwright/lib/server/browserType');3const { devices } = require('playwright/lib/server/deviceDescriptors');4const iPhone = devices['iPhone 6'];5(async () => {6 const browser = await chromium.launch({7 });8 const context = await applyOptions(browser._defaultContext, {9 });10 const page = await context.newPage();11})();12const { chromium } = require('playwright');13const { devices } = require('playwright/lib/server/deviceDescriptors');14const iPhone = devices['iPhone 6'];15(async () => {16 const browser = await chromium.launch({17 });18 const context = await browser.newContext({19 });20 const page = await context.newPage();21})();22const { chromium } = require('playwright');23const { devices } = require('playwright/lib/server/deviceDescriptors');24const iPhone = devices['iPhone 6'];25(async () => {26 const browser = await chromium.launch({27 });28 const context = await browser.newContext(iPhone);29 const page = await context.newPage();30})();31const { chromium } = require('playwright');32const { devices } = require('playwright/lib/server/deviceDescriptors');33const iPhone = devices['iPhone 6'];34(async () => {35 const browser = await chromium.launch({36 });37 const context = await browser.newContext(iPhone);38 const page = await context.newPage(iPhone);
Using AI Code Generation
1const playwright = require('playwright');2const { Playwright } = require('playwright/lib/server/playwright');3const { chromium } = require('playwright');4const { devices } = require('playwright');5(async () => {6 const browser = await chromium.launch();7 const page = await browser.newPage();8 await page.screenshot({ path: `example.png` });9 await browser.close();10})();11const { devices } = require('../deviceDescriptors');12const { BrowserType } = require('./browserType');13const { BrowserServer } = require('./browserServer');14const { BrowserContext } = require('./browserContext');15const { Browser } = require('./browser');16const { ConnectionTransport } = require('./transport');17const { Connection } = require('./connection');18const { assert } = require('../utils/utils');19const { TimeoutSettings } = require('../utils/timeoutSettings');20const { Events } = require('../utils/events');21const { helper } = require('../helper');22const { debugLogger } = require('../utils/debugLogger');23const { ProgressController } = require('../utils/progress');24const { createGuid } = require('../utils/utils');25const { BrowserFetcher } = require('./browserFetcher');26const { PlaywrightDispatcher } = require('../dispatchers/playwrightDispatcher');27const { DispatcherConnection } = require('../dispatchers/dispatcher');28const { serializeError } = require('../utils/serializeError');29const { BrowserContextDispatcher } = require('../dispatchers/browserContextDispatcher');30const { BrowserTypeDispatcher } = require('../dispatchers/browserTypeDispatcher');31const { BrowserDispatcher } = require('../dispatchers/browserDispatcher');32const { BrowserServerDispatcher } = require('../dispatchers/browserServerDispatcher');33const { BrowserContextChannel } = require('../channels');34const { BrowserTypeChannel } = require('../channels');35const { BrowserChannel } = require('../channels');36const { BrowserServerChannel } = require('../channels');37const { BrowserContextInitializer, BrowserTypeInitializer, BrowserInitializer, BrowserServerInitializer } = require('../protocol/channels');38const { BrowserContextEvents } = require('../protocol/browserContext');39const { BrowserTypeEvents } = require('../protocol/browserType');40const { BrowserEvents } = require('../protocol/browser');41const { BrowserServerEvents } = require('../protocol/browserServer');42const { BrowserContextChannelOwner } =
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!