Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage statues of moving items #456 #472

Merged
merged 33 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1bfc460
usage statues of moving items #456
joshuadkitenge Apr 2, 2024
51dbc69
clear aggregatedCell status if a nested status is changed
joshuadkitenge Apr 2, 2024
7c1743a
remove useRef
joshuadkitenge Apr 2, 2024
2488f8d
update the api hook to include usage status
joshuadkitenge Apr 2, 2024
4641d42
clear usestates onclose
joshuadkitenge Apr 2, 2024
6fbd13e
move to item unit test
joshuadkitenge Apr 2, 2024
92d567b
unit tests for systemitemstable
joshuadkitenge Apr 3, 2024
d28abee
improve coverage
joshuadkitenge Apr 3, 2024
c44354f
Merge branch 'develop' into usage-statues-of-moving-items-#456
joshuadkitenge Apr 3, 2024
9a5eaad
Merge branch 'develop' into usage-statues-of-moving-items-#456
joshuadkitenge Apr 3, 2024
6dd190c
add test to systemsitemsdialog
joshuadkitenge Apr 3, 2024
fb7eb4f
e2e test with mock data
joshuadkitenge Apr 3, 2024
80016d9
remove .only
joshuadkitenge Apr 3, 2024
9f2c294
fix e2e with api
joshuadkitenge Apr 4, 2024
931b073
debug for e2e tests
joshuadkitenge Apr 4, 2024
909cd5d
fix e2e test with api
joshuadkitenge Apr 4, 2024
0ef1be2
Update src/systems/systemItemsDialog.component.tsx
joshuadkitenge Apr 5, 2024
28ab3bf
Update src/systems/systemItemsDialog.component.test.tsx
joshuadkitenge Apr 5, 2024
b69313c
Update src/api/items.test.tsx
joshuadkitenge Apr 5, 2024
9eaa546
Update src/systems/systemItemsTable.component.tsx
joshuadkitenge Apr 5, 2024
16a520f
Update src/systems/systemItemsDialog.component.tsx
joshuadkitenge Apr 5, 2024
fa14210
Update src/systems/systemItemsDialog.component.tsx
joshuadkitenge Apr 5, 2024
11fc865
fix failing e2e and unit tests
joshuadkitenge Apr 8, 2024
cf2dbcb
fix spelling error Statues to Statuses
joshuadkitenge Apr 8, 2024
873e0ba
fix spelling error
joshuadkitenge Apr 8, 2024
6a44a65
update dependency array
joshuadkitenge Apr 8, 2024
eb15fa8
remove useEffect
joshuadkitenge Apr 8, 2024
99695be
fix flaky e2e tests. the check has been moved to the Finish button
joshuadkitenge Apr 8, 2024
78aa635
Merge branch 'develop' into usage-statues-of-moving-items-#456
joshuadkitenge Apr 8, 2024
52d8c75
Change notification to use the serial number instead of database id
joshuadkitenge Apr 9, 2024
0c8522e
address review comments
joshuadkitenge Apr 9, 2024
354da7b
Merge branch 'develop' into usage-statues-of-moving-items-#456
joshuadkitenge Apr 9, 2024
4cb9156
fix unit tests
joshuadkitenge Apr 9, 2024
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
17 changes: 15 additions & 2 deletions cypress/e2e/with_api/systems/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,21 @@ export const moveItemToSystem = (values: {
cy.findByText('Storage 2').click();
});

cy.findByRole('button', { name: 'Move here' }).should('not.be.disabled');
cy.findByRole('button', { name: 'Move here' }).click();
cy.findByRole('button', { name: 'Next' }).should('not.be.disabled');
cy.findByRole('button', { name: 'Next' }).click();

cy.findByRole('cell', {
name: `Plano-Convex Lens (1)`,
}).should('exist');

cy.findByRole('progressbar').should('not.exist');

cy.findAllByRole('combobox').eq(1).click();
cy.findByText('Scrapped').click();

cy.findByRole('button', { name: 'Finish' }).should('not.be.disabled');
cy.findByRole('button', { name: 'Finish' }).click();

cy.findByRole('dialog').should('not.exist', { timeout: 10000 });

cy.findByRole('button', { name: 'navigate to systems home' }).click();
Expand Down
145 changes: 107 additions & 38 deletions cypress/e2e/with_mock_data/systems.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,54 +765,123 @@ describe('Systems', () => {
);
});
});
describe('Move', () => {
it('moves items', () => {
cy.findByRole('cell', { name: 'Pulse Laser' }).click();
cy.findAllByRole('button', { name: 'Expand' }).eq(1).click();

// Second table, first checkbox
cy.findAllByRole('table')
.eq(1)
.within(() => {
cy.findAllByRole('checkbox', {
name: 'Toggle select row',
})
.eq(1)
.click();
cy.findAllByRole('checkbox', {
name: 'Toggle select row',
})
.eq(2)
.click();
});

it('moves items', () => {
cy.findByRole('cell', { name: 'Pulse Laser' }).click();
cy.findAllByRole('button', { name: 'Expand' }).eq(1).click();
cy.findByRole('button', { name: 'Move to' }).click();

// Second table, first checkbox
cy.findAllByRole('table')
.eq(1)
.within(() => {
cy.findAllByRole('checkbox', {
name: 'Toggle select row',
})
.eq(1)
.click();
cy.findAllByRole('checkbox', {
name: 'Toggle select row',
})
.eq(2)
.click();
});
cy.startSnoopingBrowserMockedRequest();

cy.findByRole('button', { name: 'Move to' }).click();
cy.findByRole('dialog')
.should('be.visible')
.within(() => {
cy.findByRole('button', { name: 'navigate to systems home' }).click();
cy.findByLabelText('Giant laser row').click();
cy.findByRole('button', { name: 'Next' }).click();
});

cy.startSnoopingBrowserMockedRequest();
cy.findAllByRole('combobox').eq(1).click();
cy.findByText('Scrapped').click();

cy.findByRole('dialog')
.should('be.visible')
.within(() => {
cy.findByRole('button', { name: 'navigate to systems home' }).click();
cy.findByLabelText('Giant laser row').click();
cy.findByRole('button', { name: 'Move here' }).click();
cy.findByRole('button', { name: 'Finish' }).click();

cy.findByRole('dialog').should('not.exist');

cy.findBrowserMockedRequests({
method: 'PATCH',
url: '/v1/items/:id',
}).should(async (patchRequests) => {
expect(patchRequests.length).eq(2);
expect(patchRequests[0].url.toString()).to.contain('/z1hJvV8Z');
expect(JSON.stringify(await patchRequests[0].json())).equal(
JSON.stringify({
system_id: '65328f34a40ff5301575a4e3',
usage_status: 3,
})
);
expect(patchRequests[1].url.toString()).to.contain('/4mYoI7pr');
expect(JSON.stringify(await patchRequests[1].json())).equal(
JSON.stringify({
system_id: '65328f34a40ff5301575a4e3',
usage_status: 3,
})
);
});
});

cy.findByRole('dialog').should('not.exist');
it('display errors message and clears error message when resolved', () => {
cy.findByRole('cell', { name: 'Pulse Laser' }).click();
cy.findAllByRole('button', { name: 'Expand' }).eq(1).click();

cy.findBrowserMockedRequests({
method: 'PATCH',
url: '/v1/items/:id',
}).should(async (patchRequests) => {
expect(patchRequests.length).eq(2);
expect(patchRequests[0].url.toString()).to.contain('/z1hJvV8Z');
expect(JSON.stringify(await patchRequests[0].json())).equal(
JSON.stringify({ system_id: '65328f34a40ff5301575a4e3' })
// Second table, first checkbox
cy.findAllByRole('table')
.eq(1)
.within(() => {
cy.findAllByRole('checkbox', {
name: 'Toggle select row',
})
.eq(1)
.click();
cy.findAllByRole('checkbox', {
name: 'Toggle select row',
})
.eq(2)
.click();
});

cy.findByRole('button', { name: 'Move to' }).click();

cy.findByText('Set usage statuses').click();
cy.findByRole('button', { name: 'Finish' }).click();

cy.findByText(
'Move items from current location or root to another system'
).should('exist');
cy.findByText('Please select a usage status for all items').should(
'exist'
);
expect(patchRequests[1].url.toString()).to.contain('/4mYoI7pr');
expect(JSON.stringify(await patchRequests[1].json())).equal(
JSON.stringify({ system_id: '65328f34a40ff5301575a4e3' })
cy.findAllByLabelText('Expand all').eq(2).click();
cy.findAllByText('Please select a usage status').should('have.length', 2);
cy.findAllByRole('combobox').eq(1).click();
cy.findByText('Scrapped').click();
cy.findAllByText('Please select a usage status').should('have.length', 0);
cy.findByText('Please select a usage status for all items').should(
'not.exist'
);
cy.findByText('Place into a system').click();
cy.findByRole('button', { name: 'navigate to systems home' }).click();
cy.findByText(
'Move items from current location or root to another system'
).should('not.exist');
cy.findByRole('button', { name: 'Next' }).click();
cy.findByText(
'Move items from current location or root to another system'
).should('exist');

cy.findByText('Pico Laser').click();
cy.findByRole('button', { name: 'Next' }).click();
cy.findByText(
'Move items from current location or root to another system'
).should('not.exist');
cy.findByRole('button', { name: 'Finish' }).should('not.be.disabled');
});
});
});
26 changes: 22 additions & 4 deletions src/api/items.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EditItem,
Item,
MoveItemsToSystem,
MoveItemsToSystemUsageStatus,
System,
} from '../app.types';
import SystemsJSON from '../mocks/Systems.json';
Expand Down Expand Up @@ -208,6 +209,11 @@ describe('items api functions', () => {
getItemById('G463gOIA'),
];

const mockUsageStatuses: MoveItemsToSystemUsageStatus[] = [
{ item_id: 'KvT2Ox7n', usage_status: 0 },
{ item_id: 'G463gOIA', usage_status: 0 },
];

let moveItemsToSystem: MoveItemsToSystem;

// Use patch spy for testing since response is not actual data in this case
Expand All @@ -216,7 +222,8 @@ describe('items api functions', () => {

beforeEach(() => {
moveItemsToSystem = {
// Prevent test interference if modifying the selected items
// Prevent test interference if modifying the usage statuses or selected items
usageStatuses: JSON.parse(JSON.stringify(mockUsageStatuses)),
selectedItems: JSON.parse(JSON.stringify(mockItems)),
targetSystem: SystemsJSON[0] as System,
};
Expand All @@ -243,12 +250,15 @@ describe('items api functions', () => {
moveItemsToSystem.selectedItems.map((item) =>
expect(axiosPatchSpy).toHaveBeenCalledWith(`/v1/items/${item.id}`, {
system_id: moveItemsToSystem.targetSystem.id,
usage_status: moveItemsToSystem.usageStatuses.find(
(status) => status.item_id === item.id
)?.usage_status,
})
);
expect(result.current.data).toEqual(
moveItemsToSystem.selectedItems.map((item) => ({
message: `Successfully moved to Giant laser`,
name: item.id,
name: item.serial_number,
state: 'success',
}))
);
Expand All @@ -260,9 +270,14 @@ describe('items api functions', () => {
name: 'New system name',
id: 'new_system_id',
};
moveItemsToSystem.usageStatuses = [
...moveItemsToSystem.usageStatuses,
{ item_id: 'Error 409', usage_status: 2 },
];

// Fail just the 1st system
moveItemsToSystem.selectedItems[0].id = 'Error 409';
moveItemsToSystem.selectedItems[0].serial_number = null;

const { result } = renderHook(() => useMoveItemsToSystem(), {
wrapper: hooksWrapperWithProviders(),
Expand All @@ -278,6 +293,9 @@ describe('items api functions', () => {
moveItemsToSystem.selectedItems.map((item) =>
expect(axiosPatchSpy).toHaveBeenCalledWith(`/v1/items/${item.id}`, {
system_id: 'new_system_id',
usage_status: moveItemsToSystem.usageStatuses.find(
(status) => status.item_id === item.id
)?.usage_status,
})
);
expect(result.current.data).toEqual(
Expand All @@ -286,12 +304,12 @@ describe('items api functions', () => {
index === 0
? {
message: 'The specified system ID does not exist',
name: item.id,
name: item.serial_number ?? 'No serial number',
state: 'error',
}
: {
message: 'Successfully moved to New system name',
name: item.id,
name: item.serial_number,
state: 'success',
}
)
Expand Down
7 changes: 5 additions & 2 deletions src/api/items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,16 @@ export const useMoveItemsToSystem = (): UseMutationResult<
return editItem({
id: item.id,
system_id: moveItemsToSystem.targetSystem?.id || '',
usage_status: moveItemsToSystem.usageStatuses.find(
(status) => status.item_id === item.id
)?.usage_status,
})
.then((result: Item) => {
const targetSystemName =
moveItemsToSystem.targetSystem?.name || 'Root';
transferStates.push({
// Not technically a name, but will be displayed as ID: Message
name: item.id,
name: item.serial_number ?? 'No serial number',
message: `Successfully moved to ${targetSystemName}`,
state: 'success',
});
Expand All @@ -238,7 +241,7 @@ export const useMoveItemsToSystem = (): UseMutationResult<
const response = error.response?.data as ErrorParsing;

transferStates.push({
name: item.id,
name: item.serial_number ?? 'No serial number',
message: response.detail,
state: 'error',
});
Expand Down
5 changes: 5 additions & 0 deletions src/app.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ export interface EditItem extends Partial<AddItem> {
id: string;
}

export interface MoveItemsToSystemUsageStatus {
item_id: string;
usage_status: UsageStatusType;
}
export interface MoveItemsToSystem {
usageStatuses: MoveItemsToSystemUsageStatus[];
selectedItems: Item[];
targetSystem: System;
}
Expand Down
Loading