generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Cache test case #79
Open
SagarBajpai
wants to merge
15
commits into
develop
Choose a base branch
from
CacheTestCase
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cache test case #79
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8f1f129
Feat: test file initiated
SagarBajpai c8d6278
feat(cache-clear-test): Unit tests written
SagarBajpai 946c49e
Ref(test): logic fixed in test
SagarBajpai 3a1e377
Ref: tests change suggested in PR
SagarBajpai c98f048
feat(test) : ember test selectors added
SagarBajpai e1c6cbe
Ref: minor changes
SagarBajpai cd0a31d
Ref: skipping tests
SagarBajpai 0ca87c7
Ref: ember-test-selectors strip set to true
SagarBajpai cea0204
Updated the tests for #67
ankushdharkar defdfd9
Merge branch 'develop' into CacheTestCase
ankushdharkar 7c272ab
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-m…
rohan09-raj aaa2963
removed options for strip
rohan09-raj a37efc5
fixed the repetitive declaration of string
rohan09-raj 6db89f1
Fixed package-lock.json
rohan09-raj d7fec52
Fixed a redundant space in a constant
rohan09-raj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { module, skip } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { click, render, find } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
|
||
const EPOCH_TIMESTAMP = 1626242030; | ||
const HUMAN_TIME = 'July 13, 2021 10:53:50 PM IST'; | ||
const CACHE_CLEAR_CLICKED = 'CACHE_CLEAR_CLICKED'; | ||
|
||
module('Integration | Component | self-clear-cache', (hooks) => { | ||
setupRenderingTest(hooks); | ||
|
||
skip('it shows last time user cleared the cache', async function (assert) { | ||
assert.expect(1); | ||
|
||
// Assemble | ||
this.set('lastTime', EPOCH_TIMESTAMP); | ||
|
||
await render(hbs`<SelfClearCache @lastClearedOn={{this.lastTime}} />`); | ||
|
||
// Assert | ||
assert.dom('[data-test-last-time]').hasText(HUMAN_TIME); | ||
}); | ||
|
||
skip('it triggers cache clear on button click', async function (assert) { | ||
assert.expect(1); | ||
|
||
// Assemble | ||
this.set('lastTime', EPOCH_TIMESTAMP); | ||
|
||
this.set('onCacheClear', function () { | ||
assert.step(CACHE_CLEAR_CLICKED); | ||
}); | ||
|
||
await render(hbs` | ||
<SelfClearCache | ||
@lastClearedOn={{this.lastTime}} | ||
@onCacheClear={{this.onCacheClear}} | ||
/> | ||
`); | ||
|
||
// Act | ||
const btn = find('[data-test-btn-clear-cache]'); | ||
await click(btn); | ||
|
||
// Assert | ||
assert.verifySteps([CACHE_CLEAR_CLICKED]); | ||
}); | ||
|
||
skip('it disables button after a click', async function (assert) { | ||
assert.expect(1); | ||
|
||
// Assemble | ||
this.set('lastTime', EPOCH_TIMESTAMP); | ||
|
||
this.set('onCacheClear', function () { | ||
assert.step(CACHE_CLEAR_CLICKED); | ||
}); | ||
|
||
await render(hbs` | ||
<SelfClearCache | ||
@lastClearedOn={{this.lastTime}} | ||
@onCacheClear={{this.onCacheClear}} | ||
/> | ||
`); | ||
|
||
// Act | ||
const btn = find('[data-test-btn-clear-cache]'); | ||
await click(btn); | ||
rohan09-raj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await click(btn); // Another click -- This should not fire | ||
rohan09-raj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Assert | ||
assert.verifySteps([CACHE_CLEAR_CLICKED]); | ||
}); | ||
|
||
skip('it shows the number of times cache has already been cleared', async function (assert) { | ||
assert.expect(1); | ||
|
||
// Assemble | ||
this.set('lastTime', EPOCH_TIMESTAMP); | ||
this.set('totalTimes', 2); | ||
this.set('allowedLimit', 3); | ||
|
||
await render(hbs` | ||
<SelfClearCache | ||
@time={{this.lastTime}} | ||
@countCleared={{this.totalTimes}} | ||
@allowedLimit={{this.allowedLimit}} | ||
/> | ||
`); | ||
|
||
// Assert | ||
assert.dom('[data-test-pending-requests]').hasText('2 / 3'); | ||
}); | ||
|
||
skip('it disables the button if already reached allowed limit', async function (assert) { | ||
assert.expect(2); | ||
|
||
// Assemble | ||
this.set('lastTime', EPOCH_TIMESTAMP); | ||
this.set('totalTimes', 3); | ||
this.set('allowedLimit', 3); | ||
|
||
this.set('onCacheClear', function () { | ||
assert.step(CACHE_CLEAR_CLICKED); | ||
}); | ||
|
||
await render(hbs` | ||
<SelfClearCache | ||
@time={{this.lastTime}} | ||
@countCleared={{this.totalTimes}} | ||
@allowedLimit={{this.allowedLimit}} | ||
@onCacheClear={{this.onCacheClear}} | ||
/> | ||
`); | ||
|
||
// Act | ||
const btn = find('[data-test-btn-clear-cache]'); | ||
await click(btn); | ||
|
||
// Assert | ||
rohan09-raj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert.verifySteps([]); | ||
rohan09-raj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
On what condition it gets enabled again?
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.
I had the same doubt, need to ask @ankushdharkar, but probably there will be a fixed time after which the button gets enabled again and it will be handled on the frontend, we need not to test that I guess
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.
How I think it should be -
Button clicked > Handle Click function calls which disables button & an API request to clear cache > Wait for server to respond > Server responds > Enable button again
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.
Good questions and suggestions.
We should be testing this on Frontend AND Backend. Backend should always validate and verify the behaviour (otherwise a bad user can just use curl/postman/etc to trigger the API anyway)
The button to be disabled here is to prevent multiple calls from firing (because clearing cache costs us as well as, it will cost crypto to clear your cache in future). We want to ideally make idempotent calls to clear the cache, and we should discuss this. We would have to implement some sort of UUID for this.
You can read more about the solution here: https://stripe.com/docs/api/idempotent_requests, but until then, we should just do a simpler implementation of maybe disabling the button for 5 seconds and move on.
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.
Created an RFC here
Real-Dev-Squad/website-backend#627