Skip to content
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

Improve styling of holiday card on the dashboard page #320

Merged
merged 4 commits into from
Oct 3, 2022
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
2 changes: 2 additions & 0 deletions app/lib/blocs/dashbord_widgets_blocs/holiday_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class HolidayBloc extends BlocBase {

final HolidayStateGateway stateGateway;
Stream<StateEnum> get userState => stateGateway.userState;
Stream<bool> get hasStateSelected =>
userState.map((state) => state != null && state != StateEnum.notSelected);
Future<void> Function(StateEnum state) get changeState =>
stateGateway.changeState;

Expand Down
2 changes: 1 addition & 1 deletion app/lib/dashboard/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class DashboardPageBody extends StatelessWidget {
const _HomeworkSection(),
_EventsSection(),
_BlackboardSection(),
_HolidayCountdownSection(),
HolidayCountdownSection(),
const SizedBox(height: 32)
],
),
Expand Down
25 changes: 18 additions & 7 deletions app/lib/dashboard/sections/holiday_countdown_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

part of '../dashboard_page.dart';

class _HolidayCountdownSection extends StatelessWidget {
const _HolidayCountdownSection({Key key}) : super(key: key);
@visibleForTesting
class HolidayCountdownSection extends StatelessWidget {
const HolidayCountdownSection({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -21,11 +22,11 @@ class _HolidayCountdownSection extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
child: CustomCard(
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 12),
child: SizedBox(
width: double.infinity,
child: StreamBuilder<bool>(
stream: bloc.userState
.map((state) => state != StateEnum.notSelected),
stream: bloc.hasStateSelected,
builder: (context, snapshot) {
if (!snapshot.hasData) return Container(height: 50);
final hasUserSelectedState = snapshot.data;
Expand Down Expand Up @@ -56,9 +57,13 @@ class _HolidayCounter extends StatelessWidget {
if (!snapshot.hasData)
return const Center(child: AccentColorCircularProgressIndicator());
if (snapshot.data.isEmpty) return handleError(null);
return _HolidayText(
maxItems: 2,
holidayList: snapshot.data,
return DefaultTextStyle(
style: DefaultTextStyle.of(context).style,
textAlign: TextAlign.center,
child: _HolidayText(
maxItems: 2,
holidayList: snapshot.data,
),
);
},
),
Expand Down Expand Up @@ -142,6 +147,12 @@ class _HolidayText extends StatelessWidget {
}
}

final isFirstText = holidayList.first.slug == holiday.slug;
if (!isFirstText) {
// Add padding between the text widgets
widgetList.add(SizedBox(height: 4));
}

widgetList.add(textWidget);
});
return widgetList;
Expand Down
83 changes: 83 additions & 0 deletions app/test/dashboard/dashboard_page_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt)
// Licensed under the EUPL-1.2-or-later.
//
// You may obtain a copy of the Licence at:
// https://joinup.ec.europa.eu/software/page/eupl
//
// SPDX-License-Identifier: EUPL-1.2

import 'dart:async';
import 'dart:convert';

import 'package:bloc_provider/bloc_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:golden_toolkit/golden_toolkit.dart';
import 'package:intl/intl.dart';
import 'package:sharezone/blocs/dashbord_widgets_blocs/holiday_bloc.dart';
import 'package:sharezone/dashboard/dashboard_page.dart';
import 'package:sharezone/models/extern_apis/holiday.dart';

class FakeHolidayBloc extends Fake implements HolidayBloc {
StreamController<bool> hasStateSelectedController = StreamController();
StreamController<List<Holiday>> holidaysController = StreamController();

@override
Stream<List<Holiday>> get holidays => holidaysController.stream;

@override
Stream<bool> get hasStateSelected => hasStateSelectedController.stream;

@override
void dispose() {
holidaysController.close();
hasStateSelectedController.close();
}
}

void main() {
group('DashboardPage', () {
testGoldens('displays holiday card as excepted', (tester) async {
final holidayBloc = FakeHolidayBloc();
addTearDown(holidayBloc.dispose);

final now = DateTime.now();
final firstHolidays = Holiday.fromJson(jsonEncode({
"start": "${DateFormat('yyyy-MM-dd').format(now)}",
"end": "${now.year + 1}-02-01",
"year": now.year,
"stateCode": "HB",
"name": "winterferien, aber mit einem sehr langen Namen",
"slug": "winterferien 2022-2022-HB"
}));

final secondHolidays = Holiday.fromJson(jsonEncode({
"start":
"${DateFormat('yyyy-MM-dd').format(now.add(Duration(days: 20)))}",
"end": "${now.year + 1}-02-01",
"year": now.year,
"stateCode": "HB",
"name": "osterferien",
"slug": "osterferien 2022-2022-HB"
}));

holidayBloc.holidaysController.add([firstHolidays, secondHolidays]);
holidayBloc.hasStateSelectedController.add(true);

await tester.pumpWidget(
BlocProvider<HolidayBloc>(
bloc: holidayBloc,
child: MaterialApp(
home: Scaffold(
body: Center(
child: HolidayCountdownSection(),
),
),
),
),
);

await multiScreenGolden(tester, 'holiday_card', devices: [Device.phone]);
});
});
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.