-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Add visual feedback to user choosing a value in a CSAT survey - Disable survey after user gives feedback or if they ignore it and move on
- Loading branch information
1 parent
334e01a
commit 6263d4e
Showing
4 changed files
with
163 additions
and
2 deletions.
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
74 changes: 74 additions & 0 deletions
74
src/applications/virtual-agent/tests/utils/processCSAT.unit.spec.js
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,74 @@ | ||
import sinon from 'sinon'; | ||
import { expect } from 'chai'; | ||
|
||
import processCSAT, { BLUE_STAR } from '../../utils/processCSAT'; | ||
|
||
describe('processCSAT', () => { | ||
let sandbox; | ||
let columns; | ||
let stars; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
columns = [{ style: { pointerEvents: 'not-none' } }]; | ||
stars = [ | ||
{ | ||
src: 'some-url', | ||
}, | ||
{ | ||
src: 'some-url', | ||
}, | ||
{ | ||
src: 'some-url', | ||
}, | ||
{ | ||
src: 'some-url', | ||
}, | ||
{ | ||
src: 'some-url', | ||
}, | ||
]; | ||
|
||
sandbox.stub(document, 'querySelectorAll').returns([ | ||
{ | ||
querySelectorAll: sandbox.stub().callsFake(query => { | ||
if (query === '#chatbot-csat-survey-columnset') { | ||
return columns; | ||
} | ||
if (query === 'img') { | ||
return stars; | ||
} | ||
return sandbox.stub(); | ||
}), | ||
}, | ||
]); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
it('Should disable the survey', () => { | ||
processCSAT({ value: { response: '3' } }); | ||
|
||
expect(columns[0].style.pointerEvents).to.equal('none'); | ||
}); | ||
it('Should fill in the stars when a numerical rating is given', () => { | ||
processCSAT({ value: { response: '3' } }); | ||
|
||
expect(stars[0].src).to.equal(BLUE_STAR); | ||
expect(stars[1].src).to.equal(BLUE_STAR); | ||
expect(stars[2].src).to.equal(BLUE_STAR); | ||
expect(stars[3].src).to.equal('some-url'); | ||
expect(stars[4].src).to.equal('some-url'); | ||
}); | ||
it('Should not fill in the stars when a non-numerical rating is given', () => { | ||
processCSAT({ value: { response: 'No response' } }); | ||
|
||
expect(stars[0].src).to.equal('some-url'); | ||
expect(stars[1].src).to.equal('some-url'); | ||
expect(stars[2].src).to.equal('some-url'); | ||
expect(stars[3].src).to.equal('some-url'); | ||
expect(stars[4].src).to.equal('some-url'); | ||
}); | ||
}); |
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
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,19 @@ | ||
export const BLUE_STAR = | ||
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzYiIGhlaWdodD0iMzYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiA8Zz4KICA8dGl0bGU+TGF5ZXIgMTwvdGl0bGU+CiAgPHBhdGggc3Ryb2tlPSIjMDAzZTczIiBkPSJtMi44NjE5OCwxNC43MDc1bDExLjYzMTgxLDBsMy41OTQzMiwtMTEuMzU1NzVsMy41OTQzMiwxMS4zNTU3NWwxMS42MzE4MSwwbC05LjQxMDMyLDcuMDE4MTZsMy41OTQ1MSwxMS4zNTU3NWwtOS40MTAzMiwtNy4wMTgzNWwtOS40MTAzMiw3LjAxODM1bDMuNTk0NTEsLTExLjM1NTc1bC05LjQxMDMyLC03LjAxODE2eiIgaWQ9InN2Z18xIiBzdHJva2Utd2lkdGg9IjIiIGZpbGw9IiMwMDNlNzMiLz4KIDwvZz4KCjwvc3ZnPg=='; | ||
|
||
export default function processCSAT(data) { | ||
const surveys = document.querySelectorAll('#chatbot-csat-survey'); | ||
const survey = surveys[surveys.length - 1]; | ||
|
||
const stars = survey.querySelectorAll('img'); | ||
const rating = Number(data.value.response); | ||
if (!Number.isNaN(rating)) { | ||
for (let i = 0; i < rating; i++) { | ||
stars[i].src = BLUE_STAR; | ||
} | ||
} | ||
|
||
// Make survey not clickable and appear disabled | ||
const columns = survey.querySelectorAll('#chatbot-csat-survey-columnset'); | ||
columns[0].style.pointerEvents = 'none'; | ||
} |