Skip to content

Commit

Permalink
feat(kiali): add tests for the overview page (#1790)
Browse files Browse the repository at this point in the history
feat(kiali): add tests for the overview page
  • Loading branch information
matejnesuta authored Jun 26, 2024
1 parent 52aaaec commit 582cf36
Show file tree
Hide file tree
Showing 17 changed files with 356 additions and 22 deletions.
4 changes: 2 additions & 2 deletions plugins/kiali/dev/__fixtures__/general/istioValidations.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
},
"travel-control": {
"errors": 0,
"objectCount": 0,
"warnings": 0
"objectCount": 1,
"warnings": 1
},
"travel-portal": {
"errors": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"desiredReplicas": 1,
"currentReplicas": 1,
"availableReplicas": 1,
"syncedProxies": 1
"syncedProxies": 0
}
],
"requests": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "control",
"desiredReplicas": 1,
"currentReplicas": 1,
"currentReplicas": 0,
"availableReplicas": 1,
"syncedProxies": 1
}
Expand Down
13 changes: 9 additions & 4 deletions plugins/kiali/src/components/About/AboutUIModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ export const AboutUIModal = (props: AboutUIModalProps) => {
<Grid item xs={8} key={`component_${name}`}>
{name}
</Grid>
<Grid item xs={4} key={`component_version_${name}`}>
<Grid
data-test={`${externalService.name}`}
item
xs={4}
key={`component_version_${name}`}
>
{additionalInfo}
</Grid>
</>
Expand Down Expand Up @@ -158,19 +163,19 @@ export const AboutUIModal = (props: AboutUIModalProps) => {
<Grid item xs={4}>
Kiali
</Grid>
<Grid item xs={8}>
<Grid item xs={8} data-test="Kiali">
{coreVersion || 'Unknown'}
</Grid>
<Grid item xs={4}>
Kiali Container
</Grid>
<Grid item xs={8}>
<Grid item xs={8} data-test="Kiali container">
{containerVersion || 'Unknown'}
</Grid>
<Grid item xs={4}>
Service Mesh
</Grid>
<Grid item xs={8}>
<Grid item xs={8} data-test="Service Mesh">
{meshVersion || 'Unknown'}
</Grid>
<Grid item xs={4}>
Expand Down
3 changes: 2 additions & 1 deletion plugins/kiali/src/components/MessageCenter/AlertDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const noNotificationsMessage = (

export const AlertDrawer = (props: AlertDrawerProps) => {
return (
<Card className={drawer}>
<Card className={drawer} data-test="message-center-modal">
<CardMedia>
<ItemCardHeader title="MessageCenter" subtitle="" />
</CardMedia>
Expand All @@ -74,6 +74,7 @@ export const AlertDrawer = (props: AlertDrawerProps) => {
<AccordionSummary
key={`${group.id}_item`}
expandIcon={<ExpandMoreRounded />}
data-test="message-center-summary"
>
<Typography>
{group.title} {getUnreadMessageLabel(group.messages)}
Expand Down
17 changes: 14 additions & 3 deletions plugins/kiali/src/components/MessageCenter/AlertDrawerGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,29 @@ export const AlertDrawerGroup = (props: AlertDrawerGroupProps) => {

return (
<Card elevation={0}>
<CardContent style={{ paddingTop: 0 }}>
<CardContent
style={{ paddingTop: 0 }}
data-test="message-center-messages"
>
{group.messages.length === 0 && noNotificationsMessage}
{getMessages().map(message => (
<AlertDrawerMessage key={message.id} message={message} />
))}
</CardContent>
{group.showActions && group.messages.length > 0 && (
<CardActions>
<Button variant="text" onClick={() => markGroupAsRead(group.id)}>
<Button
data-test="mark-as-read"
variant="text"
onClick={() => markGroupAsRead(group.id)}
>
Mark All Read
</Button>
<Button variant="text" onClick={() => clearGroup(group.id)}>
<Button
data-test="clear-all"
variant="text"
onClick={() => clearGroup(group.id)}
>
Clear All
</Button>
</CardActions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const AlertDrawerMessage = (props: AlertDrawerMessageProps) => {

return (
<Card>
<CardContent>
<CardContent data-test="drawer-message">
{getIcon(props.message.type)}{' '}
{props.message.seen ? (
props.message.content
Expand All @@ -60,11 +60,17 @@ export const AlertDrawerMessage = (props: AlertDrawerMessageProps) => {
onClick={() => toggleMessageDetail(props.message)}
expandIcon={<ExpandMoreRounded />}
>
<Typography>
<Typography
data-test={
props.message.showDetail
? 'hide-message-detail'
: 'show-message-detail'
}
>
{props.message.showDetail ? 'Hide Detail' : 'Show Detail'}
</Typography>
</AccordionSummary>
<AccordionDetails>
<AccordionDetails data-test="message-detail">
<pre style={{ whiteSpace: 'pre-wrap' }}>
{props.message.detail}
</pre>
Expand Down
6 changes: 5 additions & 1 deletion plugins/kiali/src/components/MessageCenter/MessageCenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export const MessageCenter = (props: { color?: string }) => {
*/
return (
<>
<Button onClick={() => toggleDrawer(true)} style={{ marginTop: '-15px' }}>
<Button
onClick={() => toggleDrawer(true)}
style={{ marginTop: '-15px' }}
data-test="message-center"
>
<Badge
overlap="circular"
badgeContent={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const ValidationSummary = (props: Props) => {
return (
<Tooltip
aria-label="Validations list"
data-test={`validation-icon-${severity()}`}
placement="right"
title={tooltipContent()}
>
Expand Down
6 changes: 5 additions & 1 deletion plugins/kiali/src/pages/Kiali/Header/HelpKiali.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export const HelpKiali = (props: { color?: string }) => {

return (
<>
<Button onClick={openAbout} style={{ marginTop: '-5px' }}>
<Button
onClick={openAbout}
style={{ marginTop: '-5px' }}
data-test="help-button"
>
<QuestionCircleIcon color={`${props.color}`} />
</Button>
<AboutUIModal
Expand Down
2 changes: 2 additions & 0 deletions plugins/kiali/src/pages/Kiali/Header/KialiHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const KialiHeader = () => {
color="primary"
icon={<ClusterIcon />}
label={homeCluster?.name}
data-test="home-cluster"
/>
</Tooltip>
<HelpKiali />
Expand All @@ -35,6 +36,7 @@ export const KialiHeader = () => {
flexDirection: 'row',
justifyContent: 'space-between',
}}
data-test="user"
>
<span style={{ margin: '10px' }}>
<b>User : </b>
Expand Down
1 change: 1 addition & 0 deletions plugins/kiali/src/pages/Kiali/Header/NamespaceSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const NamespaceSelector = (props: { page?: boolean }) => {
onChange={handleChange}
renderValue={selected => (selected as string[]).join(', ')}
MenuProps={MenuProps}
data-test="namespace-selector"
>
{(kialiState.namespaces.items || []).map(ns => (
<MenuItem key={ns.name} value={ns.name}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const NamespaceLabels = (props: NamespaceLabelsprops) => {
? `${Object.entries(props.labels).length}`
: 'No';
const tooltipTitle = (
<ul>
<ul data-test="namespace-labels">
{Object.entries(props.labels || []).map(([key, value]) => (
<li key={key}>
{key}={value}
Expand All @@ -27,7 +27,7 @@ export const NamespaceLabels = (props: NamespaceLabelsprops) => {
{labelsLength} label{labelsLength !== '1' ? 's' : ''}
</div>
<Tooltip title={tooltipTitle} placement="right">
<span>
<span data-test="labels-info-icon">
<KialiIcon.Info className={infoStyle} />
</span>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ export const OverviewCard = (props: OverviewCardProps) => {
errors={validations.errors}
warnings={validations.warnings}
objectCount={validations.objectCount}
data-test="validation-summary"
/>
);
};

return (
<Card>
<Card data-test={`overview-card-${props.namespace.name}`}>
{!props.entity && <NamespaceHeader {...props} />}
<CardContent>
{!props.entity && isMultiCluster && props.namespace.cluster && (
Expand Down
6 changes: 4 additions & 2 deletions plugins/kiali/src/pages/Overview/OverviewStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export class OverviewStatus extends React.Component<Props, {}> {
items.push(`and ${length - items.length} more...`);
}
const tooltipContent = (
<div>
<strong>{this.props.status.name}</strong>
<div data-test="overview-status">
<strong data-test={`${this.props.status.name}-status`}>
{this.props.status.name}
</strong>
{items.map((app, idx) => {
return (
<div
Expand Down
2 changes: 2 additions & 0 deletions plugins/kiali/tests/kialiHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect, type Locator, type Page } from '@playwright/test';

export { kialiData } from '../dev/__fixtures__';

export class Common {
page: Page;

Expand Down
Loading

0 comments on commit 582cf36

Please sign in to comment.