Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TSLarson committed Oct 8, 2024
1 parent 6b3a1cc commit 38d53bb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
68 changes: 40 additions & 28 deletions test/captcha_signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import en from '../src/i18n/en';

const lockOpts = {
allowedConnections: ['db'],
rememberLastLogin: false,
initialScreen: 'signUp'
rememberLastLogin: false
};

const svgCaptchaRequiredResponse1 = {
Expand Down Expand Up @@ -33,39 +32,40 @@ describe('captcha on signup', function () {
describe('svg-captcha', () => {
describe('when the api returns a new challenge', function () {
beforeEach(function (done) {
this.stub = h.stubGetChallenge({ required: false });
this.stub = h.stubGetSignupChallenge([svgCaptchaRequiredResponse1, svgCaptchaRequiredResponse2]);
this.lock = h.displayLock('', lockOpts, done);
this.lock = h.displayLock('', lockOpts, () => {
h.clickSignUpTab();
h.waitUntilExists(this.lock, '.auth0-lock-with-terms', () => {
done();
});
});
});

afterEach(function () {
this.lock.hide();
});

it('sign-up tab should be active', function (done) {
h.waitUntilExists(this.lock, '.auth0-lock-tabs-current', () => {
expect(h.isSignUpTabCurrent(this.lock)).to.be.ok();
done();
});
it('sign-up tab should be active', function () {
expect(h.isSignUpTabCurrent(this.lock)).to.be.ok();
});

it('should show the captcha input', function (done) {
expect(h.isSignUpTabCurrent(this.lock)).to.be.ok();
setTimeout(() => {
expect(h.qInput(this.lock, 'captcha', false)).to.be.ok();
done();
}, 500);
});

it('should require another challenge when clicking the refresh button', function (done) {
h.waitUntilExists(this.lock, '.auth0-lock-captcha-refresh', () => {
h.clickRefreshCaptchaButton(this.lock);

setTimeout(() => {
expect(h.q(this.lock, '.auth0-lock-captcha-image').style.backgroundImage).to.equal(
`url("${svgCaptchaRequiredResponse2.image}")`
);
done();
}, 200);
});
h.clickRefreshCaptchaButton(this.lock);
setTimeout(() => {
expect(h.q(this.lock, '.auth0-lock-captcha-image').style.backgroundImage).to.equal(
`url("${svgCaptchaRequiredResponse2.image}")`
);
done();
}, 200);
});

it('should submit the captcha provided by the user', function (done) {
Expand All @@ -86,12 +86,16 @@ describe('captcha on signup', function () {
});
});

describe('when the challenge api returns required: false', function () {
describe('when the challenge api returns required: false for signup', function () {
beforeEach(function (done) {
h.stubGetSignupChallenge({
required: false
h.stubGetChallenge([svgCaptchaRequiredResponse1, svgCaptchaRequiredResponse2]);
h.stubGetSignupChallenge({ required: false });
this.lock = h.displayLock('', lockOpts, () => {
h.clickSignUpTab();
h.waitUntilExists(this.lock, '.auth0-lock-with-terms', () => {
done();
});
});
this.lock = h.displayLock('', lockOpts, done);
});

afterEach(function () {
Expand Down Expand Up @@ -127,8 +131,14 @@ describe('captcha on signup', function () {
describe('recaptcha', () => {
describe('when the api returns a new challenge', function () {
beforeEach(function (done) {
this.stub = h.stubGetChallenge({ required: false });
this.stub = h.stubGetSignupChallenge([recaptchav2Response]);
this.lock = h.displayLock('', lockOpts, done);
this.lock = h.displayLock('', lockOpts, () => {
h.clickSignUpTab();
h.waitUntilExists(this.lock, '.auth0-lock-with-terms', () => {
done();
});
});
});

afterEach(function () {
Expand Down Expand Up @@ -159,19 +169,21 @@ describe('captcha on signup', function () {
let notRequiredStub;
let loginGetChallengeStub;
beforeEach(function (done) {
notRequiredStub = h.stubGetSignupChallenge({
required: false
});
loginGetChallengeStub = h.stubGetChallenge([recaptchav2Response]);
this.lock = h.displayLock('', lockOpts, done);
notRequiredStub = h.stubGetSignupChallenge({ required: false });
this.lock = h.displayLock('', lockOpts, () => {
h.clickSignUpTab();
h.waitUntilExists(this.lock, '.auth0-lock-with-terms', () => {
done();
});
});
});

afterEach(function () {
this.lock.hide();
});

it('should not show the captcha input', function () {
expect(loginGetChallengeStub.calledOnce).to.be.false;
expect(h.q(this.lock, '.auth0-lock-recaptchav2')).to.not.be.ok();
});

Expand Down
7 changes: 7 additions & 0 deletions test/helper/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ export const clickRefreshCaptchaButton = (lock, connection) =>

export const clickSocialConnectionButton = (lock, connection) =>
clickFn(lock, `.auth0-lock-social-button[data-provider='${connection}']`);

export const clickSignUpTab = (lock) => {
// there is no id for the unselected tab (Login is selected by default)
const signUpTab = window.document['querySelector']('.auth0-lock-tabs > li:nth-child(2) > a');
Simulate.click(signUpTab, {});
}

Check notice

Code scanning / CodeQL

Semicolon insertion Note test

Avoid automated semicolon insertion (98% of all statements in
the enclosing script
have an explicit semicolon).

const fillInput = (lock, name, str) => {
Simulate.change(qInput(lock, name, true), { target: { value: str } });
};
Expand Down

0 comments on commit 38d53bb

Please sign in to comment.