How to use getUniqueId method in Cypress

Best JavaScript code snippet using cypress

Identity.js

Source:Identity.js Github

copy

Full Screen

...35const instances = {};36class Identity {37 constructor(o) {38 this.o = o;39 const instanceKey = `${this.constructor.getNamespace()}:${this.getUniqueId()}`40 if (!instances[instanceKey]) {41 this._policy = {};42 const c = require('./MessageBus.js');43 this.subscriber = new c('info');44 if (f.isMain()) {45 this.monitoring = false;46 const uid = this.getUniqueId();47 if (uid) {48 this.subscriber.subscribeOnce("DiscoveryEvent", "IdentityPolicy:Changed", uid, (channel, type, id, obj) => {49 log.info(`Identity policy is changed on ${uid}`, obj);50 this.scheduleApplyPolicy();51 })52 }53 }54 instances[instanceKey] = this;55 }56 return instances[instanceKey];57 }58 update(o) {59 this.o = o;60 }61 scheduleApplyPolicy() {62 if (this.applyPolicyTask)63 clearTimeout(this.applyPolicyTask);64 this.applyPolicyTask = setTimeout(() => {65 this.applyPolicy();66 }, 3000);67 }68 _getPolicyKey() {69 return `policy:${this.constructor.getNamespace()}:${this.getUniqueId()}`;70 }71 toJson() {72 const json = Object.assign({}, this.o, {policy: this._policy});73 return json;74 }75 async applyPolicy() {76 await this.loadPolicy();77 const policy = JSON.parse(JSON.stringify(this._policy));78 await pm.executeAsync(this, this.getUniqueId(), policy);79 }80 async loadPolicy() {81 const key = this._getPolicyKey();82 const policyData = await rclient.hgetallAsync(key);83 if (policyData) {84 this._policy = {};85 for (let k in policyData) {86 this._policy[k] = JSON.parse(policyData[k]);87 }88 } else {89 this._policy = {};90 }91 return this._policy;92 }93 async savePolicy() {94 const key = this._getPolicyKey();95 const policyObj = {};96 for (let k in this._policy) {97 policyObj[k] = JSON.stringify(this._policy[k]);98 }99 await rclient.hmsetAsync(key, policyObj).catch((err) => {100 log.error(`Failed to save policy to ${key}`, err);101 })102 }103 async setPolicy(name, data) {104 this._policy[name] = data;105 await this.savePolicy();106 if (this.subscriber) {107 this.subscriber.publish("DiscoveryEvent", "IdentityPolicy:Changed", this.getUniqueId(), {name, data});108 }109 }110 static getEnforcementIPsetName(uid, af = 4) {111 return `c_${this.getNamespace()}_${uid.substring(0, 12)}_set` + (af === 4 ? "" : "6");112 }113 static getEnforcementDnsmasqGroupId(uid) {114 return `${this.getNamespace()}_${uid}`;115 }116 static getRedisSetName(uid) {117 return `${this.getNamespace()}:addresses:${uid}`118 }119 static getDnsmasqConfigDirectory(uid) {120 return `${f.getUserConfigFolder()}/dnsmasq`121 }122 static getDnsmasqConfigFilenamePrefix(uid) {123 return `${this.getNamespace()}_${uid}`;124 }125 static async ensureCreateEnforcementEnv(uid) {126 const content = `redis-src-address-group=%${this.getRedisSetName(uid)}@${this.getEnforcementDnsmasqGroupId(uid)}`;127 await fs.writeFileAsync(`${this.getDnsmasqConfigDirectory(uid)}/${this.getDnsmasqConfigFilenamePrefix(uid)}.conf`, content, { encoding: 'utf8' }).catch((err) => {128 log.error(`Failed to create dnsmasq config for identity ${uid}`, err.message);129 });130 dnsmasq.scheduleRestartDNSService();131 const instanceKey = `${this.getNamespace()}:${uid}`132 if (envCreatedMap[instanceKey])133 return;134 // create related ipsets135 await exec(`sudo ipset create -! ${this.getEnforcementIPsetName(uid)} hash:net`).catch((err) => {136 log.error(`Failed to create identity ipset ${this.getEnforcementIPsetName(uid)}`, err.message);137 });138 await exec(`sudo ipset create -! ${this.getEnforcementIPsetName(uid, 6)} hash:net family inet6`).catch((err) => {139 log.error(`Failed to create identity ipset ${this.getEnforcementIPsetName(uid, 6)}`, err.message);140 });141 envCreatedMap[instanceKey] = 1;142 }143 async createEnv() {144 await this.constructor.ensureCreateEnforcementEnv(this.getUniqueId());145 }146 async destroyEnv() {147 await exec(`sudo ipset flush -! ${this.constructor.getEnforcementIPsetName(this.getUniqueId())}`).catch((err) => {148 log.error(`Failed to flush identity ipset ${this.constructor.getEnforcementIPsetName(this.getUniqueId())}`, err.message);149 });150 await exec(`sudo ipset flush -! ${this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6)}`).catch((err) => {151 log.error(`Failed to flush identity ipset ${this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6)}`, err.message);152 });153 // delete related dnsmasq config files154 await exec(`sudo rm -f ${this.constructor.getDnsmasqConfigDirectory(uid)}/${this.constructor.getDnsmasqConfigFilenamePrefix(uid)}.conf`).catch((err) => {});155 await exec(`sudo rm -f ${this.constructor.getDnsmasqConfigDirectory(uid)}/${this.constructor.getDnsmasqConfigFilenamePrefix(uid)}_*.conf`).catch((err) => {});156 dnsmasq.scheduleRestartDNSService();157 }158 async updateIPs(ips) {159 if (this._ips && _.isEqual(ips.sort(), this._ips.sort())) {160 log.info(`IP addresses of identity ${this.getUniqueId()} is not changed`, ips);161 return;162 }163 log.info(`IP addresses of identity ${this.getUniqueId()} is changed`, this._ips, ips);164 await exec(`sudo ipset flush ${this.constructor.getEnforcementIPsetName(this.getUniqueId())}`).catch((err) => {165 log.error(`Failed to flush ${this.constructor.getEnforcementIPsetName(this.getUniqueId())}`, err.message);166 });167 await exec(`sudo ipset flush ${this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6)}`).catch((err) => {168 log.error(`Failed to flush ${this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6)}`, err.message);169 });170 const cmds = [];171 for (const ip of ips) {172 if (new Address4(ip).isValid()) {173 cmds.push(`add ${this.constructor.getEnforcementIPsetName(this.getUniqueId())} ${ip}`);174 } else {175 if (new Address6(ip).isValid()) {176 cmds.push(`add ${this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6)} ${ip}`);177 }178 }179 }180 await ipset.batchOp(cmds).catch((err) => {181 log.error(`Failed to populate ipset of identity ${this.getUniqueId()}`, err.message);182 });183 // update IP addresses in redis set184 // TODO: only supports IPv4 address here185 const currentIPs = await rclient.smembersAsync(this.constructor.getRedisSetName(this.getUniqueId()));186 const removedIPs = currentIPs.filter(ip => !ips.includes(ip)) || [];187 const newIPs = ips.filter(ip => !currentIPs.includes(ip)).map(ip => (ip.endsWith('/32') || ip.endsWith('/128')) ? ip.split('/')[0] : ip); // TODO: support cidr match in dnsmasq188 if (removedIPs.length > 0)189 await rclient.sremAsync(this.constructor.getRedisSetName(this.getUniqueId()), removedIPs);190 if (newIPs.length > 0)191 await rclient.saddAsync(this.constructor.getRedisSetName(this.getUniqueId()), newIPs);192 this._ips = ips;193 }194 static isEnabled() {195 return true;196 }197 getUniqueId() {198 }199 static getKeyOfUIDInAlarm() {200 }201 // return a string, length of which should not exceed 8202 static getNamespace() {203 }204 static getKeyOfInitData() {205 }206 static async getInitData() {207 const json = {};208 const identities = await this.getIdentities();209 for (const uid of Object.keys(identities)) {210 await identities[uid].loadPolicy();211 json[uid] = identities[uid].toJson();212 }213 return json;214 }215 // return an object, key is uid, value is an Idendity object216 static async getIdentities() {217 return {};218 }219 // return an object, key is IP address, value is uid220 static async getIPUniqueIdMappings() {221 return {};222 }223 // return an object, key is IP address, value is IP:port of the endpoint. This is usually applicable on tunnelled identity224 static async getIPEndpointMappings() {225 return {};226 }227 // getIdentities will be invoked if any of these events is triggered228 static getRefreshIdentitiesHookEvents() {229 return [];230 }231 // getIPUniqueIdMappings will be invoked if any of these events is triggered232 static getRefreshIPMappingsHookEvents() {233 return [];234 }235 getReadableName() {236 return this.getUniqueId();237 }238 getLocalizedNotificationKeySuffix() {239 return "";240 }241 getDeviceNameInNotificationContent(alarm) {242 return alarm["p.device.name"];243 }244 getNicName() {245 }246 getNicUUID() {247 const nic = this.getNicName();248 if (nic) {249 const intf = sysManager.getInterface(nic);250 return intf && intf.uuid;251 }252 return null;253 }254 async spoof(state) {255 this.monitoring = state;256 }257 isMonitoring() {258 return this.monitoring;259 }260 async qos(state) {261 const identityIpsetName = this.constructor.getEnforcementIPsetName(this.getUniqueId());262 const identityIpsetName6 = this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6);263 if (state === true) { 264 await exec(`sudo ipset del -! ${ipset.CONSTANTS.IPSET_QOS_OFF} ${identityIpsetName}`).catch((err) => {265 log.error(`Failed to remove ${identityIpsetName} from ${ipset.CONSTANTS.IPSET_QOS_OFF}`, err.message);266 });267 await exec(`sudo ipset del -! ${ipset.CONSTANTS.IPSET_QOS_OFF} ${identityIpsetName6}`).catch((err) => {268 log.error(`Failed to remove ${identityIpsetName6} from ${ipset.CONSTANTS.IPSET_QOS_OFF}`, err.message);269 });270 } else {271 await exec(`sudo ipset add -! ${ipset.CONSTANTS.IPSET_QOS_OFF} ${identityIpsetName}`).catch((err) => {272 log.error(`Failed to add ${identityIpsetName} to ${ipset.CONSTANTS.IPSET_QOS_OFF}`, err.message);273 });274 await exec(`sudo ipset add -! ${ipset.CONSTANTS.IPSET_QOS_OFF} ${identityIpsetName6}`).catch((err) => {275 log.error(`Failed to add ${identityIpsetName6} to ${ipset.CONSTANTS.IPSET_QOS_OFF}`, err.message);276 });277 }278 }279 async acl(state) {280 const identityIpsetName = this.constructor.getEnforcementIPsetName(this.getUniqueId());281 const identityIpsetName6 = this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6);282 if (state === true) { 283 await exec(`sudo ipset del -! ${ipset.CONSTANTS.IPSET_ACL_OFF} ${identityIpsetName}`).catch((err) => {284 log.error(`Failed to remove ${identityIpsetName} from ${ipset.CONSTANTS.IPSET_ACL_OFF}`, err.message);285 });286 await exec(`sudo ipset del -! ${ipset.CONSTANTS.IPSET_ACL_OFF} ${identityIpsetName6}`).catch((err) => {287 log.error(`Failed to remove ${identityIpsetName6} from ${ipset.CONSTANTS.IPSET_ACL_OFF}`, err.message);288 });289 } else {290 await exec(`sudo ipset add -! ${ipset.CONSTANTS.IPSET_ACL_OFF} ${identityIpsetName}`).catch((err) => {291 log.error(`Failed to add ${identityIpsetName} to ${ipset.CONSTANTS.IPSET_ACL_OFF}`, err.message);292 });293 await exec(`sudo ipset add -! ${ipset.CONSTANTS.IPSET_ACL_OFF} ${identityIpsetName6}`).catch((err) => {294 log.error(`Failed to add ${identityIpsetName6} to ${ipset.CONSTANTS.IPSET_ACL_OFF}`, err.message);295 });296 }297 }298 async aclTimer(policy = {}) {299 if (this._aclTimer)300 clearTimeout(this._aclTimer);301 if (policy.hasOwnProperty("state") && !isNaN(policy.time) && Number(policy.time) > Date.now() / 1000) {302 const nextState = policy.state;303 this._aclTimer = setTimeout(() => {304 log.info(`Set acl on ${this.getUniqueId()} to ${nextState} in acl timer`);305 this.setPolicy("acl", nextState);306 }, policy.time * 1000 - Date.now());307 }308 }309 async vpnClient(policy) {310 try {311 const state = policy.state;312 const profileId = policy.profileId;313 if (this._profileId && profileId !== this._profileId) {314 log.info(`Current VPN profile id id different from the previous profile id ${this._profileId}, remove old rule on identity ${this.getUniqueId()}`);315 const rule = new Rule("mangle").chn("FW_RT_TAG_DEVICE_5")316 .jmp(`SET --map-set ${VPNClient.getRouteIpsetName(this._profileId)} dst,dst --map-mark`)317 .comment(this._getPolicyKey());318 const rule4 = rule.clone().mdl("set", `--match-set ${this.constructor.getEnforcementIPsetName(this.getUniqueId())} src`);319 const rule6 = rule.clone().mdl("set", `--match-set ${this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6)} src`).fam(6);320 await exec(rule4.toCmd('-D')).catch((err) => {321 log.error(`Failed to remove ipv4 vpn client rule for ${this.getUniqueId()} ${this._profileId}`, err.message);322 });323 await exec(rule6.toCmd('-D')).catch((err) => {324 log.error(`Failed to remove ipv6 vpn client rule for ${this.getUniqueId()} ${this._profileId}`, err.message);325 });326 // remove rule that was set by state == null327 rule4.jmp(`MARK --set-xmark 0x0000/${routing.MASK_VC}`);328 rule6.jmp(`MARK --set-xmark 0x0000/${routing.MASK_VC}`);329 await exec(rule4.toCmd('-D')).catch((err) => {330 log.error(`Failed to remove ipv4 vpn client rule for ${this.getUniqueId()} ${this._profileId}`, err.message);331 });332 await exec(rule6.toCmd('-D')).catch((err) => {333 log.error(`Failed to remove ipv6 vpn client rule for ${this.getUniqueId()} ${this._profileId}`, err.message);334 });335 }336 this._profileId = profileId;337 if (!profileId) {338 log.warn("VPN client profileId is not specified for " + this.getUniqueId());339 return;340 }341 const rule = new Rule("mangle").chn("FW_RT_TAG_DEVICE_5")342 .jmp(`SET --map-set ${VPNClient.getRouteIpsetName(profileId)} dst,dst --map-mark`)343 .comment(this._getPolicyKey());344 await VPNClient.ensureCreateEnforcementEnv(profileId);345 await this.constructor.ensureCreateEnforcementEnv(this.getUniqueId());346 if (state === true) {347 const rule4 = rule.clone().mdl("set", `--match-set ${this.constructor.getEnforcementIPsetName(this.getUniqueId())} src`);348 const rule6 = rule.clone().mdl("set", `--match-set ${this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6)} src`).fam(6);349 await exec(rule4.toCmd('-A')).catch((err) => {350 log.error(`Failed to add ipv4 vpn client rule for ${this.getUniqueId()} ${profileId}`, err.message);351 });352 await exec(rule6.toCmd('-A')).catch((err) => {353 log.error(`Failed to add ipv6 vpn client rule for ${this.getUniqueId()} ${profileId}`, err.message);354 });355 // remove rule that was set by state == null356 rule4.jmp(`MARK --set-xmark 0x0000/${routing.MASK_VC}`);357 rule6.jmp(`MARK --set-xmark 0x0000/${routing.MASK_VC}`);358 await exec(rule4.toCmd('-D')).catch((err) => {359 log.error(`Failed to remove ipv4 vpn client rule for ${this.getUniqueId()} ${this._profileId}`, err.message);360 });361 await exec(rule6.toCmd('-D')).catch((err) => {362 log.error(`Failed to remove ipv6 vpn client rule for ${this.getUniqueId()} ${this._profileId}`, err.message);363 });364 }365 // null means off366 if (state === null) {367 // remove rule that was set by state == true368 const rule4 = rule.clone().mdl("set", `--match-set ${this.constructor.getEnforcementIPsetName(this.getUniqueId())} src`);369 const rule6 = rule.clone().mdl("set", `--match-set ${this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6)} src`).fam(6);370 await exec(rule4.toCmd('-D')).catch((err) => {371 log.error(`Failed to remove ipv4 vpn client rule for ${this.getUniqueId()} ${this._profileId}`, err.message);372 });373 await exec(rule6.toCmd('-D')).catch((err) => {374 log.error(`Failed to remove ipv6 vpn client rule for ${this.getUniqueId()} ${this._profileId}`, err.message);375 });376 // override target and clear vpn client bits in fwmark377 rule4.jmp(`MARK --set-xmark 0x0000/${routing.MASK_VC}`);378 rule6.jmp(`MARK --set-xmark 0x0000/${routing.MASK_VC}`);379 await exec(rule4.toCmd('-A')).catch((err) => {380 log.error(`Failed to add ipv4 vpn client rule for ${this.getUniqueId()} ${profileId}`, err.message);381 });382 await exec(rule6.toCmd('-A')).catch((err) => {383 log.error(`Failed to add ipv6 vpn client rule for ${this.getUniqueId()} ${profileId}`, err.message);384 });385 }386 // false means N/A387 if (state === false) {388 const rule4 = rule.clone().mdl("set", `--match-set ${this.constructor.getEnforcementIPsetName(this.getUniqueId())} src`);389 const rule6 = rule.clone().mdl("set", `--match-set ${this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6)} src`).fam(6);390 await exec(rule4.toCmd('-D')).catch((err) => {391 log.error(`Failed to remove ipv4 vpn client rule for ${this.getUniqueId()} ${profileId}`, err.message);392 });393 await exec(rule6.toCmd('-D')).catch((err) => {394 log.error(`Failed to remove ipv6 vpn client rule for ${this.getUniqueId()} ${profileId}`, err.message);395 });396 // remove rule that was set by state == null397 rule4.jmp(`MARK --set-xmark 0x0000/${routing.MASK_VC}`);398 rule6.jmp(`MARK --set-xmark 0x0000/${routing.MASK_VC}`);399 await exec(rule4.toCmd('-D')).catch((err) => {400 log.error(`Failed to remove ipv4 vpn client rule for ${this.getUniqueId()} ${this._profileId}`, err.message);401 });402 await exec(rule6.toCmd('-D')).catch((err) => {403 log.error(`Failed to remove ipv6 vpn client rule for ${this.getUniqueId()} ${this._profileId}`, err.message);404 });405 }406 } catch (err) {407 log.error("Failed to set VPN client access on " + this.getUniqueId());408 }409 }410 async _dnsmasq(policy) {411 const dnsCaching = policy.dnsCaching;412 const identityIpsetName = this.constructor.getEnforcementIPsetName(this.getUniqueId());413 const identityIpsetName6 = this.constructor.getEnforcementIPsetName(this.getUniqueId(), 6);414 if (dnsCaching === true) {415 let cmd = `sudo ipset del -! ${ipset.CONSTANTS.IPSET_NO_DNS_BOOST} ${identityIpsetName}`;416 await exec(cmd).catch((err) => {417 log.error(`Failed to enable dns cache on ${identityIpsetName} ${this.getUniqueId()}`, err);418 });419 cmd = `sudo ipset del -! ${ipset.CONSTANTS.IPSET_NO_DNS_BOOST} ${identityIpsetName6}`;420 await exec(cmd).catch((err) => {421 log.error(`Failed to enable dns cache on ${identityIpsetName6} ${this.getUniqueId()}`, err);422 });423 } else {424 let cmd = `sudo ipset add -! ${ipset.CONSTANTS.IPSET_NO_DNS_BOOST} ${identityIpsetName}`;425 await exec(cmd).catch((err) => {426 log.error(`Failed to disable dns cache on ${identityIpsetName} ${this.getUniqueId()}`, err);427 });428 cmd = `sudo ipset add -! ${ipset.CONSTANTS.IPSET_NO_DNS_BOOST} ${identityIpsetName6}`;429 await exec(cmd).catch((err) => {430 log.error(`Failed to disable dns cache on ${identityIpsetName6} ${this.getUniqueId()}`, err);431 });432 }433 }434}...

Full Screen

Full Screen

events.js

Source:events.js Github

copy

Full Screen

...29 *30 * @enum {string}31 */32events.EventType = {33 CLICK: goog.events.getUniqueId('c'),34 CONFIG_LOADED: goog.events.getUniqueId('cl'),35 DOUBLE_CLICK: goog.events.getUniqueId('dc'),36 DOUBLE_CLICK_END: goog.events.getUniqueId('dce'),37 DRAG: goog.events.getUniqueId('dg'),38 LAYOUT_LOADED: goog.events.getUniqueId('ll'),39 LONG_PRESS: goog.events.getUniqueId('lp'),40 LONG_PRESS_END: goog.events.getUniqueId('lpe'),41 POINTER_DOWN: goog.events.getUniqueId('pd'),42 POINTER_UP: goog.events.getUniqueId('pu'),43 POINTER_OVER: goog.events.getUniqueId('pv'),44 POINTER_OUT: goog.events.getUniqueId('po'),45 REFRESH: goog.events.getUniqueId('rf'),46 SETTINGS_READY: goog.events.getUniqueId('sr'),47 SURROUNDING_TEXT_CHANGED: goog.events.getUniqueId('stc'),48 SWIPE: goog.events.getUniqueId('s'),49 CONTEXT_UPDATE: goog.events.getUniqueId('cu'),50 CONTEXT_FOCUS: goog.events.getUniqueId('cf'),51 CONTEXT_BLUR: goog.events.getUniqueId('cb'),52 VISIBILITY_CHANGE: goog.events.getUniqueId('vc'),53 MODEL_UPDATE: goog.events.getUniqueId('mu'),54 URL_CHANGED: goog.events.getUniqueId('uc'),55 UPDATE_SETTINGS: goog.events.getUniqueId('us'),56 VOICE_STATE_CHANGE: goog.events.getUniqueId('vsc'),57 HWT_NETWORK_ERROR: goog.events.getUniqueId('hne'),58 FRONT_TOGGLE_LANGUAGE_STATE: goog.events.getUniqueId('ftls')59};60/**61 * The event when the data is loaded complete.62 *63 * @param {!Object} data The layout data.64 * @constructor65 * @extends {goog.events.Event}66 */67events.LayoutLoadedEvent = function(data) {68 goog.base(this, events.EventType.LAYOUT_LOADED);69 /**70 * The layout data.71 *72 * @type {!Object}...

Full Screen

Full Screen

hwt_eventtype.js

Source:hwt_eventtype.js Github

copy

Full Screen

...25 *26 * @enum {string}27 */28i18n.input.hwt.EventType = {29 BACKSPACE: goog.events.getUniqueId('b'),30 CANDIDATE_SELECT: goog.events.getUniqueId('cs'),31 COMMIT: goog.events.getUniqueId('c'),32 COMMIT_START: goog.events.getUniqueId('hcs'),33 COMMIT_END: goog.events.getUniqueId('hce'),34 RECOGNITION_READY: goog.events.getUniqueId('rr'),35 ENTER: goog.events.getUniqueId('e'),36 HANDWRITING_CLOSED: goog.events.getUniqueId('hc'),37 MOUSEUP: goog.events.getUniqueId('m'),38 SPACE: goog.events.getUniqueId('s')39};40/**41 * Candidate select event.42 *43 * @param {string} candidate The candidate.44 * @constructor45 * @extends {goog.events.Event}46 */47i18n.input.hwt.CandidateSelectEvent = function(candidate) {48 goog.base(this, i18n.input.hwt.EventType.CANDIDATE_SELECT);49 /**50 * The candidate.51 *52 * @type {string}...

Full Screen

Full Screen

helpers.js

Source:helpers.js Github

copy

Full Screen

1import { getFullApiUrl, getRandomColor, getUniqueID } from '../';2const GROUP_ID = 'test';3const api = 'https://lab.lectrum.io/react/api';4describe('helpers: ', () => {5 test('getFullApiUrl should be a function', () => {6 expect(typeof getFullApiUrl).toBe('function');7 });8 test('getFullApiUrl should throw an err for wrong argument', () => {9 const getFullApiNameWithError = () => {10 getFullApiUrl(null, 1);11 };12 expect(getFullApiNameWithError).toThrowError(13 `'api' and 'GROUP_ID' should be a string`14 );15 });16 test('getFullApiUrl should return full api URL', () => {17 expect(getFullApiUrl(api, GROUP_ID)).toBe(`${api}/${GROUP_ID}`);18 });19});20describe('helpers: ', () => {21 test('getRandomColor should be a function', () => {22 expect(typeof getRandomColor).toBe('function');23 });24 test('getRandomColor should return a string starts with # symbol', () => {25 expect(getRandomColor()[0]).toBe('#');26 });27 test('getRandomColor should return full api URL', () => {28 expect(getRandomColor().length).toBe(7);29 });30});31describe('helpers: ', () => {32 test('getUniqueID should be a function', () => {33 expect(typeof getUniqueID).toBe('function');34 });35 test('getUniqueID should return a string', () => {36 expect(typeof getUniqueID(4)).toBe('string');37 });38 test('getUniqueID(10) should return UniqueID with length = 10', () => {39 expect(getUniqueID(10).length).toBe(10);40 });41 test('getUniqueID() should return UniqueID with length = 15', () => {42 expect(getUniqueID().length).toBe(15);43 });44 test('getUniqueID should throw an err for wrong argument', () => {45 const getUniqueIDWithError = () => {46 getUniqueID('aaaa');47 };48 expect(getUniqueIDWithError).toThrowError('The function argument should be a number!');49 });...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

1import { getUniqueID, getRandomColor } from './index';2describe('helpers.index.js getUniqueID function tested: ', () => {3 test('getUniqueID function should be a function', () => {4 expect(typeof getUniqueID).toBe('function');5 });6 test('getUniqueID function should be a string', () => {7 expect(typeof getUniqueID()).toBe('string');8 });9 test('getUniqueID function call result should have length of 15 elements', () => {10 expect(getUniqueID().length).toEqual(15);11 });12 test('getUniqueID function argument should be a number', () => {13 function getFullNameWithError () {14 getUniqueID(null, 1);15 }16 expect(getFullNameWithError).toThrowError(17 'The function argument should be a number!'18 );19 });20});21describe('helpers/ index.js getUniqueID getRandomColor tested: ', () => {22 test('getRandomColor function should be a function', () => {23 expect(typeof getRandomColor).toBe('function');24 });25 test('getRandomColor function should be a string', () => {26 expect(typeof getRandomColor()).toBe('string');27 });28 test('getRandomColor function call result should have length = 7', () => {29 expect(getRandomColor().length).toEqual(7);30 });31 test('getRandomColor function call result should started from # symbol', () => {32 expect(getRandomColor().charAt(0)).toBe('#');33 });...

Full Screen

Full Screen

getuniqueid.js

Source:getuniqueid.js Github

copy

Full Screen

...8 var editor = this.editor,9 editable = editor.editable(),10 id = 'foo',11 mock = sinon.stub( CKEDITOR.dom.domObject.prototype, 'getUniqueId' ).returns( id );12 assert.isNotNull( id, editable.getUniqueId(), 'id on first call' );13 assert.areSame( id, editable.getUniqueId(), 'id on second call' );14 mock.restore();15 var origMethod = CKEDITOR.dom.domObject.prototype.getUniqueId;16 CKEDITOR.dom.domObject.prototype.getUniqueId = function() {17 throw( 'error' );18 };19 var actualId = editable.getUniqueId();20 CKEDITOR.dom.domObject.prototype.getUniqueId = origMethod;21 assert.areSame( id, actualId, 'id when error thrown' );22 }23 } );...

Full Screen

Full Screen

getUniqueId-test.js

Source:getUniqueId-test.js Github

copy

Full Screen

1import getUniqueId from '../getUniqueId';2describe('getUniqueId', () => {3 it('ids start from 0', () => {4 const id = getUniqueId();5 expect(id).toEqual(0);6 });7 it('next ids requested are sequential', () => {8 expect(getUniqueId()).toEqual(1);9 expect(getUniqueId()).toEqual(2);10 });11 it('ids are globally unique', () => {12 const id1 = getUniqueId();13 const id2 = getUniqueId();14 expect(id1).not.toEqual(id2);15 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', () => {2 it('Gets, types and asserts', () => {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Gets, types and asserts', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add('getUniqueId', () => {2 return Cypress._.uniqueId('id')3})4Cypress.Commands.add('getUniqueId', () => {5 return Cypress._.uniqueId('id')6})7describe('Test', () => {8 it('test', () => {9 cy.getUniqueId().then((id) => {10 cy.log(id)11 })12 })13})14describe('Test', () => {15 it('test', () => {16 cy.getUniqueId().then((id) => {17 cy.log(id)18 })19 })20})21describe('Test', () => {22 it('test', () => {23 cy.getUniqueId().then((id) => {24 cy.log(id)25 })26 })27})28describe('Test', () => {29 it('test', () => {30 cy.getUniqueId().then((id) => {31 cy.log(id)32 })33 })34})35describe('Test', () => {36 it('test', () => {37 cy.getUniqueId().then((id) => {38 cy.log(id)39 })40 })41})42describe('Test', () => {43 it('test', () => {44 cy.getUniqueId().then((id) => {45 cy.log(id)46 })47 })48})49describe('Test', () => {50 it('test', () => {51 cy.getUniqueId().then((id) => {52 cy.log(id)53 })54 })55})56describe('Test', () => {57 it('test', () => {58 cy.getUniqueId().then((id) => {59 cy.log(id)60 })61 })62})63describe('Test', () => {64 it('test', () => {65 cy.getUniqueId().then((id) => {66 cy.log(id)67 })68 })69})70describe('Test', ()

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.getUniqueId()2.then((id) => {3 cy.log(id)4})5import 'cypress-unique-selector'63. You can now use the `cy.getUniqueId()` command in your tests

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress 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