Skip to content

Commit

Permalink
Additional ci check for button text uniqueness + url logic for dismis…
Browse files Browse the repository at this point in the history
…s actions (#105)

* Checking action logic + unique button texts enforced

* Apply suggestions from code review

Co-authored-by: Parker Lougheed <[email protected]>

* Update json-validator.dart

---------

Co-authored-by: Parker Lougheed <[email protected]>
  • Loading branch information
eliasyishak and parlough authored Aug 24, 2023
1 parent e8d9eee commit b5a826b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/contextual-json-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
contents: read

jobs:
json-yaml-validate:
contextual-json-validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
Expand Down
17 changes: 17 additions & 0 deletions surveys/validator/json-validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void main() {
}

// Validation on the button array
final buttonTextSet = <String>{};
for (final buttonObject in buttonList) {
if (buttonObject is! Map) {
throw ArgumentError('Each item in the button array must '
Expand All @@ -116,6 +117,22 @@ void main() {
if (url != null && url.isEmpty) {
throw ArgumentError('URL values must be a non-empty string or "null"');
}

// If a given button has "dismiss" as the action,
// there should be no URL defined.
if (action == 'dismiss' && url != null) {
throw ArgumentError('URL should be null if action for a button is '
'"dismiss" or "snooze" for survey: $uniqueId');
}

// Add the button text to a set to ensure that
// each button in a survey has a unique label.
buttonTextSet.add(buttonText);
}

if (buttonTextSet.length != buttonList.length) {
throw ArgumentError(
'Each button must have unique text in survey: $uniqueId');
}
}
}
Expand Down

0 comments on commit b5a826b

Please sign in to comment.