Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 32 additions & 1 deletion e2e-tests/tests/plan-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,34 @@ test.afterAll(async () => {
});

test.describe.serial('Plan Metadata', () => {
test('Description can be edited, read on both pages, and cleared', async () => {
await planA.showPanel(PanelNames.PLAN_METADATA, true);
const description = planA.panelPlanMetadata.getByLabel('Description', { exact: true });
const value = 'Plan purpose\nSecond line <plain text>';
await description.fill(value);
await description.press('Tab');
await expect(setupA.page.getByText('Plan Updated Successfully', { exact: true })).toBeVisible();
await setupA.page.reload();
await planA.showPanel(PanelNames.PLAN_METADATA, true);
await expect(description).toHaveValue(value);

await plansA.goto();
await plansA.filterTable(planA.planName);
await plansA.tableRow(planA.planName).click();
const selectedDescription = setupA.page.getByLabel('Description', { exact: true });
await expect(selectedDescription).toHaveValue(value);
await expect(selectedDescription).toHaveAttribute('readonly', '');

await planA.goto(String(planAId));
await planA.showPanel(PanelNames.PLAN_METADATA, true);
await description.fill('');
await description.press('Tab');
await expect(setupA.page.getByText('Plan Updated Successfully', { exact: true })).toBeVisible();
await setupA.page.reload();
await planA.showPanel(PanelNames.PLAN_METADATA, true);
await expect(description).toHaveValue('');
});

test('Plan should be re-nameable', async () => {
await planA.showPanel(PanelNames.PLAN_METADATA, true);
await planA.renamePlan(planA.planName + '_renamed');
Expand Down Expand Up @@ -173,7 +201,7 @@ test.describe.serial('Plan Metadata', () => {
await planA.removePlanCollaborator('userA');
});

test(`Non-collaborator userB as role user should not be able to edit userA's plan collaborators`, async () => {
test(`Non-collaborator userB as role user should not be able to edit userA's plan collaborators or metadata`, async () => {
// Use userB's separate browser context - no login/logout needed!
const userB = new User(setupB.page, 'userB');
await userB.gotoWithRetry('/plans');
Expand All @@ -183,6 +211,9 @@ test.describe.serial('Plan Metadata', () => {
await planAForUserB.showPanel(PanelNames.PLAN_METADATA, true);
await planAForUserB.waitForPlanCollaboratorLoad();
await expect(planAForUserB.planCollaboratorInputContainer).toHaveAttribute('readonly');
const description = planAForUserB.panelPlanMetadata.getByLabel('Description', { exact: true });
await expect(description).toHaveAttribute('readonly');
await expect(description).toBeEnabled();
});

test(`userB can be added as a plan collaborator to userA's plan`, async () => {
Expand Down
8 changes: 8 additions & 0 deletions e2e-tests/tests/plans.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ test.describe('Plans - Form Validation', () => {
test.describe.serial('Plans - CRUD Operations', () => {
test('Create plan', async () => {
await setup.plans.goto();
await setup.page.getByLabel('Description', { exact: true }).fill('Created description\nSecond line');
await setup.plans.createPlan();
await expect(setup.page.getByLabel('Description', { exact: true })).toHaveValue('');
await setup.plans.tableRow(setup.plans.planName).click();
await expect(setup.page.getByLabel('Description', { exact: true })).toHaveValue('Created description\nSecond line');
await setup.page.reload();
await setup.plans.filterTable(setup.plans.planName);
await setup.plans.tableRow(setup.plans.planName).click();
await expect(setup.page.getByLabel('Description', { exact: true })).toHaveValue('Created description\nSecond line');
});

test('Delete plan', async () => {
Expand Down
24 changes: 24 additions & 0 deletions src/components/plan/PlanForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
'Plan name already exists',
),
]);
let planDescription: string = '';
let planExporting: boolean = false;

$: permissionError = $planReadOnly ? PlanStatusMessages.READ_ONLY : 'You do not have permission to edit this plan.';
Expand Down Expand Up @@ -109,6 +110,7 @@
}
$: if (plan) {
planNameField.validateAndSet(plan?.name ?? '');
planDescription = plan.description ?? '';
}

async function onTagsInputChange(event: TagsChangeEvent) {
Expand Down Expand Up @@ -172,6 +174,12 @@
}
}

async function onPlanDescriptionChange() {
if (plan && hasPlanUpdatePermission && planDescription !== (plan.description ?? '')) {
await effects.updatePlan(plan, { description: planDescription }, user);
}
}

async function onExportPlan() {
if (plan && !planExporting && !$planImportRequest && activityDirectivesMap) {
planExporting = true;
Expand Down Expand Up @@ -224,6 +232,22 @@
</Input>
</Field>
</div>
<Input layout="inline" class="!items-baseline">
<label for="plan-description">Description</label>
<textarea
aria-label="Description"
id="plan-description"
name="plan-description"
class="st-input resize-y"
rows={4}
use:permissionHandler={{
hasPermission: hasPlanUpdatePermission,
permissionError,
}}
bind:value={planDescription}
on:change={onPlanDescriptionChange}
/>
</Input>
<Input layout="inline">
<label use:tooltip={{ content: 'ID', placement: 'top' }} for="id">Plan ID</label>
<input class="st-input w-full" disabled name="id" value={plan.id} id="id" />
Expand Down
1 change: 1 addition & 0 deletions src/components/plan/PlanMergeReview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const mockInitialPlan: Plan = {
collaborators: [{ collaborator: 'tester 2' }],
constraint_specification: [],
created_at: '2023-02-16T00:00:00',
description: '',
duration: '168:00:00',
end_time_doy: '2023-054T00:00:00',
id: 1,
Expand Down
29 changes: 28 additions & 1 deletion src/routes/plans/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Alert, Button, cn, Input as InputStellar, Label, Select } from '@nasa-jpl/stellar-svelte';
import { Alert, Button, cn, Input as InputStellar, Label, Select, Textarea } from '@nasa-jpl/stellar-svelte';
import type { ICellRendererParams, ValueGetterParams } from 'ag-grid-community';
import { flatten } from 'lodash-es';
import { FileUp, Import, LoaderCircle, LockKeyhole, Pencil, TriangleAlert, X } from 'lucide-svelte';
Expand Down Expand Up @@ -365,6 +365,7 @@
// This array should only be mutated to avoid extra re-renders. It is not needed for rendering as $planImportRequests will
// be used to track the status of the import requests and retrigger a render
let currentImportRequests: { planName: string; requestId: number }[] = [];
let description: string = '';
let durationString: string = 'None';
let filterText: string = '';
let isPlanImportMode: boolean = false;
Expand Down Expand Up @@ -582,6 +583,7 @@
startTime,
$simTemplateField.value,
$user,
description,
);
if (newPlan) {
// Associate new tags with plan
Expand All @@ -597,6 +599,7 @@
startTimeField.reset('');
endTimeField.reset('');
nameField.reset('');
description = '';
}
}
}
Expand Down Expand Up @@ -931,6 +934,16 @@
value={selectedPlan.name}
/>
</div>
<div class="flex flex-col gap-0.5 pt-2">
<Label size="sm" for="selected-plan-description">Description</Label>
<Textarea
id="selected-plan-description"
class="px-2 py-1 text-xs"
rows={4}
readonly
value={selectedPlan.description ?? ''}
/>
</div>
<div class="flex flex-col gap-0.5 pt-2">
<Label size="sm" for="selected-plan-model">Model</Label>
{#if selectedPlan.is_read_only}
Expand Down Expand Up @@ -1193,6 +1206,20 @@
</div>
</Field>

{#if !isPlanImportMode}
<fieldset>
<Label size="sm" class="pb-0.5" for="plan-description">Description</Label>
<Textarea
id="plan-description"
name="description"
class="px-2 py-1 text-xs"
rows={4}
disabled={!canCreate}
bind:value={description}
/>
</fieldset>
{/if}

<fieldset>
<DatePickerField
disabled={!canModify}
Expand Down
5 changes: 4 additions & 1 deletion src/types/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type PlanCollaborator = { collaborator: UserId; plan_id: number };

export type PlanCollaboratorSlim = Pick<PlanCollaborator, 'collaborator'>;

export type PlanInsertInput = Pick<PlanSchema, 'duration' | 'model_id' | 'name' | 'start_time'>;
export type PlanInsertInput = Pick<PlanSchema, 'description' | 'duration' | 'model_id' | 'name' | 'start_time'>;

export type PlanMergeActivityOutcome = 'add' | 'delete' | 'modify' | 'none';

Expand Down Expand Up @@ -106,6 +106,7 @@ export type PlanSchema = {
collaborators: PlanCollaboratorSlim[];
constraint_specification: ConstraintPlanSpecification[];
created_at: string;
description: string | null;
duration: string;
id: number;
is_locked: boolean;
Expand Down Expand Up @@ -171,6 +172,7 @@ export type PlanMetadata = Pick<
| 'name'
| 'owner'
| 'created_at'
| 'description'
| 'collaborators'
| 'model'
| 'start_time'
Expand All @@ -181,6 +183,7 @@ export type PlanMetadata = Pick<
export type PlanSlim = Pick<
Plan,
| 'created_at'
| 'description'
| 'collaborators'
| 'duration'
| 'end_time_doy'
Expand Down
1 change: 1 addition & 0 deletions src/utilities/activities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ function getTestPlan(): Plan {
collaborators: [],
constraint_specification: [],
created_at: '2006-07-11T00:00:00',
description: null,
duration: '1y',
end_time_doy: '2006-T194:00:00',
id: 1,
Expand Down
41 changes: 41 additions & 0 deletions src/utilities/effects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Plan } from '../types/plan';
import type { SequenceTemplate } from '../types/sequence-template';
import type { ActivityLayerFilter } from '../types/timeline';
import effects, { replacePaths } from './effects';
import gql from './gql';
import * as Modals from './modal';
import * as Requests from './requests';

Expand All @@ -34,6 +35,46 @@ describe('Handle modal and requests in effects', () => {
catchErrorSpy.mockReset();
});

describe('plan description', () => {
it.each(['First line\nSecond line', ''])('persists a new plan description: %j', async description => {
const request = vi.spyOn(Requests, 'reqHasura').mockResolvedValue({
createPlan: { description, id: 42 },
});
vi.spyOn(effects, 'initialSimulationUpdate').mockResolvedValue(true);

const result = await effects.createPlan(
'2024-002T00:00:00',
1,
'Test plan',
'2024-001T00:00:00',
null,
mockUser,
description,
);

expect(request).toHaveBeenCalledWith(
gql.CREATE_PLAN,
{ plan: expect.objectContaining({ description }) },
mockUser,
);
expect(result?.description).toBe(description);
});

it('can clear an existing description', async () => {
const request = vi.spyOn(Requests, 'reqHasura').mockResolvedValue({ updatePlan: { id: 42 } });
const plan = {
collaborators: [],
description: 'Existing description',
id: 42,
name: 'Test plan',
owner: mockUser.id,
} as unknown as Plan;

expect(await effects.updatePlan(plan, { description: '' }, mockUser)).toBe(true);
expect(request).toHaveBeenCalledWith(gql.UPDATE_PLAN, { plan: { description: '' }, plan_id: 42 }, mockUser);
});
});

describe('applyPresetToActivity', () => {
it('should correctly handle null responses', async () => {
vi.spyOn(Requests, 'reqHasura').mockResolvedValue({
Expand Down
4 changes: 4 additions & 0 deletions src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,7 @@ const effects = {
startTimeDoy: string,
simulationTemplateId: number | null,
user: User | null,
description: string = '',
): Promise<PlanSlim | null> {
try {
createPlanErrorStore.set(null);
Expand All @@ -1636,6 +1637,7 @@ const effects = {
creatingPlanStore.set(true);

const planInsertInput: PlanInsertInput = {
description,
duration: getIntervalFromDoyRange(startTimeDoy, endTimeDoy),
model_id: modelId,
name,
Expand All @@ -1653,6 +1655,7 @@ const effects = {
const {
collaborators,
created_at,
description,
duration,
id,
is_read_only,
Expand All @@ -1670,6 +1673,7 @@ const effects = {
const plan: PlanSlim = {
collaborators,
created_at,
description,
duration,
end_time_doy: endTimeDoy,
id,
Expand Down
5 changes: 5 additions & 0 deletions src/utilities/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ const gql = {
CREATE_PLAN: `#graphql
mutation CreatePlan($plan: plan_insert_input!) {
createPlan: ${Queries.INSERT_PLAN}(object: $plan) {
description
created_at
collaborators {
collaborator
Expand Down Expand Up @@ -1360,6 +1361,7 @@ const gql = {
collaborator
}
created_at
description
duration
id
is_locked
Expand Down Expand Up @@ -1495,6 +1497,7 @@ const gql = {
collaborator
}
created_at
description
duration
id
is_read_only
Expand Down Expand Up @@ -2692,6 +2695,7 @@ const gql = {
collaborator
}
created_at
description
duration
id
is_read_only
Expand Down Expand Up @@ -2972,6 +2976,7 @@ const gql = {
id
is_read_only
start_time
description
duration
model: mission_model {
definition_file_id
Expand Down
3 changes: 3 additions & 0 deletions src/utilities/plan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('Plan utility', () => {
collaborators: [],
constraint_specification: [],
created_at: '2024-01-01T00:00:00',
description: null,
duration: '1y',
end_time_doy: '2025-001T00:00:00',
id: 1,
Expand Down Expand Up @@ -229,6 +230,7 @@ describe('Plan utility', () => {
collaborators: [],
constraint_specification: [],
created_at: '2024-01-01T00:00:00',
description: null,
duration: '1y',
end_time_doy: '2025-001T00:00:00',
id: 1,
Expand Down Expand Up @@ -343,6 +345,7 @@ describe('Plan utility', () => {
collaborators: [],
constraint_specification: [],
created_at: '2024-01-01T00:00:00',
description: '',
duration: '1y',
end_time_doy: '2025-001T00:00:00',
id: 1,
Expand Down
Loading