How to use isEmailAllowed method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

Notifications.js

Source:Notifications.js Github

copy

Full Screen

1/* eslint-disable max-len */2/* eslint-disable no-empty */3import React, {4 useEffect,5 useState,6} from 'react';7import { useDispatch } from 'react-redux';8import PropTypes from 'prop-types';9import clsx from 'clsx';10import {11 Box,12 Button,13 Card,14 CardContent,15 CardHeader,16 Checkbox,17 Divider,18 FormControlLabel,19 Grid,20 makeStyles21} from '@material-ui/core';22import { useSnackbar } from 'notistack';23import axios from 'src/utils/axios';24import { API_BASE_URL } from 'src/config';25import { SET_GARBAGE } from 'src/actions/garbageActions';26const useStyles = makeStyles(() => ({27 root: {}28}));29function Notifications({ className, oldGarbage, ...rest }) {30 const classes = useStyles();31 const [isEmailAllowed, setIsEmailAllowed] = useState(oldGarbage.isEmailAllowed);32 const [isNotificationAllowed, setIsNotificationAllowed] = useState(oldGarbage.isNotificationAllowed);33 const [isTextAllowed, setIsTextAllowed] = useState(oldGarbage.isTextAllowed);34 const { enqueueSnackbar } = useSnackbar();35 const dispatch = useDispatch();36 const handleSubmit = async (event) => {37 event.preventDefault();38 // Make API request39 try {40 const values = {41 isEmailAllowed,42 isNotificationAllowed,43 isTextAllowed,44 };45 const response = await axios.put(`${API_BASE_URL}/garbage`, values);46 if (response.data.status) {47 enqueueSnackbar('Notification Settings updated.', {48 variant: 'success',49 });50 dispatch({51 type: SET_GARBAGE,52 payload: {53 garbage: values,54 }55 });56 } else {57 enqueueSnackbar('Failed to save notification notificationSettings.', {58 variant: 'error',59 });60 }61 } catch (ex) {62 enqueueSnackbar('Failed to save notification notificationSettings.', {63 variant: 'error',64 });65 }66 };67 const getNotificationSettings = async () => {68 try {69 const response = await axios.get(`${API_BASE_URL}/garbage`);70 if (response.data.status) {71 setIsEmailAllowed(response.data.garbage.isEmailAllowed);72 setIsNotificationAllowed(response.data.garbage.isNotificationAllowed);73 setIsTextAllowed(response.data.garbage.isTextAllowed);74 const values = {75 isEmailAllowed: response.data.garbage.isEmailAllowed,76 isNotificationAllowed: response.data.garbage.isNotificationAllowed,77 isTextAllowed: response.data.garbage.isTextAllowed,78 };79 dispatch({80 type: SET_GARBAGE,81 payload: {82 garbage: values,83 }84 });85 }86 } catch (ex) {}87 };88 useEffect(() => {89 getNotificationSettings();90 }, []);91 return (92 <form onSubmit={handleSubmit}>93 <Card94 className={clsx(classes.root, className)}95 {...rest}96 >97 <CardHeader title="Notifications" />98 <Divider />99 <CardContent>100 <Grid101 container102 spacing={6}103 wrap="wrap"104 >105 <Grid106 item107 md={4}108 sm={6}109 xs={12}110 >111 <div>112 <FormControlLabel113 control={(114 <Checkbox115 checked={isEmailAllowed}116 value={isEmailAllowed}117 name="isEmailAllowed"118 onChange={(event) => { setIsEmailAllowed(event.target.checked); }}119 />120 )}121 label="Email alerts"122 />123 </div>124 <div>125 <FormControlLabel126 control={(127 <Checkbox128 checked={isNotificationAllowed}129 value={isNotificationAllowed}130 name="isNotificationAllowed"131 onChange={(event) => { setIsNotificationAllowed(event.target.checked); }}132 />133 )}134 label="Push Notifications"135 />136 </div>137 <div>138 <FormControlLabel139 control={(140 <Checkbox141 checked={isTextAllowed}142 value={isTextAllowed}143 name="isTextAllowed"144 onChange={(event) => { setIsTextAllowed(event.target.checked); }}145 />146 )}147 label="Text message"148 />149 </div>150 </Grid>151 </Grid>152 </CardContent>153 <Divider />154 <Box155 p={2}156 display="flex"157 justifyContent="flex-end"158 >159 <Button160 color="secondary"161 type="submit"162 variant="contained"163 >164 Save Settings165 </Button>166 </Box>167 </Card>168 </form>169 );170}171Notifications.propTypes = {172 className: PropTypes.string,173 oldGarbage: PropTypes.any,174};...

Full Screen

Full Screen

email-validator.test.js

Source:email-validator.test.js Github

copy

Full Screen

2test('should email be allowed ', () => {3 // arrange data 4 const email = 'klaudia@warsaw.js';5 // act 6 const result = isEmailAllowed(email);7 // assert8 expect(result).toBe(true);9});10test('should block out email without warsaw.js domain', () => {11 const result = isEmailAllowed('test@test.js');12 expect(result).toBe(false);13});14test('should block email without @', () => {15 const result = isEmailAllowed('test');16 expect(result).toBe(false);17});18test('should only contain alphanumeric', () => {19 expect(isEmailAllowed('test@warsaw.js')).toBe(true);20 expect(isEmailAllowed('!test@warsaw.js')).toBe(false);21 expect(isEmailAllowed('@test@warsaw.js')).toBe(false);22 expect(isEmailAllowed('_test@warsaw.js')).toBe(false);23 expect(isEmailAllowed('_te78st@warsaw.js')).toBe(false);24});25const cases = [['asdasd@as.com', false], ['adam@warsaw.js', true], ['441@warsaw.js', false]];26describe('email validator', () => {27 test.each(cases)(28 "given %p returns %p",29 (arg, out) => {30 const result = isEmailAllowed(arg);31 expect(result).toBe(out);32 }33 )...

Full Screen

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 devicefarmer-stf 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