How to use resetPromise method in wpt

Best JavaScript code snippet using wpt

class.notifications.audio.js

Source:class.notifications.audio.js Github

copy

Full Screen

...39 this.ms_timeout = 0;40 this.is_playing = false;41 this.message_timeout = 0;42 this.callback = null;43 this.resetPromise();44 this.listen();45}46/**47 * Starts main loop.48 *49 * @return int Interval ID.50 */51ZBX_NotificationsAudio.prototype.listen = function() {52 var ms_step = 10;53 if (!this.audio) {54 return;55 }56 function resolveAudioState() {57 if (this.play_once_on_ready) {58 return this.once();59 }60 this.ms_timeout -= ms_step;61 this.is_playing = (this.ms_timeout > 0.0001);62 this.audio.volume = this.is_playing ? 1 : 0;63 if (this.ms_timeout < 0.0001) {64 this._resolve_timeout(this);65 this.ms_timeout = 0;66 this.seek(0);67 if (this.callback !== null) {68 this.callback();69 this.callback = null;70 }71 }72 }73 resolveAudioState.call(this);74 return setInterval(resolveAudioState.bind(this), ms_step);75};76/**77 * File is applied only if it is different than on instate, so this method may be called repeatedly, and will not78 * interrupt playback.79 *80 * @param {string} file Audio file path relative to DOCUMENT_ROOT/audio/ directory.81 *82 * @return {ZBX_NotificationsAudio}83 */84ZBX_NotificationsAudio.prototype.file = function(file) {85 if (!this.audio) {86 return this;87 }88 if (this.wave == file) {89 return this;90 }91 this.wave = file;92 this.seek(0);93 if (!this.wave) {94 this.audio.removeAttribute('src');95 }96 else {97 this.audio.src = 'audio/' + this.wave;98 }99 return this;100};101/**102 * Sets player seek position. There are no safety checks, if one decides to seek out of audio file bounds - no audio.103 *104 * @param {number} seconds105 *106 * @return {ZBX_NotificationsAudio}107 */108ZBX_NotificationsAudio.prototype.seek = function(seconds) {109 if (!this.audio) {110 return this;111 }112 if (this.audio.readyState > 0) {113 this.audio.currentTime = seconds;114 }115 return this;116};117/**118 * Once file duration is known, this method seeks player to the beginning and sets timeout equal to file duration.119 *120 * @return {Promise}121 */122ZBX_NotificationsAudio.prototype.once = function() {123 if (!this.audio) {124 return this.resetPromise();125 }126 if (this.play_once_on_ready && this.audio.readyState >= 3) {127 this.play_once_on_ready = false;128 var timeout = (this.message_timeout == 0)129 ? this.audio.duration130 : Math.min(this.message_timeout, this.audio.duration);131 return this.timeout(timeout);132 }133 this.play_once_on_ready = true;134 return this.resetPromise();135};136/**137 * An alias method. Player is stopped by exhausting timeout.138 *139 * @return {ZBX_NotificationsAudio}140 */141ZBX_NotificationsAudio.prototype.stop = function() {142 this.ms_timeout = 0;143 this.is_playing = false;144 return this;145};146/**147 * Mute player.148 *149 * @return {ZBX_NotificationsAudio}150 */151ZBX_NotificationsAudio.prototype.mute = function() {152 if (!this.audio) {153 return this;154 }155 this.audio.muted = true;156 return this;157};158/**159 * Unmute player.160 *161 * @return {ZBX_NotificationsAudio}162 */163ZBX_NotificationsAudio.prototype.unmute = function() {164 if (!this.audio) {165 return this;166 }167 this.audio.muted = false;168 return this;169};170/**171 * Tune player.172 *173 * @argument {object} options174 * @argument {bool} options[playOnce] Player will not play in the loop if set to true.175 * @argument {number} options[messageTimeout] Message display timeout. Used to avoid playing when message box is gone.176 * @argument {mixed} options[callback]177 *178 * @return {ZBX_NotificationsAudio}179 */180ZBX_NotificationsAudio.prototype.tune = function(options) {181 if (!this.audio) {182 return this;183 }184 if (typeof options.playOnce === 'boolean') {185 this.audio.loop = !options.playOnce;186 }187 if (typeof options.messageTimeout === 'number') {188 this.message_timeout = options.messageTimeout;189 }190 if (typeof options.callback !== 'undefined') {191 this.callback = options.callback;192 }193 return this;194};195/**196 * Assigns new promise property in place, any pending promise will not be resolved.197 *198 * @return {Promise}199 */200ZBX_NotificationsAudio.prototype.resetPromise = function() {201 this.timeout_promise = new Promise(function(resolve, reject) {202 this._resolve_timeout = resolve;203 }.bind(this));204 return this.timeout_promise;205};206/**207 * Will play in loop for seconds given, since this call. If "0" given - will just not play. If "-1" is given - file will208 * be played once.209 *210 * @param {number} seconds211 *212 * @return {Promise}213 */214ZBX_NotificationsAudio.prototype.timeout = function(seconds) {215 if (!this.audio) {216 return this.resetPromise();217 }218 if (this.message_timeout == 0) {219 this.stop();220 return this.resetPromise();221 }222 if (!this.audio.loop) {223 if (seconds == ZBX_Notifications.ALARM_ONCE_PLAYER) {224 return this.once();225 }226 else if (this.is_playing) {227 return this.timeout_promise;228 }229 else {230 this.audio.load();231 }232 }233 this.ms_timeout = seconds * 1000;234 return this.resetPromise();235};236/**237 * Get current player seek position.238 *239 * @return {float} Amount of seconds.240 */241ZBX_NotificationsAudio.prototype.getSeek = function() {242 if (!this.audio) {243 return 0;244 }245 return this.audio.currentTime;246};247/**248 * Get the time player will play for....

Full Screen

Full Screen

ResetPasswordService.spec.ts

Source:ResetPasswordService.spec.ts Github

copy

Full Screen

1import FakeUsersRepository from '../repositories/fakes/FakeUsersRepository'2import FakeMailProvider from '@shared/providers/MailProvider/fakes/FakeMailProvider'3import FakeUserTokensRepository from '@users/repositories/fakes/FakeUserTokensRepository'4import FakeHashProvider from '@users/providers/HashProvider/fakes/FakeHashProvider'5import ResetPasswordService from './ResetPasswordService'6import AppError from '@shared/errors/appError'7let fakeUsersRepository: FakeUsersRepository,8fakeMailProvider: FakeMailProvider,9fakeHashProvider: FakeHashProvider,10fakeUserTokensRepository: FakeUserTokensRepository,11resetPassword: ResetPasswordService12describe('ResetPassword', () => {13 beforeEach(() => {14 fakeUsersRepository = new FakeUsersRepository()15 fakeMailProvider = new FakeMailProvider()16 fakeUserTokensRepository = new FakeUserTokensRepository()17 fakeHashProvider = new FakeHashProvider()18 resetPassword = new ResetPasswordService(fakeUsersRepository, fakeUserTokensRepository, fakeHashProvider)19 })20 it('Should be able to reset the password ', async () => {21 const user = await fakeUsersRepository.create({22 email: 'test@email.com',23 name: 'John Doe',24 password: '123'25 })26 const { token } = await fakeUserTokensRepository.generate(user.id)27 const generateHashSpy = jest.spyOn(fakeHashProvider, 'generateHash')28 await resetPassword.execute({29 token,30 password: '123456'31 })32 const updatedUser = await fakeUsersRepository.findById(user.id)33 const isHashed = await fakeHashProvider.compare('123456', updatedUser?.password || '')34 expect(generateHashSpy).toHaveBeenCalledWith('123456')35 expect(isHashed).toBe(true)36 })37 it('Should not be able to reset password with an invalid token', async () => {38 const resetPromise = resetPassword.execute({39 token: 'invalid-token',40 password: '123456'41 })42 await expect(resetPromise).rejects.toBeInstanceOf(AppError)43 })44 it('Should not be able to reset password of an invalid user', async () => {45 const {token} = await fakeUserTokensRepository.generate('invalid-user')46 const resetPromise = resetPassword.execute({47 token,48 password: '123456'49 })50 await expect(resetPromise).rejects.toBeInstanceOf(AppError)51 })52 it('Should not be able to reset the password with a token older than 2h', async () => {53 const user = await fakeUsersRepository.create({54 email: 'test@email.com',55 name: 'John Doe',56 password: '123'57 })58 const { token } = await fakeUserTokensRepository.generate(user.id)59 jest.spyOn(Date, 'now').mockImplementationOnce(() => {60 const customDate = new Date()61 return customDate.setHours(customDate.getHours() + 2, customDate.getMinutes() + 1)62 })63 const resetPromise = resetPassword.execute({64 token,65 password: '123456'66 })67 await expect(resetPromise).rejects.toBeInstanceOf(AppError)68 })...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

1import React from "react";2import ReactDOM from "react-dom";3import { act } from "react-dom/test-utils";4import ForgotPassword from "./index";5import { FirebaseContext } from "../Firebase";6import { SessionContext } from "../Session";7import { MemoryRouter } from "react-router-dom";8it("renders without crashing", async () => {9 const div = document.createElement("div");10 const resetPromise = {11 resolve: undefined,12 reject: undefined13 };14 const fakebase = {15 sendPasswordResetEmail: email =>16 new Promise((resolve, reject) => {17 resetPromise.resolve = resolve;18 resetPromise.reject = reject;19 })20 };21 act(() => {22 ReactDOM.render(23 <MemoryRouter>24 <FirebaseContext.Provider value={fakebase}>25 <ForgotPassword />26 </FirebaseContext.Provider>27 </MemoryRouter>,28 div29 );30 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const webPageTest = new wpt('WPT_API_KEY');3webPageTest.resetPromise('TEST_ID')4 .then(data => {5 console.log(data);6 })7 .catch(err => {8 console.log(err);9 });10### getLocationsPromise()11const wpt = require('webpagetest');12const webPageTest = new wpt('WPT_API_KEY');13webPageTest.getLocationsPromise()14 .then(data => {15 console.log(data);16 })17 .catch(err => {18 console.log(err);19 });20### getLocationsPromise('state')21const wpt = require('webpagetest');22const webPageTest = new wpt('WPT_API_KEY');23webPageTest.getLocationsPromise('CA')24 .then(data => {25 console.log(data);26 })27 .catch(err => {28 console.log(err);29 });30### getTestersPromise()31const wpt = require('webpagetest');32const webPageTest = new wpt('WPT_API_KEY');33webPageTest.getTestersPromise()34 .then(data => {35 console.log(data);36 })37 .catch(err => {38 console.log(err);39 });40### getTestersPromise('location')41const wpt = require('webpagetest');42const webPageTest = new wpt('WPT_API_KEY');43webPageTest.getTestersPromise('Dulles:Chrome')44 .then(data => {45 console.log(data);46 })47 .catch(err => {48 console.log(err);49 });50### getTestStatusPromise('testId')

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.resetPromise("Test ID")4.then(function(data) {5 console.log(data);6})7.catch(function(err) {8 console.log(err);9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12wpt.runPromise("www.google.com", {13})14.then(function(data) {15 console.log(data);16})17.catch(function(err) {18 console.log(err);19});20var wpt = require('webpagetest');21var wpt = new WebPageTest('www.webpagetest.org');22wpt.getLocationsPromise()23.then(function(data) {24 console.log(data);25})26.catch(function(err) {27 console.log(err);28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31wpt.getTestersPromise()32.then(function(data) {33 console.log(data);34})35.catch(function(err) {36 console.log(err);37});38var wpt = require('webpagetest');39var wpt = new WebPageTest('www.webpagetest.org');40wpt.getBrowsersPromise()41.then(function(data) {42 console.log(data);43})44.catch(function(err) {45 console.log(err);46});47var wpt = require('webpagetest');48var wpt = new WebPageTest('www.webpagetest.org');49wpt.getTestersPromise()50.then(function(data) {51 console.log(data);52})53.catch(function(err) {54 console.log(err);55});56var wpt = require('webpagetest');57var wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const wptPromise = new wpt('API_KEY');3const runWpt = async (url, location) => {4 const test = await wptPromise.runTest(url, {5 });6 const testId = test.data.testId;7 const testStatus = await wptPromise.getTestStatus(testId);8 const testResults = await wptPromise.getTestResults(testId);9 console.log(testResults);10};11const wpt = require('webpagetest');12const wptPromise = new wpt('API_KEY');13const runWpt = async (url, location) => {14 const test = await wptPromise.runTest(url, {15 });16 const testId = test.data.testId;17 const testStatus = await wptPromise.getTestStatus(testId);18 const testResults = await wptPromise.getTestResults(testId);19 console.log(testResults);20};21const wpt = require('webpagetest');22const wptPromise = new wpt('API_KEY');23const runWpt = async (url, location) => {24 const test = await wptPromise.runTest(url, {25 });26 const testId = test.data.testId;27 const testStatus = await wptPromise.getTestStatus(testId);28 const testResults = await wptPromise.getTestResults(testId);29 console.log(testResults);30};31const wpt = require('webpagetest');32const wptPromise = new wpt('API_KEY');33const runWpt = async (url, location) => {34 const test = await wptPromise.runTest(url, {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptDriver = require("wpt-driver");2var driver = wptDriver.getDriver();3var By = require('selenium-webdriver').By;4var until = require('selenium-webdriver').until;5var assert = require('assert');6var promise = require('selenium-webdriver').promise;7var test = require('selenium-webdriver/testing');8test.describe('Google Search', function() {9 test.it('should work', function() {10 driver.findElement(By.name('q')).sendKeys('webdriver');11 driver.findElement(By.name('btnG')).click();12 driver.wait(until.titleIs('webdriver - Google Search'), 1000);13 });14});15var wptDriver = require("wpt-driver");16var driver = wptDriver.getDriver();17var By = require('selenium-webdriver').By;18var until = require('selenium-webdriver').until;19var assert = require('assert');20var promise = require('selenium-webdriver').promise;21var test = require('selenium-webdriver/testing');22test.describe('Google Search', function() {23 test.it('should work', function() {24 driver.findElement(By.name('q')).sendKeys('webdriver');25 driver.findElement(By.name('btnG')).click();26 driver.wait(until.titleIs('webdriver - Google Search'), 1000);27 });28});29var wptDriver = require("wpt-driver");30var driver = wptDriver.getDriver();31var By = require('selenium-webdriver').By;32var until = require('selenium-webdriver').until;33var assert = require('assert');34var promise = require('selenium-webdriver').promise;35var test = require('selenium-webdriver/testing');36test.describe('Google Search', function() {37 test.it('should work', function() {

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