Skip to content

Commit

Permalink
fix: refresh component when field is updated
Browse files Browse the repository at this point in the history
fixes podman-desktop#3524
Signed-off-by: Florent Benoit <[email protected]>
  • Loading branch information
benoitf committed Aug 14, 2023
1 parent 87f9f62 commit 5277096
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
40 changes: 40 additions & 0 deletions packages/renderer/src/lib/ui/AuditMessageBox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,43 @@ test('Should display error message', async () => {
expect(errMessage).toBeInTheDocument();
expect(errMessage).toHaveTextContent('Dummy error message');
});

test('Should update data when audit result is updated', async () => {
const dummyResult = {
records: [
{
type: 'error',
record: 'Dummy error message',
} as AuditRecord,
],
} as AuditResult;
const renderComponent = render(AuditMessageBox, { auditResult: dummyResult });
const errMessage = screen.getByLabelText('error');

expect(errMessage).toBeInTheDocument();
expect(errMessage).toHaveTextContent('Dummy error message');

// now we update the audit result field
renderComponent.component.$set({
auditResult: {
records: [
{
type: 'info',
record: 'Dummy info message',
},
],
},
});

// wait for tick
await new Promise(resolve => setTimeout(resolve, 500));

const afterUpdateError = screen.queryByLabelText('error');
expect(afterUpdateError).not.toBeInTheDocument();

// check the info message now
const infoMessage = screen.getByLabelText('info');

expect(infoMessage).toBeInTheDocument();
expect(infoMessage).toHaveTextContent('Dummy info message');
});
9 changes: 3 additions & 6 deletions packages/renderer/src/lib/ui/AuditMessageBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
import Fa from 'svelte-fa/src/fa.svelte';
import { faTriangleExclamation, faCircleInfo, faXmarkCircle } from '@fortawesome/free-solid-svg-icons';
import type { AuditRecord, AuditResult } from '@podman-desktop/api';
import { onMount } from 'svelte';
export let auditResult: AuditResult;
let infoRecords: AuditRecord[];
let warningRecords: AuditRecord[];
let errorRecords: AuditRecord[];
onMount(async () => {
infoRecords = auditResult?.records.filter(record => record.type === 'info');
warningRecords = auditResult?.records.filter(record => record.type === 'warning');
errorRecords = auditResult?.records.filter(record => record.type === 'error');
});
$: infoRecords = auditResult?.records.filter(record => record.type === 'info');
$: warningRecords = auditResult?.records.filter(record => record.type === 'warning');
$: errorRecords = auditResult?.records.filter(record => record.type === 'error');
</script>

{#if errorRecords && errorRecords.length > 0}
Expand Down

0 comments on commit 5277096

Please sign in to comment.