Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RocketChat
Rocket.Chat
Commits
037128cc
Unverified
Commit
037128cc
authored
7 months ago
by
Douglas Fabris
Committed by
GitHub
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
test: Add some unit tests for `useRetentionPolicy` (#33196)
parent
377b8bbd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/meteor/client/views/room/hooks/useRetentionPolicy.spec.ts
+87
-0
87 additions, 0 deletions
...meteor/client/views/room/hooks/useRetentionPolicy.spec.ts
apps/meteor/tests/mocks/data.ts
+1
-1
1 addition, 1 deletion
apps/meteor/tests/mocks/data.ts
with
88 additions
and
1 deletion
apps/meteor/client/views/room/hooks/useRetentionPolicy.spec.ts
0 → 100644
+
87
−
0
View file @
037128cc
import
{
mockAppRoot
}
from
'
@rocket.chat/mock-providers
'
;
import
{
renderHook
}
from
'
@testing-library/react
'
;
import
{
createFakeRoom
}
from
'
../../../../tests/mocks/data
'
;
import
{
useRetentionPolicy
}
from
'
./useRetentionPolicy
'
;
const
getGlobalSettings
=
({
enabled
=
false
,
filesOnly
=
false
,
doNotPrunePinned
=
false
,
ignoreThreads
=
false
,
appliesToChannels
=
false
,
appliesToGroups
=
false
,
appliesToDMs
=
false
,
})
=>
{
return
mockAppRoot
()
.
withSetting
(
'
RetentionPolicy_Enabled
'
,
enabled
)
.
withSetting
(
'
RetentionPolicy_FilesOnly
'
,
filesOnly
)
.
withSetting
(
'
RetentionPolicy_DoNotPrunePinned
'
,
doNotPrunePinned
)
.
withSetting
(
'
RetentionPolicy_DoNotPruneThreads
'
,
ignoreThreads
)
.
withSetting
(
'
RetentionPolicy_AppliesToChannels
'
,
appliesToChannels
)
.
withSetting
(
'
RetentionPolicy_AppliesToGroups
'
,
appliesToGroups
)
.
withSetting
(
'
RetentionPolicy_AppliesToDMs
'
,
appliesToDMs
);
};
const
defaultValue
=
{
enabled
:
false
,
isActive
:
false
,
filesOnly
:
false
,
excludePinned
:
false
,
ignoreThreads
:
false
,
};
const
roomTypeConfig
=
{
c
:
{
appliesToChannels
:
true
},
p
:
{
appliesToGroups
:
true
},
d
:
{
appliesToDMs
:
true
},
};
const
CHANNELS_TYPE
=
'
c
'
;
it
(
'
should return the default value if global retention is not enabled
'
,
async
()
=>
{
const
fakeRoom
=
createFakeRoom
({
t
:
CHANNELS_TYPE
});
const
{
result
}
=
renderHook
(()
=>
useRetentionPolicy
(
fakeRoom
),
{
legacyRoot
:
true
,
wrapper
:
getGlobalSettings
({}).
build
(),
});
expect
(
result
.
current
).
toEqual
(
expect
.
objectContaining
(
defaultValue
));
});
it
(
'
should return enabled true if global retention is enabled
'
,
async
()
=>
{
const
fakeRoom
=
createFakeRoom
({
t
:
CHANNELS_TYPE
});
const
{
result
}
=
renderHook
(()
=>
useRetentionPolicy
(
fakeRoom
),
{
legacyRoot
:
true
,
wrapper
:
getGlobalSettings
({
enabled
:
true
}).
build
(),
});
expect
(
result
.
current
).
toEqual
(
expect
.
objectContaining
({
...
defaultValue
,
enabled
:
true
}));
});
it
(
'
should return enabled and active true global retention is active for rooms of the type
'
,
async
()
=>
{
const
fakeRoom
=
createFakeRoom
({
t
:
CHANNELS_TYPE
});
const
{
result
}
=
renderHook
(()
=>
useRetentionPolicy
(
fakeRoom
),
{
legacyRoot
:
true
,
wrapper
:
getGlobalSettings
({
enabled
:
true
,
...
roomTypeConfig
[
CHANNELS_TYPE
]
}).
build
(),
});
expect
(
result
.
current
).
toEqual
(
expect
.
objectContaining
({
...
defaultValue
,
enabled
:
true
,
isActive
:
true
}));
});
it
.
failing
(
'
should isActive be false if global retention is active for rooms of the type and room has retention.enabled false
'
,
async
()
=>
{
const
fakeRoom
=
createFakeRoom
({
t
:
CHANNELS_TYPE
,
retention
:
{
enabled
:
false
}
});
const
{
result
}
=
renderHook
(()
=>
useRetentionPolicy
(
fakeRoom
),
{
legacyRoot
:
true
,
wrapper
:
getGlobalSettings
({
enabled
:
true
,
...
roomTypeConfig
[
CHANNELS_TYPE
]
}).
build
(),
});
expect
(
result
.
current
?.
isActive
).
toBe
(
false
);
},
);
This diff is collapsed.
Click to expand it.
apps/meteor/tests/mocks/data.ts
+
1
−
1
View file @
037128cc
...
...
@@ -21,7 +21,7 @@ export function createFakeUser(overrides?: Partial<IUser>): IUser {
};
}
export
const
createFakeRoom
=
(
overrides
?:
Partial
<
IRoom
>
):
IRoom
=>
({
export
const
createFakeRoom
=
(
overrides
?:
Partial
<
IRoom
&
{
retention
?:
{
enabled
:
boolean
}
}
>
):
IRoom
=>
({
_id
:
faker
.
database
.
mongodbObjectId
(),
_updatedAt
:
faker
.
date
.
recent
(),
t
:
faker
.
helpers
.
arrayElement
([
'
c
'
,
'
p
'
,
'
d
'
]),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment