Skip to content

Commit

Permalink
merge develop #1040
Browse files Browse the repository at this point in the history
  • Loading branch information
asuresh-code committed Nov 5, 2024
1 parent 6769b76 commit 28a6383
Show file tree
Hide file tree
Showing 39 changed files with 1,096 additions and 221 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Setup Node.js
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
node-version: 20
cache: 'yarn'
Expand Down Expand Up @@ -45,10 +45,10 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Setup Node.js
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
node-version: 20
cache: 'yarn'
Expand All @@ -74,13 +74,13 @@ jobs:

steps:
- name: Clone api repo
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
repository: ral-facilities/inventory-management-system-api
ref: develop

- name: Set up Python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: '3.12'

Expand Down Expand Up @@ -120,10 +120,10 @@ jobs:
harbor.stfc.ac.uk/inventory-management-system/ims-api:develop
- name: Checkout repo
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Setup Node.js
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
node-version: 20
cache: 'yarn'
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Login to Harbor
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Login to Harbor
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
Expand Down
15 changes: 15 additions & 0 deletions cypress/e2e/with_api/catalogueItems/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const modifyCatalogueItem = (
costToReworkGbp?: string;
daysToReplace: string;
daysToRework?: string;
expectedLifetimeDays?: string;
drawingNumber?: string;
drawingLink?: string;
itemModelNumber?: string;
Expand Down Expand Up @@ -62,6 +63,15 @@ const modifyCatalogueItem = (
cy.findByLabelText('Time to rework (days)').clear();
}

if (values.expectedLifetimeDays) {
cy.findByLabelText('Expected Lifetime (days)').clear();
cy.findByLabelText('Expected Lifetime (days)').type(
values.expectedLifetimeDays
);
} else {
cy.findByLabelText('Expected Lifetime (days)').clear();
}

if (values.drawingNumber) {
cy.findByLabelText('Drawing number').clear();
cy.findByLabelText('Drawing number').type(values.drawingNumber);
Expand Down Expand Up @@ -139,6 +149,9 @@ const modifyCatalogueItem = (

if (values.daysToRework) cy.findByText(values.daysToRework).should('exist');

if (values.expectedLifetimeDays)
cy.findByText(values.expectedLifetimeDays).should('exist');

if (values.drawingNumber)
cy.findByText(values.drawingNumber).should('exist');

Expand Down Expand Up @@ -297,6 +310,7 @@ export const addCatalogueItem = (ignoreChecks?: boolean) => {
costToReworkGbp: '20',
daysToReplace: '5',
daysToRework: '1',
expectedLifetimeDays: '365',
drawingLink: 'https://example.com/',
drawingNumber: 'GH45235324',
itemModelNumber: 'rew5435453',
Expand All @@ -319,6 +333,7 @@ export const editCatalogueItem = () => {
costGbp: '43.95',
costToReworkGbp: '20',
daysToReplace: '5',
expectedLifetimeDays: '365',
drawingLink: 'https://example.com/',
drawingNumber: 'GH4523566324',
itemModelNumber: 'rew54359453',
Expand Down
16 changes: 15 additions & 1 deletion cypress/e2e/with_mock_data/catalogueItems.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Catalogue Items', () => {
cy.findByLabelText('Cost to rework (£)').type('400');
cy.findByLabelText('Time to replace (days) *').type('14');
cy.findByLabelText('Time to rework (days)').type('5');
cy.findByLabelText('Expected Lifetime (days)').type('345');
cy.findByLabelText('Drawing number').type('MX43242');
cy.findByLabelText('Drawing link').type('https://example.com');
cy.findByLabelText('Model number').type('MXtest');
Expand Down Expand Up @@ -56,6 +57,7 @@ describe('Catalogue Items', () => {
cost_to_rework_gbp: 400,
days_to_replace: 14,
days_to_rework: 5,
expected_lifetime_days: 345,
drawing_number: 'MX43242',
drawing_link: 'https://example.com',
item_model_number: 'MXtest',
Expand Down Expand Up @@ -104,6 +106,7 @@ describe('Catalogue Items', () => {
cost_to_rework_gbp: 89,
days_to_replace: 7,
days_to_rework: 60,
expected_lifetime_days: 3635,
drawing_number: null,
drawing_link: null,
item_model_number: null,
Expand Down Expand Up @@ -165,6 +168,7 @@ describe('Catalogue Items', () => {
cost_to_rework_gbp: null,
days_to_replace: 14,
days_to_rework: null,
expected_lifetime_days: null,
drawing_number: null,
drawing_link: null,
item_model_number: null,
Expand Down Expand Up @@ -231,6 +235,7 @@ describe('Catalogue Items', () => {
cost_to_rework_gbp: null,
days_to_replace: 14,
days_to_rework: null,
expected_lifetime_days: null,
drawing_number: null,
drawing_link: null,
item_model_number: null,
Expand Down Expand Up @@ -314,11 +319,13 @@ describe('Catalogue Items', () => {
cy.findByLabelText('Time to replace (days) *').clear();
cy.findByLabelText('Cost (£) *').type('gfdg');
cy.findByLabelText('Time to replace (days) *').type('32gf');
cy.findByLabelText('Expected Lifetime (days)').clear();
cy.findByLabelText('Drawing link').type('test.co.uk');
cy.findByLabelText('Expected Lifetime (days)').type('friday');

cy.findAllByText('Please enter a valid number.').should(
'have.length',
2
3
);
cy.findAllByText(
'Please enter a valid Drawing link. Only "http://" and "https://" links with typical top-level domain are accepted.'
Expand All @@ -330,6 +337,8 @@ describe('Catalogue Items', () => {
cy.findByLabelText('Time to replace (days) *').type('14');
cy.findByLabelText('Drawing link').clear();
cy.findByLabelText('Drawing link').type('https://test.co.uk');
cy.findByLabelText('Expected Lifetime (days)').clear();
cy.findByLabelText('Expected Lifetime (days)').type('200');

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

Expand Down Expand Up @@ -579,6 +588,8 @@ describe('Catalogue Items', () => {
cy.findByLabelText('Cost to rework (£)').type('4');
cy.findByLabelText('Time to replace (days) *').type('1');
cy.findByLabelText('Time to rework (days)').type('5');
cy.findByLabelText('Expected Lifetime (days)').clear();
cy.findByLabelText('Expected Lifetime (days)').type('345');
cy.findByLabelText('Drawing number').type('MX43242');
cy.findByLabelText('Drawing link').type('https://example.com');
cy.findByLabelText('Model number').type('MXtest');
Expand Down Expand Up @@ -609,6 +620,7 @@ describe('Catalogue Items', () => {
cost_to_rework_gbp: 894,
days_to_replace: 71,
days_to_rework: 605,
expected_lifetime_days: 345,
drawing_number: 'MX43242',
drawing_link: 'https://example.com',
item_model_number: 'MXtest',
Expand Down Expand Up @@ -1016,6 +1028,7 @@ describe('Catalogue Items', () => {
cost_to_rework_gbp: null,
days_to_replace: 7,
days_to_rework: null,
expected_lifetime_days: 3124,
drawing_number: null,
drawing_link: 'http://example-drawing-link.com',
item_model_number: null,
Expand All @@ -1042,6 +1055,7 @@ describe('Catalogue Items', () => {
cost_to_rework_gbp: 89,
days_to_replace: 7,
days_to_rework: 60,
expected_lifetime_days: 3635,
drawing_number: null,
drawing_link: null,
item_model_number: null,
Expand Down
101 changes: 99 additions & 2 deletions cypress/e2e/with_mock_data/items.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,10 @@ describe('Items', () => {
expect(postRequests.length).eq(1);
});

// Click the "Remove file" button
cy.findByRole('button', { name: 'Remove file' }).click();

//TODO: Assert axios delete request was called

// Assert that the text "Upload 1 file" is not in the document
cy.findByText('Upload 1 file').should('not.exist');
});

Expand Down Expand Up @@ -604,6 +602,105 @@ describe('Items', () => {
});
});

describe('Images', () => {
afterEach(() => {
cy.clearMocks();
});

it('uploads images', () => {
cy.findByText('5YUQDDjKpz2z').click();
cy.findByText(
'High-resolution cameras for beam characterization. 1'
).should('exist');
cy.findByRole('button', {
name: 'items landing page actions menu',
}).click();
cy.findByText('Upload Images').click();

cy.findAllByText('Files cannot be larger than', { exact: false }).should(
'exist'
);
cy.get('.uppy-Dashboard-input').as('fileInput');

cy.get('@fileInput')
.last()
.selectFile(
[
'cypress/fixtures/images/logo1.png',
'cypress/fixtures/images/logo2.png',
],
{ force: true }
);

cy.findByRole('button', { name: 'Edit file logo1.png' }).click();

cy.findByText('File name').should('be.visible');

cy.findByPlaceholderText('Enter file title').type('test');
cy.findByPlaceholderText('Enter file description').type('test');

cy.findByText('Save changes').click();

cy.startSnoopingBrowserMockedRequest();
cy.findByText('Upload 2 files').click();

cy.findBrowserMockedRequests({
method: 'POST',
url: '/images',
}).should(async (postRequests: Request[]) => {
expect(postRequests.length).eq(2);
});
cy.findByText('Complete').should('exist');
});

it('displays error if post is unsuccessful', () => {
cy.window().its('msw').should('not.equal', undefined);
cy.window().then((window) => {
const { worker, http } = window.msw;

worker.use(
http.post('/images', async () => {
return HttpResponse.error();
})
);
});
cy.findByText('5YUQDDjKpz2z').click();
cy.findByText(
'High-resolution cameras for beam characterization. 1'
).should('exist');
cy.findByRole('button', {
name: 'items landing page actions menu',
}).click();
cy.findByText('Upload Images').click();

cy.findAllByText('Files cannot be larger than', { exact: false }).should(
'exist'
);
cy.get('.uppy-Dashboard-input').as('fileInput');

cy.get('@fileInput')
.last()
.selectFile(
[
'cypress/fixtures/images/logo1.png',
'cypress/fixtures/images/logo2.png',
],
{ force: true }
);
cy.startSnoopingBrowserMockedRequest();
cy.findByText('Upload 2 files').click();

cy.findBrowserMockedRequests({
method: 'POST',
url: '/images',
}).should(async (postRequests: Request[]) => {
expect(postRequests.length).eq(2);
});

cy.findByText('Upload failed').should('exist');
});
});

it('delete an item', () => {
cy.findAllByLabelText('Row Actions').first().click();
cy.findByText('Delete').click();
Expand Down
Binary file added cypress/fixtures/images/logo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cypress/fixtures/images/logo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"@uppy/dashboard": "^4.1.0",
"@uppy/drag-drop": "^4.0.2",
"@uppy/file-input": "^4.0.1",
"@uppy/image-editor": "^3.1.0",
"@uppy/progress-bar": "^4.0.0",
"@uppy/react": "^4.0.2",
"@uppy/xhr-upload": "^4.2.0",
"@vitejs/plugin-react": "^4.3.0",
"axios": "^1.7.2",
"blob-polyfill": "^9.0.20240710",
Expand All @@ -41,7 +43,7 @@
"react-hook-form": "^7.52.0",
"react-redux": "^9.1.2",
"react-router-dom": "^6.23.1",
"single-spa-react": "5.1.4",
"single-spa-react": "6.0.2",
"typescript": "^5.4.5",
"uuid": "^10.0.0",
"vite": "^5.2.12",
Expand Down Expand Up @@ -100,9 +102,9 @@
"eslint-plugin-react": "7.37.1",
"eslint-plugin-react-hooks": "5.0.0",
"eslint-plugin-testing-library": "6.4.0",
"express": "4.21.0",
"express": "4.21.1",
"globals": "15.11.0",
"jsdom": "25.0.0",
"jsdom": "25.0.1",
"prettier": "3.3.3",
"serve": "14.2.3",
"serve-static": "1.16.2",
Expand Down
Loading

0 comments on commit 28a6383

Please sign in to comment.