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

feat(deriv_auth): Add language selector in auth package #576

Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:math' as math;
import 'package:deriv_auth/core/extensions/context_extension.dart';
import 'package:deriv_auth/core/helpers/semantic_labels.dart';
import 'package:deriv_auth/features/get_started/models/deriv_get_started_slide_model.dart';
import 'package:deriv_language_selector/deriv_language_selector.dart';
import 'package:deriv_theme/deriv_theme.dart';
import 'package:deriv_ui/deriv_ui.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -110,6 +111,17 @@ class _DerivGetStartedLayoutState extends State<DerivGetStartedLayout> {
title: AppSettingGestureDetector(
onTapNavigation: widget.onTapNavigation,
child: SvgPicture.asset(widget.appLogoIconPath)),
actions: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(
horizontal: ThemeProvider.margin16,
vertical: ThemeProvider.margin08,
),
child: LanguageSelector.button(
bottomsheetTitle: context.derivAuthLocalization.labelLanguage,
),
),
],
);

Timer _buildNewScrollTimer() => Timer.periodic(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:deriv_auth/features/auth/cubit/deriv_auth_cubit.dart';
import 'package:deriv_auth/features/reset_password/cubit/reset_password_cubit.dart';
import 'package:deriv_auth/features/signup/cubit/signup_cubit.dart';
import 'package:deriv_auth/features/social_auth/cubit/social_auth_cubit.dart';
import 'package:deriv_language_selector/deriv_language_selector.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

Expand All @@ -14,6 +15,7 @@ class AuthProvider extends StatelessWidget {
required this.socialAuthCubit,
required this.derivResetPassCubit,
required this.derivSignupCubit,
required this.languageCubit,
});

/// Child widget
Expand All @@ -31,6 +33,9 @@ class AuthProvider extends StatelessWidget {
/// Instance of Signup Cubit
final DerivSignupCubit derivSignupCubit;

/// Instance of language Cubit
final LanguageCubit languageCubit;

Widget build(BuildContext context) => MultiBlocProvider(
providers: [
BlocProvider<DerivAuthCubit>.value(
Expand All @@ -45,6 +50,9 @@ class AuthProvider extends StatelessWidget {
BlocProvider<DerivSignupCubit>.value(
value: derivSignupCubit,
),
BlocProvider<LanguageCubit>.value(
value: languageCubit,
),
],
child: widget,
);
Expand Down
6 changes: 6 additions & 0 deletions packages/deriv_auth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ dependencies:
url: [email protected]:regentmarkets/flutter-deriv-packages.git
path: packages/deriv_localizations
ref: deriv_localizations-v1.3.0

deriv_language_selector:
git:
url: [email protected]:regentmarkets/flutter-deriv-packages.git
path: packages/deriv_language_selector
ref: deriv_language_selector-v0.0.2+1

flutter_bloc: ^8.1.3
flutter_svg: ^2.0.7
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// ignore_for_file: always_specify_types

import 'package:bloc_test/bloc_test.dart';
import 'package:deriv_auth/features/get_started/models/deriv_get_started_slide_model.dart';
import 'package:deriv_auth/features/get_started/presentation/layouts/deriv_get_started_layout.dart';
import 'package:deriv_language_selector/deriv_language_selector.dart';
import 'package:deriv_localizations/l10n/generated/deriv_auth/deriv_auth_localizations.dart';
import 'package:deriv_localizations/l10n/generated/deriv_auth/deriv_auth_localizations_ar.dart';
import 'package:deriv_ui/deriv_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:patrol_finders/patrol_finders.dart';
Expand All @@ -13,50 +18,62 @@ import '../../../../pump_app.dart';
class MockDerivGetStartedSlideModel extends Mock
implements DerivGetStartedSlideModel {}

class MockLanguageCubit extends MockCubit<LanguageState>
implements LanguageCubit {}

void main() {
group('DerivGetStartedLayout', () {
late MockDerivGetStartedSlideModel mockSlideModel;

const String appLogoIconPath = 'assets/icons/ic_logo_extended.svg';
const String backgroundImagePath = 'assets/images/triangles.svg';

final MockLanguageCubit mockLanguageCubit = MockLanguageCubit();

setUpAll(() {
mockSlideModel = MockDerivGetStartedSlideModel();
when(() => mockSlideModel.imagePath)
.thenReturn('assets/images/charts.svg');
when(() => mockSlideModel.supportingText).thenReturn('Supporting text');
});

patrolWidgetTest('should render DerivGetStartedLayout',
(PatrolTester $) async {
await $.pumpApp(DerivGetStartedLayout(
onTapNavigation: (context) {},
slides: [mockSlideModel],
appLogoIconPath: appLogoIconPath,
backgroundImagePath: backgroundImagePath,
onLoginTapped: () {},
onSignupTapped: () {},
));

expect($(DerivGetStartedLayout), findsOneWidget);
expect($(AppBar), findsOneWidget);
expect($(PrimaryButton), findsOneWidget);
expect($(SecondaryButton), findsOneWidget);
final LanguageModel languageModel = LanguageModel(
code: 'en',
flag: 'assets/icons/flags/ic_flag_en.png',
name: 'English',
);

when(() => mockLanguageCubit.state).thenReturn(
LanguageLoadedState(
activeLanguages: [
languageModel,
],
language: languageModel,
),
);
});

patrolWidgetTest('should call onLoginTapped when login button is pressed',
(PatrolTester $) async {
bool loginTapped = false;

await $.pumpApp(DerivGetStartedLayout(
onTapNavigation: (context) {},
slides: [mockSlideModel],
appLogoIconPath: appLogoIconPath,
backgroundImagePath: backgroundImagePath,
onLoginTapped: () {
loginTapped = true;
},
onSignupTapped: () {},
await $.pumpApp(BlocProvider<LanguageCubit>(
create: (_) => mockLanguageCubit,
child: MaterialApp(
localizationsDelegates: const [DerivAuthLocalizations.delegate],
locale: const Locale('en'),
home: Scaffold(
body: DerivGetStartedLayout(
onTapNavigation: (context) {},
slides: [mockSlideModel],
appLogoIconPath: appLogoIconPath,
backgroundImagePath: backgroundImagePath,
onLoginTapped: () {
loginTapped = true;
},
onSignupTapped: () {},
),
),
),
));

await $.tap($(SecondaryButton));
Expand All @@ -68,16 +85,27 @@ void main() {
(PatrolTester $) async {
bool signupTapped = false;

await $.pumpApp(DerivGetStartedLayout(
onTapNavigation: (context) {},
slides: [mockSlideModel],
appLogoIconPath: appLogoIconPath,
backgroundImagePath: backgroundImagePath,
onLoginTapped: () {},
onSignupTapped: () {
signupTapped = true;
},
));
await $.pumpApp(
BlocProvider<LanguageCubit>(
create: (_) => mockLanguageCubit,
child: MaterialApp(
localizationsDelegates: const [DerivAuthLocalizations.delegate],
locale: const Locale('en'),
home: Scaffold(
body: DerivGetStartedLayout(
onTapNavigation: (context) {},
slides: [mockSlideModel],
appLogoIconPath: appLogoIconPath,
backgroundImagePath: backgroundImagePath,
onLoginTapped: () {},
onSignupTapped: () {
signupTapped = true;
},
),
),
),
),
);

await $.tap($(PrimaryButton));

Expand Down
Loading