-
Notifications
You must be signed in to change notification settings - Fork 481
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
Added tests for Progress View V2 Invitation #58471
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fd43ff9
added a test
kobryan0619 7db0bf0
fixed nits
kobryan0619 564899d
all tests working so far
kobryan0619 360aefa
all but one test working
kobryan0619 4cdc137
added all tests
kobryan0619 ea2bc69
modified to be visible
kobryan0619 02c9fd7
modified tests
kobryan0619 09fb18d
changed location of constant
kobryan0619 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
157 changes: 157 additions & 0 deletions
157
apps/test/unit/templates/sectionProgressV2/InviteToV2ProgressModalTest.jsx
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,157 @@ | ||
import {fireEvent, render, screen} from '@testing-library/react'; | ||
import $ from 'jquery'; | ||
import React from 'react'; | ||
import sinon from 'sinon'; | ||
|
||
import {UnconnectedInviteToV2ProgressModal} from '@cdo/apps/templates/sectionProgressV2/InviteToV2ProgressModal'; | ||
import i18n from '@cdo/locale'; | ||
|
||
import {expect} from '../../../util/reconfiguredChai'; | ||
|
||
const DEFAULT_PROPS = { | ||
setShowProgressTableV2: () => {}, | ||
setHasSeenProgressTableInvite: () => {}, | ||
setDateProgressTableInvitationDelayed: () => {}, | ||
}; | ||
|
||
describe('UnconnectedInviteToV2ProgressModal', () => { | ||
let postStub; | ||
|
||
beforeEach(() => { | ||
postStub = sinon.stub($, 'post').returns(Promise.resolve({})); | ||
}); | ||
|
||
afterEach(() => { | ||
postStub.restore(); | ||
}); | ||
|
||
function renderDefault(propOverrides = {}) { | ||
render( | ||
<UnconnectedInviteToV2ProgressModal | ||
{...DEFAULT_PROPS} | ||
{...propOverrides} | ||
/> | ||
); | ||
} | ||
|
||
it('renders the dialog with required elements', () => { | ||
renderDefault(); | ||
|
||
screen.getByText(i18n.progressTrackingAnnouncement()); | ||
screen.getByText(i18n.tryItNow()); | ||
screen.getByText(i18n.remindMeLater()); | ||
screen.getByLabelText(i18n.closeDialog()); | ||
}); | ||
|
||
it('allows user to accept the invitation', () => { | ||
const setShowProgressTableV2Stub = sinon.stub(); | ||
const setHasSeenProgressTableInviteStub = sinon.stub(); | ||
|
||
renderDefault({ | ||
setShowProgressTableV2: setShowProgressTableV2Stub, | ||
setHasSeenProgressTableInvite: setHasSeenProgressTableInviteStub, | ||
}); | ||
|
||
screen.getByText(i18n.progressTrackingAnnouncement()); | ||
const acceptButton = screen.getByText(i18n.tryItNow()); | ||
fireEvent.click(acceptButton); | ||
|
||
expect(setHasSeenProgressTableInviteStub).to.have.been.calledOnce; | ||
expect(setShowProgressTableV2Stub).to.have.been.calledOnce; | ||
|
||
expect(postStub).calledWith('/api/v1/users/show_progress_table_v2', { | ||
show_progress_table_v2: true, | ||
}); | ||
expect(postStub).calledWith( | ||
'/api/v1/users/has_seen_progress_table_v2_invitation', | ||
{ | ||
has_seen_progress_table_v2_invitation: true, | ||
} | ||
); | ||
}); | ||
|
||
it('allows user to decline the invitation', () => { | ||
const setHasSeenProgressTableInviteStub = sinon.stub(); | ||
|
||
renderDefault({ | ||
setHasSeenProgressTableInvite: setHasSeenProgressTableInviteStub, | ||
}); | ||
|
||
const xButton = screen.getByLabelText(i18n.closeDialog()); | ||
fireEvent.click(xButton); | ||
|
||
expect(setHasSeenProgressTableInviteStub).to.have.been.calledOnce; | ||
expect(postStub).calledWith( | ||
'/api/v1/users/has_seen_progress_table_v2_invitation', | ||
{ | ||
has_seen_progress_table_v2_invitation: true, | ||
} | ||
); | ||
expect(screen.queryByText(i18n.tryItNow())).to.be.null; | ||
expect(screen.queryByText(i18n.progressTrackingAnnouncement())).to.be.null; | ||
expect(screen.queryByText(i18n.remindMeLater())).to.be.null; | ||
}); | ||
|
||
it('allows user to delay the invitation', () => { | ||
renderDefault(); | ||
|
||
const delayButton = screen.getByText(i18n.remindMeLater()); | ||
fireEvent.click(delayButton); | ||
|
||
sinon.assert.calledOnce(postStub); | ||
sinon.assert.calledWithMatch( | ||
postStub, | ||
'/api/v1/users/date_progress_table_invitation_last_delayed' | ||
); | ||
|
||
expect(screen.queryByText(i18n.tryItNow())).to.be.null; | ||
expect(screen.queryByText(i18n.progressTrackingAnnouncement())).to.be.null; | ||
expect(screen.queryByText(i18n.remindMeLater())).to.be.null; | ||
}); | ||
|
||
it('does not show the dialog if they have already accepted or rejected the invitation', () => { | ||
renderDefault({hasSeenProgressTableInvite: true}); | ||
|
||
expect(screen.queryByText(i18n.tryItNow())).to.be.null; | ||
expect(screen.queryByText(i18n.progressTrackingAnnouncement())).to.be.null; | ||
expect(screen.queryByText(i18n.remindMeLater())).to.be.null; | ||
}); | ||
|
||
it('does not show the dialog if they have already accepted or rejected the invitation after delaying invitation', () => { | ||
renderDefault({ | ||
hasSeenProgressTableInvite: true, | ||
dateProgressTableInvitationDelayed: | ||
'Wed May 01 2024 14:22:23 GMT-0500 (Central Daylight Time)', | ||
}); | ||
|
||
expect(screen.queryByText(i18n.tryItNow())).to.be.null; | ||
expect(screen.queryByText(i18n.progressTrackingAnnouncement())).to.be.null; | ||
expect(screen.queryByText(i18n.remindMeLater())).to.be.null; | ||
}); | ||
|
||
it('shows the dialog if it has been more than three days since they delayed the pop-up', () => { | ||
renderDefault({ | ||
dateProgressTableInvitationDelayed: | ||
'Wed May 01 2024 14:22:23 GMT-0500 (Central Daylight Time)', | ||
}); | ||
|
||
screen.getByText(i18n.progressTrackingAnnouncement()); | ||
screen.getByText(i18n.tryItNow()); | ||
screen.getByText(i18n.remindMeLater()); | ||
screen.getByLabelText(i18n.closeDialog()); | ||
}); | ||
|
||
it('does not show the dialog if it has been less than three days since they delayed the pop-up', () => { | ||
const today = new Date(); | ||
const yesterday = new Date(today); | ||
|
||
yesterday.setDate(yesterday.getDate() - 1); | ||
renderDefault({ | ||
dateProgressTableInvitationDelayed: yesterday, | ||
}); | ||
|
||
expect(screen.queryByText(i18n.tryItNow())).to.be.null; | ||
expect(screen.queryByText(i18n.progressTrackingAnnouncement())).to.be.null; | ||
expect(screen.queryByText(i18n.remindMeLater())).to.be.null; | ||
}); | ||
}); |
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.
Nit: move this constant outside the
InviteToV2ProgressModal
function (to the top of the file).