Skip to content

Commit

Permalink
fix(test): resolve test user feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Lzyct committed Oct 3, 2024
1 parent 8edf158 commit cd683b8
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 136 deletions.
10 changes: 7 additions & 3 deletions lib/features/users/pages/dashboard/cubit/users_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_auth_app/core/core.dart';
import 'package:flutter_auth_app/features/features.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'users_cubit.freezed.dart';

part 'users_state.dart';

class UsersCubit extends Cubit<UsersState> {
Expand Down Expand Up @@ -53,8 +51,14 @@ class UsersCubit extends Cubit<UsersState> {
currentPage = r.currentPage ?? 1;
lastPage = r.lastPage ?? 1;

final updatedUsers = Users(
currentPage: currentPage,
lastPage: lastPage,
users: users,
);

if (currentPage != 1) emit(const _Initial());
emit(_Success(users));
emit(_Success(updatedUsers));
},
);
}
Expand Down
72 changes: 39 additions & 33 deletions lib/features/users/pages/dashboard/cubit/users_cubit.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mixin _$UsersState {
TResult when<TResult extends Object?>({
required TResult Function() loading,
required TResult Function() initial,
required TResult Function(List<User> data) success,
required TResult Function(Users data) success,
required TResult Function(String message) failure,
required TResult Function() empty,
}) =>
Expand All @@ -29,7 +29,7 @@ mixin _$UsersState {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? loading,
TResult? Function()? initial,
TResult? Function(List<User> data)? success,
TResult? Function(Users data)? success,
TResult? Function(String message)? failure,
TResult? Function()? empty,
}) =>
Expand All @@ -38,7 +38,7 @@ mixin _$UsersState {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? loading,
TResult Function()? initial,
TResult Function(List<User> data)? success,
TResult Function(Users data)? success,
TResult Function(String message)? failure,
TResult Function()? empty,
required TResult orElse(),
Expand Down Expand Up @@ -138,7 +138,7 @@ class _$LoadingImpl implements _Loading {
TResult when<TResult extends Object?>({
required TResult Function() loading,
required TResult Function() initial,
required TResult Function(List<User> data) success,
required TResult Function(Users data) success,
required TResult Function(String message) failure,
required TResult Function() empty,
}) {
Expand All @@ -150,7 +150,7 @@ class _$LoadingImpl implements _Loading {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? loading,
TResult? Function()? initial,
TResult? Function(List<User> data)? success,
TResult? Function(Users data)? success,
TResult? Function(String message)? failure,
TResult? Function()? empty,
}) {
Expand All @@ -162,7 +162,7 @@ class _$LoadingImpl implements _Loading {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? loading,
TResult Function()? initial,
TResult Function(List<User> data)? success,
TResult Function(Users data)? success,
TResult Function(String message)? failure,
TResult Function()? empty,
required TResult orElse(),
Expand Down Expand Up @@ -261,7 +261,7 @@ class _$InitialImpl implements _Initial {
TResult when<TResult extends Object?>({
required TResult Function() loading,
required TResult Function() initial,
required TResult Function(List<User> data) success,
required TResult Function(Users data) success,
required TResult Function(String message) failure,
required TResult Function() empty,
}) {
Expand All @@ -273,7 +273,7 @@ class _$InitialImpl implements _Initial {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? loading,
TResult? Function()? initial,
TResult? Function(List<User> data)? success,
TResult? Function(Users data)? success,
TResult? Function(String message)? failure,
TResult? Function()? empty,
}) {
Expand All @@ -285,7 +285,7 @@ class _$InitialImpl implements _Initial {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? loading,
TResult Function()? initial,
TResult Function(List<User> data)? success,
TResult Function(Users data)? success,
TResult Function(String message)? failure,
TResult Function()? empty,
required TResult orElse(),
Expand Down Expand Up @@ -347,7 +347,9 @@ abstract class _$$SuccessImplCopyWith<$Res> {
_$SuccessImpl value, $Res Function(_$SuccessImpl) then) =
__$$SuccessImplCopyWithImpl<$Res>;
@useResult
$Res call({List<User> data});
$Res call({Users data});

$UsersCopyWith<$Res> get data;
}

/// @nodoc
Expand All @@ -367,25 +369,30 @@ class __$$SuccessImplCopyWithImpl<$Res>
}) {
return _then(_$SuccessImpl(
null == data
? _value._data
? _value.data
: data // ignore: cast_nullable_to_non_nullable
as List<User>,
as Users,
));
}

/// Create a copy of UsersState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$UsersCopyWith<$Res> get data {
return $UsersCopyWith<$Res>(_value.data, (value) {
return _then(_value.copyWith(data: value));
});
}
}

/// @nodoc
class _$SuccessImpl implements _Success {
const _$SuccessImpl(final List<User> data) : _data = data;
const _$SuccessImpl(this.data);

final List<User> _data;
@override
List<User> get data {
if (_data is EqualUnmodifiableListView) return _data;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_data);
}
final Users data;

@override
String toString() {
Expand All @@ -397,12 +404,11 @@ class _$SuccessImpl implements _Success {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SuccessImpl &&
const DeepCollectionEquality().equals(other._data, _data));
(identical(other.data, data) || other.data == data));
}

@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(_data));
int get hashCode => Object.hash(runtimeType, data);

/// Create a copy of UsersState
/// with the given fields replaced by the non-null parameter values.
Expand All @@ -417,7 +423,7 @@ class _$SuccessImpl implements _Success {
TResult when<TResult extends Object?>({
required TResult Function() loading,
required TResult Function() initial,
required TResult Function(List<User> data) success,
required TResult Function(Users data) success,
required TResult Function(String message) failure,
required TResult Function() empty,
}) {
Expand All @@ -429,7 +435,7 @@ class _$SuccessImpl implements _Success {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? loading,
TResult? Function()? initial,
TResult? Function(List<User> data)? success,
TResult? Function(Users data)? success,
TResult? Function(String message)? failure,
TResult? Function()? empty,
}) {
Expand All @@ -441,7 +447,7 @@ class _$SuccessImpl implements _Success {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? loading,
TResult Function()? initial,
TResult Function(List<User> data)? success,
TResult Function(Users data)? success,
TResult Function(String message)? failure,
TResult Function()? empty,
required TResult orElse(),
Expand Down Expand Up @@ -494,9 +500,9 @@ class _$SuccessImpl implements _Success {
}

abstract class _Success implements UsersState {
const factory _Success(final List<User> data) = _$SuccessImpl;
const factory _Success(final Users data) = _$SuccessImpl;

List<User> get data;
Users get data;

/// Create a copy of UsersState
/// with the given fields replaced by the non-null parameter values.
Expand Down Expand Up @@ -575,7 +581,7 @@ class _$FailureImpl implements _Failure {
TResult when<TResult extends Object?>({
required TResult Function() loading,
required TResult Function() initial,
required TResult Function(List<User> data) success,
required TResult Function(Users data) success,
required TResult Function(String message) failure,
required TResult Function() empty,
}) {
Expand All @@ -587,7 +593,7 @@ class _$FailureImpl implements _Failure {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? loading,
TResult? Function()? initial,
TResult? Function(List<User> data)? success,
TResult? Function(Users data)? success,
TResult? Function(String message)? failure,
TResult? Function()? empty,
}) {
Expand All @@ -599,7 +605,7 @@ class _$FailureImpl implements _Failure {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? loading,
TResult Function()? initial,
TResult Function(List<User> data)? success,
TResult Function(Users data)? success,
TResult Function(String message)? failure,
TResult Function()? empty,
required TResult orElse(),
Expand Down Expand Up @@ -706,7 +712,7 @@ class _$EmptyImpl implements _Empty {
TResult when<TResult extends Object?>({
required TResult Function() loading,
required TResult Function() initial,
required TResult Function(List<User> data) success,
required TResult Function(Users data) success,
required TResult Function(String message) failure,
required TResult Function() empty,
}) {
Expand All @@ -718,7 +724,7 @@ class _$EmptyImpl implements _Empty {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? loading,
TResult? Function()? initial,
TResult? Function(List<User> data)? success,
TResult? Function(Users data)? success,
TResult? Function(String message)? failure,
TResult? Function()? empty,
}) {
Expand All @@ -730,7 +736,7 @@ class _$EmptyImpl implements _Empty {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? loading,
TResult Function()? initial,
TResult Function(List<User> data)? success,
TResult Function(Users data)? success,
TResult Function(String message)? failure,
TResult Function()? empty,
required TResult orElse(),
Expand Down
2 changes: 1 addition & 1 deletion lib/features/users/pages/dashboard/cubit/users_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ part of 'users_cubit.dart';
class UsersState with _$UsersState {
const factory UsersState.loading() = _Loading;
const factory UsersState.initial() = _Initial;
const factory UsersState.success(List<User> data) = _Success;
const factory UsersState.success(Users data) = _Success;
const factory UsersState.failure(String message) = _Failure;
const factory UsersState.empty() = _Empty;
}
Loading

0 comments on commit cd683b8

Please sign in to comment.