Skip to content

Commit

Permalink
Update conflicting
Browse files Browse the repository at this point in the history
  • Loading branch information
Thuyhaile committed Nov 25, 2023
1 parent 48e4c67 commit 9f40ca4
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 91 deletions.
83 changes: 18 additions & 65 deletions lib/screens/new_citizen_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'dart:typed_data';

import 'package:api_client/models/giraf_user_model.dart';
import 'package:auto_size_text/auto_size_text.dart';
Expand Down Expand Up @@ -76,10 +77,6 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
bool isButtonSaveEnabled = true;
bool isButtonContinueEnabled = false;

<<<<<<< Updated upstream
=======

>>>>>>> Stashed changes
@override
Widget build(BuildContext context) {
widget.screenHeight = MediaQuery.of(context).size.height;
Expand All @@ -105,11 +102,7 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
border:
const OutlineInputBorder(borderSide: BorderSide()),
labelText: 'Navn',
<<<<<<< Updated upstream
errorText: (snapshot?.data == true) &&
=======
errorText: (snapshot.data == true) &&
>>>>>>> Stashed changes
widget._bloc.displayNameController.value != null
? null
: 'Navn skal udfyldes',
Expand Down Expand Up @@ -137,9 +130,9 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
leading: Radio<Roles>(
value: Roles.guardian,
groupValue: _role,
onChanged: (Roles value) {
onChanged: (Roles? value) {
setState(() {
_role = value;
_role = value!;
widget._bloc.onUsePictogramPasswordChange
.add(value == Roles.citizen);
});
Expand All @@ -154,9 +147,9 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
leading: Radio<Roles>(
value: Roles.trustee,
groupValue: _role,
onChanged: (Roles value) {
onChanged: (Roles? value) {
setState(() {
_role = value;
_role = value!;
widget._bloc.onUsePictogramPasswordChange
.add(value == Roles.citizen);
});
Expand All @@ -171,9 +164,9 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
leading: Radio<Roles>(
value: Roles.citizen,
groupValue: _role,
onChanged: (Roles value) {
onChanged: (Roles? value) {
setState(() {
_role = value;
_role = value!;
});
},
),
Expand All @@ -197,11 +190,7 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
border:
const OutlineInputBorder(borderSide: BorderSide()),
labelText: 'Brugernavn',
<<<<<<< Updated upstream
errorText: (snapshot?.data == true) &&
=======
errorText: (snapshot.data == true) &&
>>>>>>> Stashed changes
widget._bloc.usernameController.value != null
? null
// cant make it shorter because of the string
Expand Down Expand Up @@ -250,30 +239,17 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
builder:
(BuildContext context, AsyncSnapshot<bool> snapshot) {
return Visibility(
<<<<<<< Updated upstream
visible: !widget._bloc.
usePictogramPasswordController.value,
child: TextFormField(
key: const Key('passwordField'),
enabled:
!widget._bloc.usePictogramPasswordController.value,
=======
visible:
!widget._bloc.usePictogramPasswordController.value!,
child: TextFormField(
key: const Key('passwordField'),
enabled:
!widget._bloc.usePictogramPasswordController.value!,
>>>>>>> Stashed changes
decoration: InputDecoration(
border:
const OutlineInputBorder(borderSide: BorderSide()),
labelText: 'Kodeord',
<<<<<<< Updated upstream
errorText: (snapshot?.data == true) &&
=======
errorText: (snapshot.data == true) &&
>>>>>>> Stashed changes
widget._bloc.passwordController.value != null
? null
// cant make it shorter because of the string
Expand All @@ -294,19 +270,11 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
(BuildContext context, AsyncSnapshot<bool> snapshot) {
return Visibility(
visible:
<<<<<<< Updated upstream
!widget._bloc.usePictogramPasswordController.value,
child: TextFormField(
key: const Key('passwordVerifyField'),
enabled:
!widget._bloc.usePictogramPasswordController.value,
=======
!widget._bloc.usePictogramPasswordController.value!,
child: TextFormField(
key: const Key('passwordVerifyField'),
enabled:
!widget._bloc.usePictogramPasswordController.value!,
>>>>>>> Stashed changes
decoration: InputDecoration(
border:
const
Expand All @@ -333,13 +301,16 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {

/// Profile preview picture
Center(
child: StreamBuilder<File>(
stream: widget._bloc.file,
builder:
(BuildContext context, AsyncSnapshot<File> snapshot) =>
snapshot.data != null
? widget._displayImage(snapshot.data)
: widget._displayIfNoImage()),
child: StreamBuilder<File?>(
stream: widget._bloc.file,
builder: (BuildContext context, AsyncSnapshot<File?> snapshot) {
final File? fileData =
snapshot.data; // Store the data in a local variable
return fileData != null
? widget._displayImage(fileData) // Use the local variable
: widget._displayIfNoImage();
},
),
),

Row(
Expand All @@ -353,23 +324,13 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
/// Add from gallery button
child: GirafButton(
key: const Key('TilføjFraGalleriButton'),
<<<<<<< Updated upstream
icon: const ImageIcon(AssetImage('assets/icons/gallery.png')),
=======
icon:
const ImageIcon(AssetImage('assets/icons/gallery.png')),
>>>>>>> Stashed changes
text: 'Tilføj fra galleri',
onPressed: widget._bloc.chooseImageFromGallery,
child: StreamBuilder<File>(
stream: widget._bloc.file,
builder: (BuildContext context,
<<<<<<< Updated upstream
AsyncSnapshot<File> snapshot) =>
snapshot.data != null
? widget._displayImage(snapshot.data)
: widget._displayIfNoImage()),
=======
AsyncSnapshot<File?> snapshot) {
final File? fileData = snapshot
.data; // Store the data in a local variable
Expand All @@ -378,7 +339,6 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
fileData) // Use the local variable
: widget._displayIfNoImage();
}),
>>>>>>> Stashed changes
),
),
],
Expand Down Expand Up @@ -459,21 +419,14 @@ class _NewCitizenScreenState extends State<NewCitizenScreen> {
MaterialPageRoute<void>(
builder: (BuildContext context) =>
NewPictogramPasswordScreen(
<<<<<<< Updated upstream
widget._bloc.usernameController.value,
widget._bloc.displayNameController.value,
widget._bloc.encodePicture(
widget._bloc.fileController.value),
=======
widget._bloc.usernameController.value!,
widget._bloc.displayNameController.value!,
Uint8List.fromList(
widget._bloc.encodePicture(widget
._bloc.fileController.value) ??
<int>[],
)
>>>>>>> Stashed changes
)));
)));
},
),
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module:
androidX: true

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=3.1.2"
dependencies:
api_client:
git:
Expand Down
60 changes: 35 additions & 25 deletions test/blocs/edit_weekplan_bloc_test.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:api_client/api/api.dart';
import 'package:api_client/api/week_api.dart';
import 'package:api_client/models/displayname_model.dart';
import 'package:api_client/models/enums/access_level_enum.dart';
import 'package:api_client/models/pictogram_model.dart';
import 'package:api_client/models/week_model.dart';
import 'package:api_client/models/week_name_model.dart';
import 'package:async_test/async_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:mocktail/mocktail.dart';
import 'package:rxdart/rxdart.dart' as rx_dart;
import 'package:weekplanner/blocs/edit_weekplan_bloc.dart';
import 'package:weekplanner/blocs/weekplan_selector_bloc.dart';
Expand All @@ -15,18 +16,21 @@ import 'package:weekplanner/di.dart';
class MockWeekApi extends Mock implements WeekApi {}

void main() {
EditWeekplanBloc bloc;
WeekplansBloc mockWeekplanSelector;
Api api;
Api api = Api('any');
EditWeekplanBloc bloc = EditWeekplanBloc(api);
WeekplansBloc mockWeekplanSelector = WeekplansBloc(api);

final PictogramModel mockThumbnail = PictogramModel(
id: 1,
lastEdit: null,
title: null,
accessLevel: null,
title: 'null',
accessLevel: AccessLevel.PROTECTED,
imageUrl: 'http://any.tld',
imageHash: null);

final DisplayNameModel mockUser =
DisplayNameModel(displayName: 'User', id: '1', role: null);

final WeekModel mockWeek = WeekModel(
thumbnail: mockThumbnail,
days: null,
Expand All @@ -37,29 +41,35 @@ void main() {
setUp(() {
api = Api('any');
api.week = MockWeekApi();
registerFallbackValue(mockWeek);

when(api.week.update(any, any, any, any)).thenAnswer((_) {
when(() => api.week.update(any(), any(), any(), any())).thenAnswer((_) {
return Stream<WeekModel>.value(mockWeek);
});

when(api.week.getNames(any)).thenAnswer(
(_) {
return Stream<List<WeekNameModel>>.value(<WeekNameModel>[
WeekNameModel(
when(() => api.week.getNames(any())).thenAnswer(
(_) {
return Stream<List<WeekNameModel>>.fromIterable(<List<WeekNameModel>>[
<WeekNameModel>[
WeekNameModel(
name: mockWeek.name,
weekNumber: mockWeek.weekNumber,
weekYear: mockWeek.weekYear),
weekYear: mockWeek.weekYear,
),
]
]);

},
);

when(api.week.get(any, any, any)).thenAnswer(
(_) {
when(() => api.week.get(any(), any(), any())).thenAnswer(
(_) {
return Stream<WeekModel>.value(mockWeek);
},
);

when(api.week.delete(mockUser.id, mockWeek.weekYear, mockWeek.weekNumber))
when(() => api.week
.delete(mockUser.id!, mockWeek.weekYear, mockWeek.weekNumber))
.thenAnswer((_) => rx_dart.BehaviorSubject<bool>.seeded(true));

mockWeekplanSelector = WeekplansBloc(api);
Expand All @@ -79,12 +89,12 @@ void main() {
bloc.onThumbnailChanged.add(mockThumbnail);
bloc
.editWeekPlan(
screenContext: null,
oldWeekModel: mockWeek,
selectorBloc: mockWeekplanSelector)
screenContext: null,
oldWeekModel: mockWeek,
selectorBloc: mockWeekplanSelector)
.then(
(WeekModel w) {
verify(api.week.update(any, any, any, any));
(WeekModel w) {
verify(() => api.week.update(any(), any(), any(), any()));
done();
},
);
Expand All @@ -98,12 +108,12 @@ void main() {
bloc.onThumbnailChanged.add(mockThumbnail);
bloc
.editWeekPlan(
screenContext: null,
oldWeekModel: mockWeek,
selectorBloc: mockWeekplanSelector)
screenContext: null,
oldWeekModel: mockWeek,
selectorBloc: mockWeekplanSelector)
.then(
(WeekModel w) {
verify(api.week.update(any, any, any, any));
(WeekModel w) {
verify(() => api.week.update(any(), any(), any(), any()));
done();
},
);
Expand Down
32 changes: 32 additions & 0 deletions test/blocs/weekplans_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,38 @@ void main() {
setupApiCalls();
});


when(() => weekApi.getNames('test')).thenAnswer((_) =>
rx_dart.BehaviorSubject<List<WeekNameModel>>.seeded(weekNameModelList));

when(() => weekApi.get(
'test', weekNameModel1.weekYear!, weekNameModel1.weekNumber!))
.thenAnswer((_) => rx_dart.BehaviorSubject<WeekModel>.seeded(weekModel1));

when(() => weekApi.get(
'test', weekNameModel2.weekYear!, weekNameModel2.weekNumber!))
.thenAnswer((_) => rx_dart.BehaviorSubject<WeekModel>.seeded(weekModel2));

when(() => weekApi.get(
'test', weekNameModel3.weekYear!, weekNameModel3.weekNumber!))
.thenAnswer((_) => rx_dart.BehaviorSubject<WeekModel>.seeded(weekModel3));

when(() => weekApi.get(
'test', weekNameModel4.weekYear!, weekNameModel4.weekNumber!))
.thenAnswer((_) => rx_dart.BehaviorSubject<WeekModel>.seeded(weekModel4));

when(() => weekApi.get(
'test', weekNameModel5.weekYear!, weekNameModel5.weekNumber!))
.thenAnswer((_) => rx_dart.BehaviorSubject<WeekModel>.seeded(weekModel5));

when(() => weekApi.get(
'test', weekNameModel6.weekYear!, weekNameModel6.weekNumber!))
.thenAnswer((_) => rx_dart.BehaviorSubject<WeekModel>.seeded(weekModel6));

when(() => weekApi.delete(any(), any(), any()))
.thenAnswer((_) => rx_dart.BehaviorSubject<bool>.seeded(true));


test('Should be able to load weekplans for a user', async((DoneFn done) {
bloc.weekNameModels.listen((List<WeekNameModel> response) {
expect(response, isNotNull);
Expand Down

0 comments on commit 9f40ca4

Please sign in to comment.