-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(surveys): adds targeting changes to the survey revision history #23834
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f3592d3
kinda a hack tbh, I feel like I can handle the deleted flag in more o…
dmarticus 80a2c12
progress on the UI.
dmarticus af7be47
Merge branch 'master' into feat/add-targeting-to-survey-history
dmarticus bc55730
stopping here until I figure out the best way to provide value
dmarticus a6408c8
overengineered the shit out of this but man the UX is nice
dmarticus 76e5462
cleaned up activity_log a bit
dmarticus ef262d8
seems useful
dmarticus 6f6836f
appeasing mypy
dmarticus dc0cd35
Merge branch 'master' into feat/add-targeting-to-survey-history
dmarticus 477cbef
Update UI snapshots for `chromium` (1)
github-actions[bot] 836e511
oh looks like latest ts-pattern didn't work wth typescript v4.x, let'…
dmarticus 805dde1
Merge branch 'feat/add-targeting-to-survey-history' of github.com:Pos…
dmarticus 7acdbc8
Merge branch 'master' into feat/add-targeting-to-survey-history
dmarticus 3397b5e
a few more fields
dmarticus 5ea87ee
Merge branch 'master' into feat/add-targeting-to-survey-history
dmarticus 6ee6e24
code review feedback
dmarticus 0757dfc
Merge branch 'master' into feat/add-targeting-to-survey-history
dmarticus 3cbfd67
Update UI snapshots for `chromium` (1)
github-actions[bot] cb6b31b
Update UI snapshots for `chromium` (1)
github-actions[bot] 29b4403
don't check this in
dmarticus 4b2d4b4
Merge branch 'feat/add-targeting-to-survey-history' of github.com:Pos…
dmarticus 959c8d7
Update UI snapshots for `chromium` (1)
github-actions[bot] 6c34adb
Update UI snapshots for `chromium` (1)
github-actions[bot] f9cec32
Update UI snapshots for `chromium` (2)
github-actions[bot] 41b670a
Update UI snapshots for `chromium` (1)
github-actions[bot] 1ce06c2
Update UI snapshots for `chromium` (2)
github-actions[bot] 3acf048
Merge branch 'master' into feat/add-targeting-to-survey-history
dmarticus 6989976
Merge branch 'master' into feat/add-targeting-to-survey-history
dmarticus 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
Binary file modified
BIN
-7 Bytes
(100%)
frontend/__snapshots__/scenes-app-insights--funnel-top-to-bottom-edit--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
262 changes: 262 additions & 0 deletions
262
frontend/src/scenes/surveys/surveyActivityDescriber.test.tsx
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,262 @@ | ||
import { render } from '@testing-library/react' | ||
|
||
import { | ||
LinkSurveyQuestion, | ||
MultipleSurveyQuestion, | ||
RatingSurveyQuestion, | ||
SurveyQuestion, | ||
SurveyQuestionBranchingType, | ||
SurveyQuestionType, | ||
} from '~/types' | ||
|
||
import { | ||
describeBranchingChanges, | ||
describeCommonChanges, | ||
describeFieldChange, | ||
describeLinkChanges, | ||
describeMultipleChoiceChanges, | ||
describeQuestionChanges, | ||
describeRatingChanges, | ||
} from './surveyActivityDescriber' | ||
|
||
const getTextContent = (jsxElement: JSX.Element): string => { | ||
const { container } = render(jsxElement) | ||
return container.textContent || '' | ||
} | ||
|
||
describe('describeFieldChange', () => { | ||
test('sets field with unit', () => { | ||
const result = describeFieldChange('wait period', null, 30, 'days') | ||
expect(getTextContent(result)).toBe('set wait period to 30 days') | ||
}) | ||
|
||
test('removes field with unit', () => { | ||
const result = describeFieldChange('wait period', 30, null, 'days') | ||
expect(getTextContent(result)).toBe('removed wait period (was 30 days)') | ||
}) | ||
|
||
test('changes field with unit', () => { | ||
const result = describeFieldChange('wait period', 30, 60, 'days') | ||
expect(getTextContent(result)).toBe('changed wait period from 30 days to 60 days') | ||
}) | ||
|
||
test('sets field without unit', () => { | ||
const result = describeFieldChange('response limit', null, 100) | ||
expect(getTextContent(result)).toBe('set response limit to 100') | ||
}) | ||
|
||
test('removes field without unit', () => { | ||
const result = describeFieldChange('response limit', 100, null) | ||
expect(getTextContent(result)).toBe('removed response limit (was 100)') | ||
}) | ||
|
||
test('changes field without unit', () => { | ||
const result = describeFieldChange('response limit', 100, 200) | ||
expect(getTextContent(result)).toBe('changed response limit from 100 to 200') | ||
}) | ||
|
||
test('handles undefined before value', () => { | ||
const result = describeFieldChange('iteration count', undefined, 5) | ||
expect(getTextContent(result)).toBe('set iteration count to 5') | ||
}) | ||
|
||
test('handles undefined after value', () => { | ||
const result = describeFieldChange('iteration count', 5, undefined) | ||
expect(getTextContent(result)).toBe('removed iteration count (was 5)') | ||
}) | ||
|
||
test('handles empty string before value', () => { | ||
const result = describeFieldChange('survey title', '', 'New Title') | ||
expect(getTextContent(result)).toBe('set survey title to New Title') | ||
}) | ||
|
||
test('handles empty string after value', () => { | ||
const result = describeFieldChange('survey title', 'Old Title', '') | ||
expect(getTextContent(result)).toBe('removed survey title (was Old Title)') | ||
}) | ||
|
||
test('handles both values as empty strings', () => { | ||
const result = describeFieldChange('survey title', '', '') | ||
expect(getTextContent(result)).toBe('') | ||
}) | ||
|
||
test('handles before and after as identical', () => { | ||
const result = describeFieldChange('response limit', 100, 100) | ||
expect(getTextContent(result)).toBe('') | ||
}) | ||
|
||
test('handles string values with unit', () => { | ||
const result = describeFieldChange('response time', 'fast', 'slow', 'seconds') | ||
expect(getTextContent(result)).toBe('changed response time from fast seconds to slow seconds') | ||
}) | ||
|
||
test('handles boolean values', () => { | ||
const result = describeFieldChange('is active', false, true) | ||
expect(getTextContent(result)).toBe('changed is active from false to true') | ||
}) | ||
|
||
test('handles null values', () => { | ||
const result = describeFieldChange('response limit', null, null) | ||
expect(getTextContent(result)).toBe('') | ||
}) | ||
}) | ||
|
||
describe('describeCommonChanges', () => { | ||
const before: SurveyQuestion = { | ||
question: 'What is your favorite color?', | ||
description: 'Choose a color', | ||
type: SurveyQuestionType.SingleChoice, | ||
optional: false, | ||
buttonText: 'Next', | ||
choices: ['Red', 'Blue', 'Green'], | ||
} | ||
const after: SurveyQuestion = { | ||
...before, | ||
question: 'What is your favorite animal?', | ||
description: 'Choose an animal', | ||
optional: true, | ||
buttonText: 'Continue', | ||
} | ||
|
||
test('describes common changes', () => { | ||
const changes = describeCommonChanges(before, after) | ||
expect(changes).toHaveLength(4) | ||
expect(getTextContent(changes[0])).toBe( | ||
'changed question text from "What is your favorite color?" to "What is your favorite animal?"' | ||
) | ||
expect(getTextContent(changes[1])).toBe( | ||
'changed the question description from "Choose a color" to "Choose an animal"' | ||
) | ||
expect(getTextContent(changes[2])).toBe('made question optional') | ||
expect(getTextContent(changes[3])).toBe('changed button text from "Next" to "Continue"') | ||
}) | ||
}) | ||
|
||
describe('describeLinkChanges', () => { | ||
const before: LinkSurveyQuestion = { | ||
question: 'Visit our website', | ||
type: SurveyQuestionType.Link, | ||
link: 'http://example.com', | ||
} | ||
const after: LinkSurveyQuestion = { | ||
...before, | ||
link: 'http://example.org', | ||
} | ||
|
||
test('describes link changes', () => { | ||
const changes = describeLinkChanges([before, after]) | ||
expect(changes).toHaveLength(1) | ||
expect(getTextContent(changes[0])).toBe('updated link from http://example.com to http://example.org') | ||
}) | ||
}) | ||
|
||
describe('describeRatingChanges', () => { | ||
const before: RatingSurveyQuestion = { | ||
question: 'Rate our service', | ||
type: SurveyQuestionType.Rating, | ||
display: 'emoji', | ||
scale: 5, | ||
lowerBoundLabel: 'Poor', | ||
upperBoundLabel: 'Excellent', | ||
} | ||
const after: RatingSurveyQuestion = { | ||
...before, | ||
display: 'number', | ||
scale: 10, | ||
lowerBoundLabel: 'Bad', | ||
upperBoundLabel: 'Good', | ||
} | ||
|
||
test('describes rating changes', () => { | ||
const changes = describeRatingChanges([before, after]) | ||
expect(changes).toHaveLength(3) | ||
expect(getTextContent(changes[0])).toBe('changed rating display from emoji to number') | ||
expect(getTextContent(changes[1])).toBe('changed rating scale from 5 to 10') | ||
expect(getTextContent(changes[2])).toBe('updated rating labels from "Poor"-"Excellent" to "Bad"-"Good"') | ||
}) | ||
}) | ||
|
||
describe('describeMultipleChoiceChanges', () => { | ||
const before: MultipleSurveyQuestion = { | ||
question: 'Select your hobbies', | ||
type: SurveyQuestionType.MultipleChoice, | ||
choices: ['Reading', 'Traveling', 'Cooking'], | ||
shuffleOptions: false, | ||
hasOpenChoice: false, | ||
} | ||
const after: MultipleSurveyQuestion = { | ||
...before, | ||
choices: ['Reading', 'Cooking', 'Gaming'], | ||
shuffleOptions: true, | ||
hasOpenChoice: true, | ||
} | ||
|
||
test('describes multiple choice changes', () => { | ||
const changes = describeMultipleChoiceChanges([before, after]) | ||
expect(changes).toHaveLength(4) | ||
expect(getTextContent(changes[0])).toBe('added choices: Gaming') | ||
expect(getTextContent(changes[1])).toBe('removed choices: Traveling') | ||
expect(getTextContent(changes[2])).toBe('enabled option shuffling') | ||
expect(getTextContent(changes[3])).toBe('added open choice option') | ||
}) | ||
}) | ||
|
||
describe('describeBranchingChanges', () => { | ||
const before: MultipleSurveyQuestion = { | ||
question: 'Do you like ice cream?', | ||
type: SurveyQuestionType.SingleChoice, | ||
choices: ['Yes', 'No'], | ||
branching: { | ||
type: SurveyQuestionBranchingType.NextQuestion, | ||
}, | ||
} | ||
const after: MultipleSurveyQuestion = { | ||
...before, | ||
branching: { | ||
type: SurveyQuestionBranchingType.End, | ||
}, | ||
} | ||
|
||
test('describes branching changes', () => { | ||
const changes = describeBranchingChanges(before, after) | ||
expect(changes).toHaveLength(1) | ||
expect(getTextContent(changes[0])).toBe('updated branching logic') | ||
}) | ||
}) | ||
|
||
describe('describeQuestionChanges', () => { | ||
const before: MultipleSurveyQuestion = { | ||
question: 'Do you like ice cream?', | ||
type: SurveyQuestionType.SingleChoice, | ||
description: 'Please answer honestly', | ||
optional: false, | ||
buttonText: 'Next', | ||
choices: ['Yes', 'No'], | ||
branching: { | ||
type: SurveyQuestionBranchingType.NextQuestion, | ||
}, | ||
} | ||
const after: MultipleSurveyQuestion = { | ||
question: 'Do you like pizza?', | ||
type: SurveyQuestionType.MultipleChoice, | ||
description: 'Please answer honestly', | ||
optional: true, | ||
buttonText: 'Continue', | ||
choices: ['Yes', 'No', 'Maybe'], | ||
branching: { | ||
type: SurveyQuestionBranchingType.End, | ||
}, | ||
} | ||
test('describes all changes in a question', () => { | ||
const changes = describeQuestionChanges(before, after) | ||
expect(changes).toHaveLength(6) | ||
expect(getTextContent(changes[0])).toBe( | ||
'changed question text from "Do you like ice cream?" to "Do you like pizza?"' | ||
) | ||
expect(getTextContent(changes[1])).toBe('made question optional') | ||
expect(getTextContent(changes[2])).toBe('changed button text from "Next" to "Continue"') | ||
expect(getTextContent(changes[3])).toBe('changed question type from single_choice to multiple_choice') | ||
expect(getTextContent(changes[4])).toBe('added choices: Maybe') | ||
expect(getTextContent(changes[5])).toBe('updated branching logic') | ||
}) | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
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.
drive by fix – I noticed that we never actually visualize (but we do log) creation events in the feature flag history! Here's what it look like now