How to use incumbent method in wpt

Best JavaScript code snippet using wpt

Constraints.js

Source:Constraints.js Github

copy

Full Screen

1import React, { useState, useEffect } from "react";2import "../../../node_modules/leaflet/dist/leaflet.css";3import { RangeStepInput } from "react-range-step-input";4import { Select, Modal, Button, Checkbox, Table } from "react-materialize";5import {6 RadioGroup,7 FormControl,8 FormControlLabel,9 FormLabel,10 Radio,11 Typography,12 Slider,13} from "@material-ui/core";14import emitter from "../../libs/mitt";15const Constraints = () => {16 const [equalPopulationValue, setEqualPopulationValue] = useState(20);17 const [incumbents, setIncumbents] = useState([]);18 const [compactValue, setCompactValue] = useState(0.5);19 const [minority, setMinority] = useState();20 const [MMDistricts, setMMDistricts] = useState(7);21 const [popThreshold, setPopThreshold] = useState(50);22 const [popType, setPopType] = useState();23 const [hideSummary, setHideSummary] = useState(true);24 const [constrainedJob, setConstrainedJob] = useState();25 const handleIncumbentSelected = (e) => {26 setIncumbents(incumbents.concat(e.target.value));27 };28 const handleEqualPopulationChange = (e, newValue) => {29 setEqualPopulationValue(newValue);30 };31 const handleCompactChange = (e, newValue) => {32 setCompactValue(newValue);33 };34 const handleMinorityChange = (e) => {35 setMinority(e.target.value);36 };37 const handleMMDistrictsChange = (e, newValue) => {38 setMMDistricts(newValue);39 };40 const handlePopThresholdChange = (e, newValue) => {41 setPopThreshold(newValue);42 };43 const handlePopTypeChange = (e, newValue) => {44 setPopType(newValue);45 };46 const handleButtonClick = () => {47 emitter.emit("applyContraints", {48 constraints: [49 popType,50 minority,51 MMDistricts,52 popThreshold,53 compactValue,54 equalPopulationValue,55 incumbents,56 ],57 });58 };59 useEffect(() => {60 emitter.on("constrainedJob", (payload) => {61 setConstrainedJob(payload.job);62 setHideSummary(false);63 });64 }, []);65 return (66 <div style={{ marginRight: "10px", marginLeft: "10px" }}>67 <h5>Population Constraints</h5>68 <FormControl component="fieldset">69 <FormLabel component="legend"></FormLabel>70 <RadioGroup71 aria-label="gender"72 name="gender1"73 onChange={handlePopTypeChange}74 >75 <FormControlLabel76 value="tp"77 control={<Radio />}78 label="Total Population"79 />80 <FormControlLabel81 value="tvap"82 control={<Radio />}83 label="Voting Age Population (TVAP)"84 />85 <FormControlLabel86 value="cvap"87 disabled88 control={<Radio />}89 label="Citizen Voting Age"90 />91 </RadioGroup>92 </FormControl>93 <p>Equal Population Threshold: </p>94 <Slider95 value={equalPopulationValue}96 min={0}97 step={0.01}98 max={40}99 onChange={handleEqualPopulationChange}100 valueLabelDisplay="auto"101 aria-labelledby="non-linear-slider"102 />103 <h5>Majority-Minority Districts</h5>104 <Select105 id="Select-1"106 multiple={false}107 options={{108 classes: "",109 dropdownOptions: {110 alignment: "left",111 autoTrigger: true,112 closeOnClick: true,113 constrainWidth: true,114 coverTrigger: true,115 hover: false,116 inDuration: 150,117 onCloseEnd: null,118 onCloseStart: null,119 onOpenEnd: null,120 onOpenStart: null,121 outDuration: 250,122 },123 }}124 value=""125 onChange={handleMinorityChange}126 >127 <option disabled value="">128 Select Minority129 </option>130 <option value="black">Black</option>131 <option value="hispanic">Hispanic</option>132 <option value="asian">Asian</option>133 </Select>134 <Typography id="non-linear-slider" gutterBottom></Typography>135 <h7>Number of Districts: </h7>136 <Slider137 value={MMDistricts}138 min={0}139 step={1}140 max={14}141 onChange={handleMMDistrictsChange}142 valueLabelDisplay="auto"143 aria-labelledby="non-linear-slider"144 />145 <h7>Population Percentage Threshold: </h7>146 <Slider147 value={popThreshold}148 min={0}149 step={1}150 max={100}151 onChange={handlePopThresholdChange}152 valueLabelDisplay="auto"153 aria-labelledby="non-linear-slider"154 />155 <h5>Set Protected Incumbents</h5>156 <Modal157 actions={[158 <Button flat modal="close" node="button" waves="green">159 Close160 </Button>,161 ]}162 bottomSheet={false}163 fixedFooter={false}164 header="Incumbents of Georgia"165 id="Modal-0"166 open={false}167 options={{168 dismissible: true,169 endingTop: "10%",170 inDuration: 250,171 onCloseEnd: null,172 onCloseStart: null,173 onOpenEnd: null,174 onOpenStart: null,175 opacity: 0.5,176 outDuration: 250,177 preventScrolling: true,178 startingTop: "4%",179 }}180 trigger={<Button node="button">Select Incumbents</Button>}181 >182 <p>Select Incumbents to Protect: (Name - District)</p>183 <Table>184 <thead>185 <tr>186 <th>Republican</th>187 <th>Democrat</th>188 </tr>189 </thead>190 <tbody>191 <tr>192 <td>193 <Checkbox194 id="Checkbox_6"195 checked={false}196 label="Buddy Carter - D1"197 value="district_1_incumbent"198 onChange={handleIncumbentSelected}199 />200 </td>201 <td>202 <Checkbox203 id="Checkbox_7"204 checked={false}205 label="Sanford Bishop - D2"206 value="district_2_incumbent"207 onChange={handleIncumbentSelected}208 />209 </td>210 </tr>211 <tr>212 <td>213 <Checkbox214 id="Checkbox_8"215 checked={false}216 label="Drew Ferguson - D3"217 value="district_3_incumbent"218 onChange={handleIncumbentSelected}219 />220 </td>221 <td>222 <Checkbox223 id="Checkbox_9"224 checked={false}225 label="Hank Johnson - D4"226 value="district_4_incumbent"227 onChange={handleIncumbentSelected}228 />229 </td>230 </tr>231 <tr>232 <td>233 <Checkbox234 id="Checkbox_10"235 checked={false}236 label="Austin Scott - D8"237 value="district_8_incumbent"238 onChange={handleIncumbentSelected}239 />240 </td>241 <td>242 <Checkbox243 id="Checkbox_11"244 checked={false}245 label="Nikema Williams - D5"246 value="district_5_incumbent"247 onChange={handleIncumbentSelected}248 />249 </td>250 </tr>251 <tr>252 <td>253 <Checkbox254 id="Checkbox_12"255 checked={false}256 label="Andrew Clyde - D9"257 value="district_9_incumbent"258 onChange={handleIncumbentSelected}259 />260 </td>261 <td>262 <Checkbox263 id="Checkbox_13"264 checked={false}265 label="Lucy McBath - D6"266 value="district_6_incumbent"267 onChange={handleIncumbentSelected}268 />269 </td>270 </tr>271 <tr>272 <td>273 <Checkbox274 id="Checkbox_14"275 checked={false}276 label="Jody Hice - D10"277 value="district_10_incumbent"278 onChange={handleIncumbentSelected}279 />280 </td>281 <td>282 <Checkbox283 id="Checkbox_15"284 checked={false}285 label="Carolyn Bourdeaux - D7"286 value="district_7_incumbent"287 onChange={handleIncumbentSelected}288 />289 </td>290 </tr>291 <tr>292 <td>293 <Checkbox294 id="Checkbox_16"295 checked={false}296 label="Barry Loudermilk - D11"297 value="district_11_incumbent"298 onChange={handleIncumbentSelected}299 />300 </td>301 <td>302 <Checkbox303 id="Checkbox_17"304 checked={false}305 label="David Scott - D13"306 value="district_13_incumbent"307 onChange={handleIncumbentSelected}308 />309 </td>310 </tr>311 <tr>312 <td>313 <Checkbox314 id="Checkbox_18"315 checked={false}316 label="Rick Allen - D12"317 value="district_12_incumbent"318 onChange={handleIncumbentSelected}319 />320 </td>321 <td></td>322 </tr>323 <tr>324 <td>325 <Checkbox326 id="Checkbox_19"327 checked={false}328 label="Marjorie Taylor Greene - D14"329 value="district_14_incumbent"330 onChange={handleIncumbentSelected}331 />332 </td>333 <td></td>334 </tr>335 </tbody>336 </Table>337 </Modal>338 <h5>Select Compactness</h5>339 <FormControl component="fieldset">340 <FormLabel component="legend"></FormLabel>341 <RadioGroup aria-label="gender" name="gender1">342 <FormControlLabel343 value="polsby-popper"344 control={<Radio />}345 label="Polsby-Popper"346 />347 <FormControlLabel348 value="graph compactness"349 disabled350 control={<Radio />}351 label="Graph Compactness"352 />353 <FormControlLabel354 value="population fatness"355 disabled356 control={<Radio />}357 label="Population Fatness"358 />359 </RadioGroup>360 </FormControl>361 <Typography id="non-linear-slider" gutterBottom></Typography>362 <Slider363 value={compactValue}364 min={0}365 step={0.01}366 max={1}367 onChange={handleCompactChange}368 valueLabelDisplay="auto"369 aria-labelledby="non-linear-slider"370 />371 <div372 style={{373 display: "flex",374 justifyContent: "center",375 alignItems: "center",376 height: "8vh",377 }}378 >379 <Button onClick={handleButtonClick}>Apply</Button>380 </div>381 <div style={hideSummary ? { display: "none" } : null}>382 <Modal383 actions={[384 <Button flat modal="close" node="button" waves="green">385 Close386 </Button>,387 ]}388 bottomSheet={false}389 fixedFooter={false}390 header="Summary of Constrained Districtings"391 id="Modal-0"392 open={false}393 options={{394 dismissible: true,395 endingTop: "10%",396 inDuration: 250,397 onCloseEnd: null,398 onCloseStart: null,399 onOpenEnd: null,400 onOpenStart: null,401 opacity: 0.5,402 outDuration: 250,403 preventScrolling: true,404 startingTop: "4%",405 }}406 trigger={<Button node="button">Summary</Button>}407 >408 <p>409 Table shows the number of districtings removed due to each410 constraint.411 </p>412 <p>Total Districtings at Start: 5000</p>413 <Table>414 <thead>415 <tr>416 <th>Constraint</th>417 <th>Districtings Removed</th>418 </tr>419 </thead>420 <tbody>421 <tr>422 <td>Equal Population Threshold</td>423 <td>{hideSummary ? null : constrainedJob[0]}</td>424 </tr>425 <tr>426 <td>Minority</td>427 <td>{hideSummary ? null : constrainedJob[1]}</td>428 </tr>429 <tr>430 <td>Compactness</td>431 <td>{hideSummary ? null : constrainedJob[2]}</td>432 </tr>433 <tr>434 <td>Incumbent Protection</td>435 <td>{hideSummary ? null : constrainedJob[3]}</td>436 </tr>437 </tbody>438 <p>439 Total Districtings Remaining:{" "}440 {hideSummary441 ? null442 : 5000 -443 constrainedJob[0] -444 constrainedJob[1] -445 constrainedJob[2] -446 constrainedJob[3]}447 </p>448 </Table>449 </Modal>450 </div>451 </div>452 );453};...

Full Screen

Full Screen

spec.ts

Source:spec.ts Github

copy

Full Screen

1require('dotenv').config();2import * as test from 'tape';3import createLogger from '../logger';4import { loadLocalJson, getTokenPath, authorize, fetchData } from './utils';5import { isHouston, mapCandidate, getCandidates, setIDBaseNumber, mapRace, parseData, getData } from './index';6test('loadLocalJson pulls and parses the google sheet credentials from project root or throws error', async t => {7 let credentials = await loadLocalJson('.google-sheets-credentials.json');8 let result = credentials.installed.auth_uri;9 let expected = 'https://accounts.google.com/o/oauth2/auth';10 t.equal(result, expected);11 try {12 credentials = await loadLocalJson('.bing-sheets-credentials.json');13 } catch (error) {14 result = error.toString()15 expected = 'Error: ENOENT: no such file or directory, open \'.bing-sheets-credentials.json\'';16 t.equal(result, expected);17 }18 t.end();19});20test('getTokenDir should write the directory where the credentials are stored to a string', t => {21 const credMatch = '.credentials/';22 const tokenDir = getTokenPath();23 const result = tokenDir.slice(tokenDir.indexOf(credMatch) + credMatch.length);24 const expected = '2018-midterm-elections.json';25 t.equal(result, expected);26 t.end();27});28test('authorize should return oauth2Client object', async t => {29 const credentials = await loadLocalJson('.google-sheets-credentials.json');30 const oauth2Client = await authorize(credentials);31 const result = oauth2Client.credentials.scope32 const expected = 'https://www.googleapis.com/auth/spreadsheets.readonly';33 t.equal(result, expected);34 t.end();35});36test('fetchData should return the google sheet data', async t => {37 const credentials = await loadLocalJson('.google-sheets-credentials.json');38 const oauth2Client = await authorize(credentials);39 const response = await fetchData(oauth2Client, process.env.SPREADSHEET_ID, ['HOUSTON!A2:AB', 'SAN_ANTONIO!A2:AB']);40 41 const result = response.data.map(hash => hash.range)[0].includes('HOUSTON!');42 const expected = true;43 t.equal(result, expected);44 t.end();45});46test('isHouston should detect if data comes from Houston or SA sheet', t => {47 let result = isHouston('HOUSTON!A2:AB986');48 let expected = true;49 t.equal(result, expected);50 result = isHouston('SAN_ANTONIO!A2:Z1003');51 expected = false;52 t.equal(result, expected);53 t.end();54});55test('mapCandidate should take a 2 element array and return a Candidate object', t => {56 let incumbent = 'Frankie "Mr. Big" Sharp';57 let winner = '';58 const candidate = [59 'Luke Whyte',60 '300',61 ];62 let result = mapCandidate(candidate, incumbent, winner);63 let expected = {64 name: 'Luke Whyte',65 votes: 300, 66 incumbent: false,67 winner: false,68 };69 t.deepEqual(result, expected);70 winner = 'Luke Whyte';71 result = mapCandidate(candidate, incumbent, winner);72 expected = {73 name: 'Luke Whyte',74 votes: 300, 75 incumbent: false,76 winner: true,77 };78 t.deepEqual(result, expected);79 incumbent = 'Luke Whyte';80 result = mapCandidate(candidate, incumbent, winner);81 expected = {82 name: 'Luke Whyte',83 votes: 300, 84 incumbent: true,85 winner: true,86 };87 t.deepEqual(result, expected);88 t.end();89});90test('getCandidates takes array with first elements pointing to incumbent and winner followed by N candidate elements. Returns array of candidates', t => {91 const incumbent = 'Papa Smurf';92 const winner = 'The Ultimate Warrior';93 const candidates = [94 incumbent,95 winner,96 'Luke Whyte',97 '300',98 'Papa Smurf',99 '500',100 'The Ultimate Warrior',101 '800',102 ];103 const result = getCandidates(candidates, []);104 const expected = [105 {106 name: 'Luke Whyte',107 votes: 300, 108 incumbent: false,109 winner: false,110 },111 {112 name: 'Papa Smurf',113 votes: 500, 114 incumbent: true,115 winner: false,116 },117 {118 name: 'The Ultimate Warrior',119 votes: 800, 120 incumbent: false,121 winner: true,122 },123 ];124 t.deepEqual(result, expected);125 t.end();126});127test('mapRace takes a race array of strings and returns a Race object. setIDBaseNumber adds ID digits based on market', t => {128 const race = [129 '1',130 'House Floor DJ',131 'Papa Smurf',132 '',133 'Luke Whyte',134 '300',135 'Papa Smurf',136 '500',137 'The Ultimate Warrior',138 '800',139 ];140 const result = mapRace(race, setIDBaseNumber('sa'));141 const expected = {142 id: 200001,143 title: 'House Floor DJ',144 isNational: false,145 candidates: [146 {147 name: 'Luke Whyte',148 votes: 300, 149 incumbent: false,150 winner: false,151 },152 {153 name: 'Papa Smurf',154 votes: 500, 155 incumbent: true,156 winner: false,157 },158 {159 name: 'The Ultimate Warrior',160 votes: 800, 161 incumbent: false,162 winner: false,163 },164 ],165 };166 t.deepEqual(result, expected);167 t.end();168});169test('parseData accepts an array GoogleSheet objects, which it iterates over to build a GoogleSheetData object', t => {170 const raceSA = [171 '1',172 'House Floor DJ',173 'Papa Smurf',174 '',175 'Luke Whyte',176 '300',177 'Papa Smurf',178 '500',179 'The Ultimate Warrior',180 '800',181 ];182 const raceHouston = [183 '1',184 'Senate Floor DJ',185 'Papa Smurf',186 'The Ultimate Warrior',187 'Luke Whyte',188 '300',189 'Papa Smurf',190 '500',191 'The Ultimate Warrior',192 '800',193 ];194 const sheets = [195 {196 range: 'HOUSTON!A1:AB986',197 majorDimension: 'ROWS',198 values: [raceHouston, raceHouston, raceHouston],199 },200 {201 range: 'SAN_ANTONIO!A1:Z1003',202 majorDimension: 'ROWS',203 values: [raceSA, raceSA, raceSA],204 },205 ];206 const data = parseData(sheets);207 const resultOne = data.houston[0].title;208 const expectedOne = 'Senate Floor DJ';209 t.equal(resultOne, expectedOne);210 const resultTwo = data.sa[1].id;211 const expectedTwo = 200001;212 t.equal(resultTwo, expectedTwo);213 const resultThree = data.houston[2].candidates[2].winner;214 const expectedThree = true;215 t.equal(resultThree, expectedThree);216 t.end();217});218test('getData performs above operations on live data after successful oAuth connection. On failure it returns empty GoogleSheetsData object', async t => {219 const data = await getData(process.env.SPREADSHEET_ID, ['HOUSTON!A2:AB', 'SAN_ANTONIO!A2:AB'], createLogger());220 const result = data.houston[0].id;221 const expected = 100002;222 t.equal(result, expected);223 const failedData = await getData('not_an_id', ['HOUSTON!A2:AB', 'SAN_ANTONIO!A2:AB'], createLogger());224 const failedResult = failedData.houston && failedData.houston.length === 0 && failedData.sa && failedData.sa.length === 0;225 const failedExpected = true;226 t.equal(failedResult, failedExpected);227 t.end();...

Full Screen

Full Screen

context-helper.js

Source:context-helper.js Github

copy

Full Screen

1// Usage: in the top-level Window, include:2//3// <script src="resources/context-helper.js"></script>4// <script>5// window.scriptToRun = '...';6// </script>7// <iframe id="entry" src="entry/entry.html"></iframe>8//9// Then `scriptToRun` is evaluated, with:10// - The entry Realm is that of entry/entry.html11// - The incumbent Realm is that of incumbent/empty.html12// - The relevant Realm of `relevantWindow`, `relevantWindow.location` etc. is13// that of relevant/empty.html14window.scriptToRun = '';15const entryUrl = new URL('entry/entry.html', location).href;16const incumbentUrl = new URL('incumbent/empty.html', location).href;17const relevantUrl = new URL('relevant/empty.html', location).href;18function go() {19 const entry = document.querySelector('#entry');20 const incumbent = entry.contentDocument.querySelector('#incumbent');21 const incumbentScript = incumbent.contentDocument.createElement('script');22 incumbentScript.textContent = `23 function go() {24 const relevantWindow =25 parent.document.querySelector('#relevant').contentWindow;26 ${window.scriptToRun}27 }28 `;29 incumbent.contentDocument.head.appendChild(incumbentScript);30 incumbent.contentWindow.go();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test status:', data.statusText);5 console.log('Test ID:', data.data.testId);6 console.log('Test URL:', data.data.summary);7});8api.getTestResults('170325_0Z_3e3e3b9c7b6f9a8c7a0b1d0a7c6b43b8', function(err, data) {9 if (err) return console.error(err);10 console.log('Test status:', data.statusText);11 console.log('Test ID:', data.data.testId);12 console.log('Test URL:', data.data.summary);13});14api.getLocations(function(err, data) {15 if (err) return console.error(err);16 console.log('Test status:', data.statusText);17 console.log('Test ID:', data.data.testId);18 console.log('Test URL:', data.data.summary);19});20api.getTesters(function(err, data) {21 if (err) return console.error(err);22 console.log('Test status:', data.statusText);23 console.log('Test ID:', data.data.testId);24 console.log('Test URL:', data.data.summary);25});26api.getTestStatus('170325_0Z_3e3e3b9c7b6f9a8c7a0b1d0a7c6b43b8', function(err, data) {27 if (err) return console.error(err);28 console.log('Test status:', data.statusText);29 console.log('Test ID:', data.data.testId);30 console.log('Test URL:', data.data.summary);31});32api.getTestResults('170325_0Z_3e3e3b9c7b6f9a8c7a0b1d0a7c6b43b8', function(err, data) {33 if (err) return console.error(err);34 console.log('Test status:', data.statusText);

Full Screen

Using AI Code Generation

copy

Full Screen

1const {incumbent} = require('./incumbent.js');2const {challenger} = require('./challenger.js');3const {incumbent2} = require('./incumbent2.js');4const {challenger2} = require('./challenger2.js');5const {incumbent3} = require('./incumbent3.js');6const {challenger3} = require('./challenger3.js');7const {incumbent4} = require('./incumbent4.js');8const {challenger4} = require('./challenger4.js');9const {incumbent5} = require('./incumbent5.js');10const {challenger5} = require('./challenger5.js');11const {incumbent6} = require('./incumbent6.js');12const {challenger6} = require('./challenger6.js');13const {incumbent7} = require('./incumbent7.js');14const {challenger7} = require('./challenger7.js');15const {incumbent8} = require('./incumbent8.js');16const {challenger8} = require('./challenger8.js');17const {incumbent9} = require('./incumbent9.js');18const {challenger9} = require('./challenger9.js');19const {incumbent10} = require('./incumbent10.js');20const {challenger10} =

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2wpt.incumbent('www.google.com', function(err, data){3 console.log(data);4});5var request = require('request');6module.exports = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var test = require('./test.js');2 console.log(data);3});4var test = require('./test.js');5 console.log(data);6});7var test = require('./test.js');8 console.log(data);9});10var test = require('./test.js');11 console.log(data);12});13var test = require('./test.js');14 console.log(data);15});16var test = require('./test.js');17 console.log(data);18});19var test = require('./test.js');20 console.log(data);21});22var test = require('./test.js');23 console.log(data);24});25var test = require('./test.js');26 console.log(data);27});28var test = require('./test.js');29 console.log(data);30});31var test = require('./test.js');32 console.log(data);33});34var test = require('./test.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require("webpagetest");2var wpt = new WebPageTest("www.webpagetest.org", "A.81d4d7f1baa9f9e9c1b1d6c0c0a8e8bf");3var options = {4};5wpt.runTest(url, options, function (err, data) {6 if (err) return console.error(err);7 console.log(data);8});

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 wpt 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