Skip to content

Commit

Permalink
feat: refactoring renaming planters to growers (#163)
Browse files Browse the repository at this point in the history
* feat: refactoring renaming planters to growers

* feat: refactoring renaming planters to growers

* feat: refactoring renaming planters to growers

* feat: refactoring renaming planters to growers

* fix: resolves test verify errors

* feat: change file name planter to grower

* refactor: update remaining planter references

Co-authored-by: Nick Charlton <[email protected]>
  • Loading branch information
tranquanghuy0801 and nmcharlton authored Oct 1, 2021
1 parent 318c332 commit 190ea83
Show file tree
Hide file tree
Showing 31 changed files with 542 additions and 583 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import { Provider } from 'react-redux';
import theme from '../../src/components/common/theme';
import { ThemeProvider } from '@material-ui/core/styles';
import { init } from '@rematch/core';
import api from '../../src/api/planters';
import api from '../../src/api/growers';

import EditPlanter from '../../src/components/EditPlanter';
import EditGrower from '../../src/components/EditGrower';

describe('EditPlanter', () => {
describe('EditGrower', () => {
let store;

beforeEach(() => {
store = init({
models: {
planters: {
growers: {
state: {},
effects: {
updatePlanter(_payload, _state) {},
updateGrower(_payload, _state) {},
},
},
organizations: {
Expand All @@ -42,15 +42,15 @@ describe('EditPlanter', () => {
mount(
<Provider store={store}>
<ThemeProvider theme={theme}>
<EditPlanter planter={{}} isOpen={true} onClose={() => {}} />
<EditGrower grower={{}} isOpen={true} onClose={() => {}} />
</ThemeProvider>
</Provider>,
);
cy.contains(/Edit Planter/i);
cy.contains(/Edit Grower/i);
});

describe('with valid planter', () => {
const planter = {
describe('with valid grower', () => {
const grower = {
id: 12345,
imageUrl:
'https://greenstand.org/fileadmin/_processed_/f/e/csm_MVIMG_20200303_103438_be16bc7f80.jpg',
Expand All @@ -60,40 +60,40 @@ describe('EditPlanter', () => {
phone: '+1234567890',
};

let planterSelfies;
let growerSelfies;

beforeEach(() => {
planterSelfies = [
growerSelfies = [
'https://greenstand.org/fileadmin/_processed_/d/4/csm_little_Jony_bdf756638d.jpg',
'https://greenstand.org/fileadmin/_processed_/9/f/csm_2019.08.12.09.54.39_1ca43554-b139-4ae2-bbc9-c9a37c43e645_IMG_20190812_093641_-1471408775_0bb24d7c21.jpg',
'https://greenstand.org/fileadmin/_processed_/e/3/csm_IMG_0017_3c859de144.jpg',
'https://greenstand.org/fileadmin/_processed_/9/3/csm_PHOTO-2019-08-05-11-50-37_f0d0281499.jpg',
];

cy.stub(api, 'getPlanterSelfies').returns(planterSelfies);
cy.stub(api, 'getGroerSelfies').returns(growerSelfies);
mount(
<Provider store={store}>
<ThemeProvider theme={theme}>
<EditPlanter planter={planter} isOpen={true} onClose={() => {}} />
<EditGrower grower={grower} isOpen={true} onClose={() => {}} />
</ThemeProvider>
</Provider>,
);
});

it('should display planter details', () => {
cy.get(`[title="${planter.imageUrl}"]`).should(
it('should display grower details', () => {
cy.get(`[title="${grower.imageUrl}"]`).should(
'have.css',
'background-image',
`url("${planter.imageUrl}")`,
`url("${grower.imageUrl}")`,
);
cy.get('input#firstName').should('have.value', planter.firstName);
cy.get('input#lastName').should('have.value', planter.lastName);
cy.get('input#email').should('have.value', planter.email);
cy.get('input#phone').should('have.value', planter.phone);
cy.get('input#firstName').should('have.value', grower.firstName);
cy.get('input#lastName').should('have.value', grower.lastName);
cy.get('input#email').should('have.value', grower.email);
cy.get('input#phone').should('have.value', grower.phone);
});

it('should display all other planter images', () => {
planterSelfies.forEach((img) => {
it('should display all other grower images', () => {
growerSelfies.forEach((img) => {
cy.get(`[title="${img}"]`).should(
'have.css',
'background-image',
Expand All @@ -108,12 +108,12 @@ describe('EditPlanter', () => {
cy.get('button#save').should('be.enabled');
});

it('should update the planter when Save is clicked', () => {
cy.spy(store.dispatch.planters, 'updatePlanter');
it('should update the grower when Save is clicked', () => {
cy.spy(store.dispatch.growers, 'updateGrower');
cy.get('input#firstName').type('abc');
cy.get('button#save').then(($button) => {
$button[0].click();
expect(store.dispatch.planters.updatePlanter).to.be.called;
expect(store.dispatch.growers.updateGrower).to.be.called;
});
});
});
Expand Down
11 changes: 11 additions & 0 deletions cypress/component/grower.spec.py.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { mount } from 'cypress-react-unit-test';
import React from 'react';
import { Grower } from '../../src/components/Growers.js';

describe('HelloWorld component', () => {
it('works', () => {
mount(<Grower grower={{}} />);
// now use standard Cypress commands
cy.contains('ID').should('be.visible');
});
});
11 changes: 0 additions & 11 deletions cypress/component/planter.spec.py.js

This file was deleted.

4 changes: 2 additions & 2 deletions cypress/integration/admin.spec.py.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Admin', () => {
cy.contains(/verify/i).click();
});

it('planter', () => {
cy.contains(/planter/i).click();
it('grower', () => {
cy.contains(/grower/i).click();
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('Planter', () => {
describe('Grower', () => {
const pageSize = 24;

before(() => {
Expand All @@ -9,7 +9,7 @@ describe('Planter', () => {
cy.contains(/log in/i).click();
// cy.visit('/');
// cy.get('button[title=menu]').click();
cy.contains(/Planters/i).click({ force: true });
cy.contains(/Growers/i).click({ force: true });
});

it('Should get id:xxx', () => {
Expand All @@ -28,7 +28,7 @@ describe('Planter', () => {
cy.get('button[title="Previous page"]').should('be.disabled');
});

it('Should show a full page of planters', () => {
it('Should show a full page of growers', () => {
cy.get('.MuiCard-root').should('have.length', pageSize);
});

Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/organization.spec.py.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('Organization', () => {
cy.contains('.MuiMenuItem-root', /verify/i).click();
});

it('planter', () => {
cy.contains('.MuiMenuItem-root', /planter/i).click({ force: true });
it('grower', () => {
cy.contains('.MuiMenuItem-root', /grower/i).click({ force: true });
});

it.only('tree', () => {
Expand Down
38 changes: 19 additions & 19 deletions src/api/planters.js → src/api/growers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { handleResponse, handleError, getOrganization } from './apiUtils';
import { session } from '../models/auth';

export default {
getPlanter(id) {
const planterQuery = `${
getGrower(id) {
const growerQuery = `${
process.env.REACT_APP_API_ROOT
}/api/${getOrganization()}planter/${id}`;

return fetch(planterQuery, {
return fetch(growerQuery, {
method: 'GET',
headers: {
'content-type': 'application/json',
Expand All @@ -18,9 +18,9 @@ export default {
.catch(handleError);
},

getPlanters({ skip, rowsPerPage, orderBy = 'id', order = 'desc', filter }) {
getGrowers({ skip, rowsPerPage, orderBy = 'id', order = 'desc', filter }) {
const where = filter.getWhereObj ? filter.getWhereObj() : {};
const planterFilter = {
const growerFilter = {
where: { ...where, active: true },
order: [`${orderBy} ${order}`],
limit: rowsPerPage,
Expand All @@ -40,7 +40,7 @@ export default {
};
const query = `${
process.env.REACT_APP_API_ROOT
}/api/${getOrganization()}planter?filter=${JSON.stringify(planterFilter)}`;
}/api/${getOrganization()}planter?filter=${JSON.stringify(growerFilter)}`;

return fetch(query, {
headers: {
Expand All @@ -67,10 +67,10 @@ export default {
.catch(handleError);
},

getPlanterRegistrations(planterId) {
getGrowerRegistrations(growerId) {
const registrationQuery = `${
process.env.REACT_APP_API_ROOT
}/api/${getOrganization()}planter-registration?filter[where][planterId]=${planterId}`;
}/api/${getOrganization()}planter-registration?filter[where][planterId]=${growerId}`;
return fetch(registrationQuery, {
method: 'GET',
headers: {
Expand All @@ -82,20 +82,20 @@ export default {
.catch(handleError);
},

getPlanterSelfies(planterId) {
getGrowerSelfies(growerId) {
const filter = {
order: 'timeUpdated DESC',
limit: 100,
fields: ['planterPhotoUrl'],
};

const planterSelfiesQuery = `${
const growerSelfiesQuery = `${
process.env.REACT_APP_API_ROOT
}/api/${getOrganization()}planter/${planterId}/selfies/?filter=${JSON.stringify(
}/api/${getOrganization()}planter/${growerId}/selfies/?filter=${JSON.stringify(
filter,
)}`;

return fetch(planterSelfiesQuery, {
return fetch(growerSelfiesQuery, {
method: 'GET',
headers: {
'content-type': 'application/json',
Expand All @@ -116,22 +116,22 @@ export default {
.catch(handleError);
},

updatePlanter(planterUpdate) {
if (planterUpdate.organizationId === 'null') {
planterUpdate = { ...planterUpdate, organizationId: null };
updateGrower(growerUpdate) {
if (growerUpdate.organizationId === 'null') {
growerUpdate = { ...growerUpdate, organizationId: null };
}
const { id } = planterUpdate;
const planterQuery = `${
const { id } = growerUpdate;
const growerQuery = `${
process.env.REACT_APP_API_ROOT
}/api/${getOrganization()}planter/${id}`;

return fetch(planterQuery, {
return fetch(growerQuery, {
method: 'PATCH',
headers: {
'content-type': 'application/json',
Authorization: session.token,
},
body: JSON.stringify(planterUpdate),
body: JSON.stringify(growerUpdate),
})
.then(handleResponse)
.catch(handleError);
Expand Down
38 changes: 0 additions & 38 deletions src/common/policy.js

This file was deleted.

9 changes: 2 additions & 7 deletions src/components/CaptureDetailDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,13 @@ function CaptureDetailDialog(props) {
<Typography className={classes.subtitle}>Capture Data</Typography>
{[
{
label: 'Planter ID',
label: 'Grower ID',
value: capture.planterId,
copy: true,
link: true,
},
{
label: 'Capture UUID',
value: capture.uuid,
copy: true,
},
{
label: 'Planter Identifier',
label: 'Grower Identifier',
value: capture.planterIdentifier,
copy: true,
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/CaptureTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const columns = [
},
{
attr: 'planterId',
label: 'Planter ID',
label: 'Grower ID',
},
{
attr: 'deviceIdentifier',
Expand Down
Loading

0 comments on commit 190ea83

Please sign in to comment.