Skip to content

Commit

Permalink
Errors found in testing fix -2
Browse files Browse the repository at this point in the history
  • Loading branch information
seenanair committed Sep 11, 2023
1 parent 03a14fb commit f4239a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions cypress/e2e/pages/store.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Store', () => {
)
);
});
cy.visit('/locations/STO-001');
cy.visit('/locations/STO-014');
});
it('should display transfer items option', () => {
cy.findByText('Transfer items from location').should('be.visible');
Expand All @@ -147,18 +147,18 @@ describe('Store', () => {
const location = locationRepository.findByBarcode(req.variables.barcode);
return res.once(
ctx.data({
location: { ...locationResponse(location!), customName: 'STO-002 location' }
location: { ...locationResponse(location!), customName: 'STO-014 location' }
})
);
}
)
);
});
cy.get('[id=source_barcode]').type('STO-002{enter}');
cy.get('[id=source_barcode]').type('STO-014{enter}');
});

it('should display description', () => {
cy.findByTestId('transfer-source-description').should('contain.text', 'STO-002 location');
cy.findByTestId('transfer-source-description').should('contain.text', 'STO-014 location');
});
context('Error on transfer', () => {
before(() => {
Expand Down Expand Up @@ -190,7 +190,7 @@ describe('Store', () => {
context('On successful transfer', () => {
before(() => {
cy.msw().then(({ worker, graphql }) => {
const location = locationRepository.findByBarcode('STO-002');
const location = locationRepository.findByBarcode('STO-014');
worker.use(
graphql.mutation<TransferLocationItemsMutation, TransferLocationItemsMutationVariables>(
'TransferLocationItems',
Expand All @@ -214,7 +214,7 @@ describe('Store', () => {
cy.findByRole('button', { name: 'Transfer' }).click();
});
it('should display success message', () => {
cy.contains('All items transferred from STO-002').should('be.visible');
cy.contains('All items transferred from STO-014').should('be.visible');
});
it('should display transferred items', () => {
cy.findByText('STAN-1011').should('be.visible');
Expand Down
7 changes: 6 additions & 1 deletion src/lib/machines/locations/locationMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import * as locationService from '../../services/locationService';
import { MachineConfig } from 'xstate/lib/types';
import { castDraft } from 'immer';
import { stanCore } from '../../sdk';
import { findNextAvailableAddress } from '../../helpers/locationHelper';
import { buildOrderedAddresses, findNextAvailableAddress } from '../../helpers/locationHelper';
import { GridDirection } from '../../../types/sdk';

enum Action {
ASSIGN_LOCATION = 'assignLocation',
Expand Down Expand Up @@ -63,6 +64,10 @@ export const machineOptions: Partial<MachineOptions<LocationContext, LocationEve
ctx.location = e.type === 'UPDATE_LOCATION' ? e.location : e.data;

ctx.addressToItemMap.clear();
// Create all the possible addresses for this location if it has a size.
ctx.locationAddresses = ctx.location.size
? buildOrderedAddresses(ctx.location.size, ctx.location.direction ?? GridDirection.DownRight)
: new Map<string, number>();

ctx.location.stored.forEach((storedItem) => {
if (storedItem.address) {
Expand Down
19 changes: 7 additions & 12 deletions src/pages/Location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import PasteIcon from '../components/icons/PasteIcon';
import BlueButton from '../components/buttons/BlueButton';
import { ClientError } from 'graphql-request';
import { stanCore } from '../lib/sdk';
import { useLoaderData, useLocation } from 'react-router-dom';
import { useLoaderData, useSearchParams } from 'react-router-dom';

/**
* The different ways of displaying stored items
Expand All @@ -64,13 +64,8 @@ export const LocationParentContext = React.createContext<Maybe<LocationParentCon

const Location = () => {
const storageLocation = useLoaderData() as LocationFieldsFragment;

const locationVal = useLocation();

React.useEffect(() => {
console.log(locationVal.pathname);
}, [locationVal]);

const [searchParams] = useSearchParams();
const memoLabwareBarcode = React.useMemo(() => searchParams.get('labwareBarcode') ?? '', [searchParams]);
const memoLocationMachine = React.useMemo(() => {
// Create all the possible addresses for this location if it has a size.
const locationAddresses: Map<string, number> = storageLocation.size
Expand All @@ -94,15 +89,15 @@ const Location = () => {
const selectedAddress = selectedAddresses.length > 0 ? selectedAddresses[0] : null;
return locationMachine.withContext({
location: storageLocation,
locationSearchParams: { labwareBarcode: storageLocation.barcode },
locationSearchParams: { labwareBarcode: memoLabwareBarcode },
locationAddresses,
addressToItemMap,
selectedAddress,
successMessage: '',
errorMessage: '',
serverError: null
});
}, [storageLocation]);
}, [storageLocation, memoLabwareBarcode]);

//Custom hook to retain the updated labware state
const [current, send] = useMachine(() => memoLocationMachine);
Expand Down Expand Up @@ -270,12 +265,12 @@ const Location = () => {
const labwareBarcodeToAddressMap: Map<string, string> = useMemo(() => {
const map = new Map<string, string>();
for (const item of location.stored) {
if (item.address && item.barcode === storageLocation.barcode) {
if (item.address && item.barcode === memoLabwareBarcode) {
map.set(item.barcode, item.address);
}
}
return map;
}, [location, storageLocation.barcode]);
}, [location, memoLabwareBarcode]);

const locationParentContext: LocationParentContextType = useMemo(
() => ({
Expand Down

0 comments on commit f4239a0

Please sign in to comment.