Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dev_dependencies:
flutter_lints: ^2.0.0
flutter_test:
sdk: flutter
bloc_test: ^9.1.4
mockito: ^5.3.2
test_cov_console: ^0.2.2
very_good_analysis: ^4.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:survey_admin/presentation/pages/new_question_page/new_question_cubit.dart';
import 'package:survey_admin/presentation/pages/new_question_page/new_question_state.dart';
import 'package:survey_admin/presentation/pages/new_question_page/new_question_tabs.dart';

import '../../../utils/mocked_entities.dart';

void main() {
group('New Question Cubit', () {
final data = MockedEntities.data1;

blocTest<NewQuestionCubit, NewQuestionState>(
'emits updated Tab',
build: () => NewQuestionCubit(data),
act: (cubit) => cubit.selectTab(NewQuestionTabs.slider),
expect: () => <NewQuestionState>[
NewQuestionState(
selectedTab: NewQuestionTabs.slider,
data: data,
),
],
);

blocTest<NewQuestionCubit, NewQuestionState>(
'emits updated CommonTheme for choice question',
build: () => NewQuestionCubit(data),
act: (cubit) => cubit.updateData(MockedEntities.choice2),
expect: () => <NewQuestionState>[
NewQuestionState(
data: data.copyWith(
commonTheme: data.commonTheme
.copyWith(choice: MockedEntities.choice2),
),
),
],
);

blocTest<NewQuestionCubit, NewQuestionState>(
'emits updated CommonTheme for info question',
build: () => NewQuestionCubit(data),
act: (cubit) => cubit.updateData(MockedEntities.info2),
expect: () => <NewQuestionState>[
NewQuestionState(
data: data.copyWith(
commonTheme: data.commonTheme
.copyWith(info: MockedEntities.info2),
),
),
],
);

blocTest<NewQuestionCubit, NewQuestionState>(
'emits updated CommonTheme for slider question',
build: () => NewQuestionCubit(data),
act: (cubit) => cubit.updateData(MockedEntities.slider2),
expect: () => <NewQuestionState>[
NewQuestionState(
data: data.copyWith(
commonTheme: data.commonTheme
.copyWith(slider: MockedEntities.slider2),
),
),
],
);

blocTest<NewQuestionCubit, NewQuestionState>(
'emits updated CommonTheme for input question',
build: () => NewQuestionCubit(data),
act: (cubit) => cubit.updateData(MockedEntities.input2),
expect: () => <NewQuestionState>[
NewQuestionState(
data: data.copyWith(
commonTheme: data.commonTheme
.copyWith(input: MockedEntities.input2),
),
),
],
);
});
}
207 changes: 207 additions & 0 deletions admin/test/utils/mocked_entities.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import 'package:flutter/material.dart';
import 'package:survey_sdk/survey_sdk.dart';

const _titleSize = 18.0;
const _subtitleSize = 15.0;
const _buttonTextSize = 14.0;
const _buttonRadius = 12.0;
const _horizontalPadding = 15.0;
const _verticalPadding = 15.0;
const _thumbRadius = 14.0;
const _thickness = 10.0;

abstract class MockedEntities {
static const choice1 = ChoiceQuestionData(
isMultipleChoice: true,
options: ['option 1', 'option 2', 'option 3'],
index: 0,
title: 'title',
subtitle: 'subtitle',
isSkip: true,
ruleType: RuleType.none,
ruleValue: 0,
theme: ChoiceQuestionTheme.common(),
secondaryButtonText: 'SKIP',
primaryButtonText: 'Next',
);

static const choice2 = ChoiceQuestionData(
isMultipleChoice: false,
options: ['option 1', 'option 2'],
index: 1,
title: 'Another title',
subtitle: 'Another subtitle',
isSkip: false,
content: 'content',
ruleType: RuleType.none,
ruleValue: 0,
theme: ChoiceQuestionTheme(
activeColor: SurveyColors.grey,
inactiveColor: SurveyColors.grey,
fill: SurveyColors.grey,
titleColor: SurveyColors.grey,
titleSize: _titleSize,
subtitleColor: SurveyColors.grey,
subtitleSize: _subtitleSize,
primaryButtonFill: SurveyColors.grey,
primaryButtonTextColor: SurveyColors.grey,
primaryButtonTextSize: _buttonTextSize,
primaryButtonRadius: _buttonRadius,
secondaryButtonFill: SurveyColors.grey,
secondaryButtonTextColor: SurveyColors.grey,
secondaryButtonTextSize: _buttonTextSize,
secondaryButtonRadius: _buttonRadius,
),
secondaryButtonText: 'SKIP',
primaryButtonText: 'Next',
);

static final input1 = InputQuestionData(
validator: InputValidator.text(),
index: 0,
title: 'title',
subtitle: 'subtitle',
isSkip: false,
primaryButtonText: 'NEXT',
theme: const InputQuestionTheme.common(),
secondaryButtonText: 'SKIP',
);

static final input2 = InputQuestionData(
validator: InputValidator.number(),
index: 1,
title: 'Another title',
subtitle: 'Another subtitle',
isSkip: true,
hintText: 'hint',
primaryButtonText: 'NEXT',
theme: const InputQuestionTheme(
inputFill: Colors.blueAccent,
borderColor: Colors.blueAccent,
borderWidth: 1,
lines: 1,
hintColor: SurveyColors.textLightGrey,
hintSize: SurveyFonts.sizeL,
textColor: SurveyColors.black,
textSize: SurveyFonts.sizeL,
inputType: InputType.number,
errorText: 'Error',
isMultiline: false,
fill: Colors.blueAccent,
titleColor: Colors.blueAccent,
titleSize: _titleSize,
subtitleColor: Colors.blueAccent,
subtitleSize: _subtitleSize,
primaryButtonFill: Colors.blueAccent,
primaryButtonTextColor: Colors.blueAccent,
primaryButtonTextSize: _buttonTextSize,
primaryButtonRadius: _buttonRadius,
secondaryButtonFill: Colors.blueAccent,
secondaryButtonTextColor: Colors.blueAccent,
secondaryButtonTextSize: _buttonTextSize,
secondaryButtonRadius: _buttonRadius,
horizontalPadding: _horizontalPadding,
verticalPadding: _verticalPadding,
),
secondaryButtonText: 'SKIP',
);

static const info1 = InfoQuestionData(
primaryButtonText: 'Next',
index: 0,
title: 'title',
subtitle: 'subtitle',
isSkip: false,
theme: InfoQuestionTheme.common(),
secondaryButtonText: 'SKIP',
);

static const info2 = InfoQuestionData(
index: 1,
title: 'Another title',
subtitle: 'Another subtitle',
isSkip: true,
content: 'content',
theme: InfoQuestionTheme(
fill: SurveyColors.grey,
titleColor: SurveyColors.grey,
titleSize: SurveyFonts.sizeL,
subtitleColor: SurveyColors.grey,
subtitleSize: SurveyFonts.sizeS,
primaryButtonFill: SurveyColors.grey,
primaryButtonTextColor: SurveyColors.grey,
primaryButtonTextSize: SurveyFonts.sizeS,
primaryButtonRadius: SurveyDimensions.circularRadiusS,
secondaryButtonFill: SurveyColors.grey,
secondaryButtonTextColor: SurveyColors.grey,
secondaryButtonTextSize: SurveyFonts.sizeS,
secondaryButtonRadius: SurveyDimensions.circularRadiusS,
),
secondaryButtonText: 'SKIP',
primaryButtonText: 'Next',
);

static const slider1 = SliderQuestionData(
minValue: 0,
maxValue: 10,
initialValue: 1,
index: 0,
title: 'title',
subtitle: 'subtitle',
isSkip: false,
divisions: 0,
theme: SliderQuestionTheme.common(),
secondaryButtonText: 'SKIP',
primaryButtonText: 'Next',
);

static const slider2 = SliderQuestionData(
minValue: 10,
maxValue: 100,
initialValue: 50,
index: 1,
title: 'Another title',
subtitle: 'Another subtitle',
isSkip: true,
divisions: 0,
theme: SliderQuestionTheme(
activeColor: Colors.grey,
inactiveColor: Colors.grey,
thumbColor: Colors.grey,
thumbRadius: _thumbRadius,
thickness: _thickness,
fill: Colors.grey,
titleColor: Colors.grey,
titleSize: _titleSize,
subtitleColor: Colors.grey,
subtitleSize: _subtitleSize,
primaryButtonFill: Colors.grey,
primaryButtonTextColor: Colors.grey,
primaryButtonTextSize: _buttonTextSize,
primaryButtonRadius: _buttonRadius,
secondaryButtonFill: Colors.grey,
secondaryButtonTextColor: Colors.grey,
secondaryButtonTextSize: _buttonTextSize,
secondaryButtonRadius: _buttonRadius,
),
secondaryButtonText: 'SKIP',
primaryButtonText: 'Next',
);

static final data1 = SurveyData(
questions: [
info1.copyWith(index: 1),
choice1.copyWith(index: 2),
input1.copyWith(index: 3),
slider1.copyWith(index: 4),
],
commonTheme: _commonTheme,
);

static final _commonTheme = CommonTheme(
slider: const SliderQuestionData.common(),
choice: const ChoiceQuestionData.common(),
input: InputQuestionData.common(),
info: const InfoQuestionData.common(),
);
}