Skip to content

Commit

Permalink
Make seqset tests more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusroemer committed May 12, 2024
1 parent e88c9f2 commit 791deac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 9 additions & 3 deletions website/src/components/SeqSetCitations/SeqSetItemActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type FC, useState } from 'react';
import { type FC, useState, useEffect } from 'react';

import { ExportSeqSet } from './ExportSeqSet';
import { SeqSetForm } from './SeqSetForm';
Expand Down Expand Up @@ -32,6 +32,11 @@ const SeqSetItemActionsInner: FC<SeqSetItemActionsProps> = ({
const [editModalVisible, setEditModalVisible] = useState(false);
const [exportModalVisible, setExportModalVisible] = useState(false);
const { errorMessage, isErrorOpen, openErrorFeedback, closeErrorFeedback } = useErrorFeedbackState();
const [isClient, setIsClient] = useState(false);

useEffect(() => {
setIsClient(true);
}, []);

const { mutate: deleteSeqSet } = useDeleteSeqSetAction(
clientConfig,
Expand All @@ -51,13 +56,13 @@ const SeqSetItemActionsInner: FC<SeqSetItemActionsProps> = ({
<div className='flex-row items-center justify-between w-full'>
<div className='flex justify-start items-center pt-4 pb-8'>
<div className='pr-2'>
<button className='btn' onClick={() => setExportModalVisible(true)}>
<button className='btn' onClick={() => setExportModalVisible(true)} disabled={!isClient}>
Export
</button>
</div>
<div className='px-2'>
{isAdminView ? (
<button className='btn' onClick={() => setEditModalVisible(true)}>
<button className='btn' onClick={() => setEditModalVisible(true)} disabled={!isClient}>
Edit
</button>
) : null}
Expand All @@ -72,6 +77,7 @@ const SeqSetItemActionsInner: FC<SeqSetItemActionsProps> = ({
onConfirmation: handleDeleteSeqSet,
})
}
disabled={!isClient}
>
Delete
</button>
Expand Down
8 changes: 7 additions & 1 deletion website/src/components/SeqSetCitations/SeqSetList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MUIPagination from '@mui/material/Pagination';
import { type FC, type MouseEvent, useState, useMemo } from 'react';
import { type FC, type MouseEvent, useState, useMemo, useEffect } from 'react';

import { routes } from '../../routes/routes';
import type { SeqSet } from '../../types/seqSetCitation';
Expand Down Expand Up @@ -85,8 +85,13 @@ export const SeqSetList: FC<SeqSetListProps> = ({ seqSets, username }) => {
const [order, setOrder] = useState<Order>('desc');
const [orderBy, setOrderBy] = useState<keyof SeqSet>('createdAt');
const [page, setPage] = useState(1);
const [isClient, setIsClient] = useState(false);
const rowsPerPage = 5;

useEffect(() => {
setIsClient(true);
}, []);

const handleRequestSort = (_: MouseEvent<unknown>, property: keyof SeqSet) => {
const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc');
Expand Down Expand Up @@ -174,6 +179,7 @@ export const SeqSetList: FC<SeqSetListProps> = ({ seqSets, username }) => {
className='hover:bg-primary-100 border-gray-100 cursor-pointer'
onClick={(event) => handleClick(event, row.seqSetId, row.seqSetVersion.toString())}
key={row.seqSetId}
data-testid={isClient ? row.name : 'disabled'}
>
<td className='px-2 whitespace-nowrap text-primary-900 pl-6'>
{formatDate(row.createdAt)}
Expand Down
2 changes: 1 addition & 1 deletion website/tests/pages/seqsets/seqset.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class SeqSetPage {

public async gotoDetail(seqSetName: string = testSeqSet.name) {
await this.gotoList();
await this.page.getByText(seqSetName).first().click();
await this.page.getByTestId(seqSetName).first().click();
await this.page.waitForLoadState();
}

Expand Down

0 comments on commit 791deac

Please sign in to comment.