-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suscription feature testcases #945
base: develop
Are you sure you want to change the base?
Changes from all commits
cf4fc6f
2417931
0ff4501
cfa90f1
982d066
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const phoneNumberRegex = | ||
/^[+]{1}(?:[0-9\-\\(\\)\\/.]\s?){6,15}[0-9]{1}$/; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render, fillIn, click } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
|
||
module('Integration | Component | subscribe', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('subscribe form renders and functions correctly', async function (assert) { | ||
Comment on lines
+6
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that you are writing an integration test for For template files like this, we typically write acceptance tests, not integration tests. This is because we want to simulate the full user experience by testing what the user sees when they visit the Integration tests are used to test individual components to ensure they render correctly and behave as expected in isolation, including how they respond to different inputs. |
||
assert.expect(8); | ||
|
||
this.set('email', '[email protected]'); | ||
this.set('phone', '1234567890'); | ||
this.set('isSubscribed', false); | ||
|
||
this.set('updateEmail', (event) => { | ||
this.set('email', event.target.value); | ||
}); | ||
|
||
this.set('updatePhone', (event) => { | ||
this.set('phone', event.target.value); | ||
}); | ||
|
||
this.set('onSubmit', (event) => { | ||
event.preventDefault(); | ||
this.set('isSubscribed', true); | ||
}); | ||
|
||
await render(hbs` | ||
<form {{on "submit" this.onSubmit}} data-test-subscribe-form> | ||
<label for="email" data-test-email-label>Email:</label> | ||
<input | ||
type="email" | ||
id="email" | ||
value={{this.email}} | ||
data-test-email-input | ||
{{on "input" this.updateEmail}} | ||
/> | ||
|
||
<label for="phone" data-test-phone-label>Phone:</label> | ||
<input | ||
type="tel" | ||
id="phone" | ||
value={{this.phone}} | ||
data-test-phone-input | ||
{{on "input" this.updatePhone}} | ||
/> | ||
|
||
<button type="submit" data-test-submit-button>Subscribe</button> | ||
</form> | ||
`); | ||
|
||
assert | ||
.dom('[data-test-email-label]') | ||
.hasText('Email:', 'Email label is rendered'); | ||
|
||
assert | ||
.dom('[data-test-phone-label]') | ||
.hasText('Phone:', 'Phone label is rendered'); | ||
|
||
assert | ||
.dom('[data-test-submit-button]') | ||
.hasText('Subscribe', 'Submit button is rendered'); | ||
|
||
assert | ||
.dom('[data-test-email-input]') | ||
.hasValue('[email protected]', 'Email initial value is correct'); | ||
|
||
assert | ||
.dom('[data-test-phone-input]') | ||
.hasValue('1234567890', 'Phone initial value is correct'); | ||
|
||
await fillIn('[data-test-email-input]', '[email protected]'); | ||
await fillIn('[data-test-phone-input]', '0987654321'); | ||
|
||
assert | ||
.dom('[data-test-email-input]') | ||
.hasValue('[email protected]', 'Email value updates correctly'); | ||
|
||
assert | ||
.dom('[data-test-phone-input]') | ||
.hasValue('0987654321', 'Phone value updates correctly'); | ||
|
||
await click('[data-test-submit-button]'); | ||
|
||
assert.ok( | ||
this.isSubscribed, | ||
'User should be subscribed after form submission', | ||
); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'website-www/tests/helpers'; | ||
import Service from '@ember/service'; | ||
import { tracked } from '@glimmer/tracking'; | ||
class MockLoginService extends Service { | ||
@tracked isLoggedIn = false; | ||
} | ||
|
||
module('Unit | Controller | Subscribe', function (hooks) { | ||
setupTest(hooks); | ||
|
||
hooks.beforeEach(function () { | ||
this.owner.register('service:login', MockLoginService); | ||
}); | ||
|
||
test('it exists', function (assert) { | ||
let controller = this.owner.lookup('controller:subscribe'); | ||
assert.ok(controller); | ||
}); | ||
|
||
test('it correctly identifies when a user is logged in', function (assert) { | ||
let controller = this.owner.lookup('controller:join'); | ||
let loginService = this.owner.lookup('service:login'); | ||
|
||
loginService.isLoggedIn = false; | ||
loginService.userData = null; | ||
assert.notOk( | ||
controller.isLoggedIn, | ||
'isLoggedIn is false when user is not logged in', | ||
); | ||
|
||
loginService.isLoggedIn = true; | ||
loginService.userData = null; | ||
assert.notOk( | ||
controller.isLoggedIn, | ||
'isLoggedIn is false when userData is null', | ||
); | ||
|
||
loginService.isLoggedIn = true; | ||
loginService.userData = { id: '123', username: 'testuser' }; | ||
assert.ok( | ||
controller.isLoggedIn, | ||
'isLoggedIn is true when user is logged in and userData is present', | ||
); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @tejaskh3, I see we are not using any regex in tests. and that too from this file.
Do we need it?