Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek committed Jan 15, 2025
1 parent 460f672 commit a133a6e
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test('render initial stage', async () => {

renderOpenTooltip({ name: 'initial', enteredStageAt });

await screen.findByText('initial');
await screen.findByText('Define');
await screen.findByText('2 minutes');
await screen.findByText(
'This feature flag is currently in the initial phase of its lifecycle.',
Expand All @@ -69,7 +69,7 @@ test('render pre-live stage', async () => {
enteredStageAt,
});

await screen.findByText('pre-live');
await screen.findByText('Develop');
await screen.findByText('development');
await screen.findByText('1 hour ago');
});
Expand All @@ -86,8 +86,8 @@ test('render live stage', async () => {
});

await screen.findByText('Is this feature complete?');
await screen.findByText('live');
await screen.findByText('production');
await screen.findByText('Production');
// await screen.findByText('production');
await screen.findByText('2 hours ago');
});

Expand All @@ -103,7 +103,7 @@ test('render completed stage with still active', async () => {
enteredStageAt,
});

await screen.findByText('completed');
await screen.findByText('Cleanup');
await screen.findByText('production');
await screen.findByText('2 hours ago');
expect(screen.queryByText('Archive feature')).not.toBeInTheDocument();
Expand All @@ -127,7 +127,7 @@ test('render completed stage safe to archive', async () => {
onArchive,
);

await screen.findByText('completed');
await screen.findByText('Cleanup');
const button = await screen.findByText('Archive feature');
button.click();

Expand All @@ -153,7 +153,7 @@ test('mark completed button gets activated', async () => {
onComplete,
);

await screen.findByText('live');
await screen.findByText('Production');
const button = await screen.findByText('Mark completed');
button.click();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { screen } from '@testing-library/react';
import { FeatureLifecycleTooltip } from './LegacyFeatureLifecycleTooltip';
import { render } from 'utils/testRenderer';
import userEvent from '@testing-library/user-event';
import { vi } from 'vitest';
import type { LifecycleStage } from './LifecycleStage';
import {
DELETE_FEATURE,
UPDATE_FEATURE,
} from 'component/providers/AccessProvider/permissions';

const currentTime = '2024-04-25T08:05:00.000Z';
const twoMinutesAgo = '2024-04-25T08:03:00.000Z';
const oneHourAgo = '2024-04-25T07:05:00.000Z';
const twoHoursAgo = '2024-04-25T06:05:00.000Z';

const renderOpenTooltip = (
stage: LifecycleStage,
onArchive = () => {},
onComplete = () => {},
onUncomplete = () => {},
loading = false,
) => {
render(
<FeatureLifecycleTooltip
stage={stage}
onArchive={onArchive}
onComplete={onComplete}
onUncomplete={onUncomplete}
loading={loading}
project={'default'}
>
<span>child</span>
</FeatureLifecycleTooltip>,
{
permissions: [
{ permission: DELETE_FEATURE },
{ permission: UPDATE_FEATURE },
],
},
);

const child = screen.getByText('child');

userEvent.hover(child);
};

test('render initial stage', async () => {
vi.setSystemTime(currentTime);
const enteredStageAt = twoMinutesAgo;

renderOpenTooltip({ name: 'initial', enteredStageAt });

await screen.findByText('initial');
await screen.findByText('2 minutes');
await screen.findByText(
'This feature flag is currently in the initial phase of its lifecycle.',
);
});

test('render pre-live stage', async () => {
vi.setSystemTime(currentTime);
const enteredStageAt = twoMinutesAgo;
const lastSeenAt = oneHourAgo;

renderOpenTooltip({
name: 'pre-live',
environments: [{ name: 'development', lastSeenAt }],
enteredStageAt,
});

await screen.findByText('pre-live');
await screen.findByText('development');
await screen.findByText('1 hour ago');
});

test('render live stage', async () => {
vi.setSystemTime(currentTime);
const enteredStageAt = twoMinutesAgo;
const lastSeenAt = twoHoursAgo;

renderOpenTooltip({
name: 'live',
environments: [{ name: 'production', lastSeenAt }],
enteredStageAt,
});

await screen.findByText('Is this feature complete?');
await screen.findByText('live');
await screen.findByText('production');
await screen.findByText('2 hours ago');
});

test('render completed stage with still active', async () => {
vi.setSystemTime(currentTime);
const enteredStageAt = twoMinutesAgo;
const lastSeenAt = twoHoursAgo;

renderOpenTooltip({
name: 'completed',
status: 'kept',
environments: [{ name: 'production', lastSeenAt }],
enteredStageAt,
});

await screen.findByText('completed');
await screen.findByText('production');
await screen.findByText('2 hours ago');
expect(screen.queryByText('Archive feature')).not.toBeInTheDocument();
});

test('render completed stage safe to archive', async () => {
vi.setSystemTime(currentTime);
const enteredStageAt = twoMinutesAgo;
let onArchiveInvoked = false;
const onArchive = () => {
onArchiveInvoked = true;
};

renderOpenTooltip(
{
name: 'completed',
status: 'kept',
environments: [],
enteredStageAt,
},
onArchive,
);

await screen.findByText('completed');
const button = await screen.findByText('Archive feature');
button.click();

expect(onArchiveInvoked).toBe(true);
});

test('mark completed button gets activated', async () => {
vi.setSystemTime(currentTime);
const enteredStageAt = twoMinutesAgo;
const lastSeenAt = twoHoursAgo;
let onCompleteInvoked = false;
const onComplete = () => {
onCompleteInvoked = true;
};

renderOpenTooltip(
{
name: 'live',
environments: [{ name: 'production', lastSeenAt }],
enteredStageAt,
},
() => {},
onComplete,
);

await screen.findByText('live');
const button = await screen.findByText('Mark completed');
button.click();

expect(onCompleteInvoked).toBe(true);
});

0 comments on commit a133a6e

Please sign in to comment.