-
Notifications
You must be signed in to change notification settings - Fork 7
/
cypress-otp.test.js
41 lines (37 loc) · 1.11 KB
/
cypress-otp.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/// <reference types="Cypress" />
context("Tests", () => {
const getSecretFromPage = () =>
cy.waitUntil(() =>
cy
.contains("Demo Secret")
.then(
$el =>
$el
.parent()
.parent()
.find("input")[0].value
)
.then(value => value !== "Loading..." && value)
);
const fillFormWithSecret = token => {
cy.contains("Verify Token").click();
cy.contains("Please input a token.")
.then($el => $el.parent().find("input"))
.type(token);
cy.contains("The token is valid in this current window.").should("be.visible");
};
it("The OTP token generation should work", () => {
// go to the baseUrl page (see cypress.json)
cy.visit("/");
getSecretFromPage().then(secret => {
cy.task("generateOTP", secret).then(fillFormWithSecret);
});
});
it("The last OTP secret shuold be used if not passed everytime", () => {
cy.visit("/");
getSecretFromPage().then(secret => {
cy.task("generateOTP", secret);
cy.task("generateOTP").then(fillFormWithSecret);
});
});
});