Skip to content

Commit

Permalink
Merge pull request Greenstand#118 from gwynndp/refactor-redux
Browse files Browse the repository at this point in the history
refactor: move redux to context
  • Loading branch information
gwynndp authored Sep 19, 2021
2 parents 77d3727 + 1013a03 commit 93b7154
Show file tree
Hide file tree
Showing 90 changed files with 6,179 additions and 5,840 deletions.
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/src/components/tests/tags.test.js"
},
{
"name": "Debug CRA Tests",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
"args": ["test", "--runInBand", "--no-cache", "--watchAll=false"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"env": {
"CI": "true"
},
"disableOptimisticBPs": true
}
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mount } from 'cypress-react-unit-test';
import React from 'react';
import Account from './Account';
import theme from './common/theme';
import Account from '../../src/components/Account';
import theme from '../../src/components/common/theme';
import { ThemeProvider } from '@material-ui/core/styles';

describe('Account', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import { mount } from 'cypress-react-unit-test';
import React from 'react';
import { Provider } from 'react-redux';
import theme from './common/theme';
import theme from '../../src/components/common/theme';
import { ThemeProvider } from '@material-ui/core/styles';
import { init } from '@rematch/core';
import api from '../api/planters';
import api from '../../src/api/planters';

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

describe('EditPlanter', () => {
let store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ describe('Filter', () => {
beforeEach(() => {
mount(
<ThemeProvider theme={theme}>
<Filter
filter={filterModel}
isOpen={true}
/>
<Filter filter={filterModel} isOpen={true} />
</ThemeProvider>,
);
});
Expand All @@ -28,11 +25,17 @@ describe('Filter', () => {
cy.get('#start-date-picker+* button').then(($buttons) => {
$buttons[0].click();
// Check forward button is disabled
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should('have.length', 1);
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should(
'have.length',
1,
);
cy.get('.MuiPickersCalendarHeader-iconButton').then(($headerButtons) => {
$headerButtons[0].click();
// Check both buttons are enabled
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should('have.length', 0);
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should(
'have.length',
0,
);
});
});
});
Expand All @@ -41,11 +44,17 @@ describe('Filter', () => {
cy.get('#end-date-picker+* button').then(($buttons) => {
$buttons[0].click();
// Check forward button is disabled
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should('have.length', 1);
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should(
'have.length',
1,
);
cy.get('.MuiPickersCalendarHeader-iconButton').then(($headerButtons) => {
$headerButtons[0].click();
// Check both buttons are enabled
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should('have.length', 0);
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should(
'have.length',
0,
);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,28 @@ describe('FilterTop', () => {
mount(
<Provider store={store}>
<ThemeProvider theme={theme}>
<FilterTop
filter={filterModel}
isOpen={true}
/>
</ThemeProvider>,
</Provider>
<FilterTop filter={filterModel} isOpen={true} />
</ThemeProvider>
,
</Provider>,
);
});

it('start date picker forward button should be enabled', () => {
cy.get('#start-date-picker+* button').then(($buttons) => {
$buttons[0].click();
// Check forward button is disabled
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should('have.length', 1);
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should(
'have.length',
1,
);
cy.get('.MuiPickersCalendarHeader-iconButton').then(($headerButtons) => {
$headerButtons[0].click();
// Check both buttons are enabled
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should('have.length', 0);
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should(
'have.length',
0,
);
});
});
});
Expand All @@ -68,11 +72,17 @@ describe('FilterTop', () => {
cy.get('#end-date-picker+* button').then(($buttons) => {
$buttons[0].click();
// Check forward button is disabled
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should('have.length', 1);
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should(
'have.length',
1,
);
cy.get('.MuiPickersCalendarHeader-iconButton').then(($headerButtons) => {
$headerButtons[0].click();
// Check both buttons are enabled
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should('have.length', 0);
cy.get('.MuiPickersCalendarHeader-iconButton.Mui-disabled').should(
'have.length',
0,
);
});
});
});
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mount } from 'cypress-react-unit-test';
import React from 'react';
import Login from './Login';
import theme from './common/theme';
import Login from '../../src/components/Login';
import theme from '../../src/components/common/theme';
import { ThemeProvider } from '@material-ui/core/styles';

describe('Login', () => {
Expand Down
File renamed without changes.
File renamed without changes.
30 changes: 11 additions & 19 deletions cypress/integration/account.spec.py.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@


describe("Account", () => {
before(() => {
cy.visit("/");
cy.contains(/Login/i);
cy.findInputByLabel("username")
.type("amdin");
cy.findInputByLabel("password")
.type("amdin");
cy.contains(/login/i)
.click();
cy.contains(/Welcome/i);
describe('Account', () => {
beforeEach(() => {
cy.visit('/');
cy.contains(/Log in/i);
cy.findInputByLabel(/Username/i).type('username');
cy.findInputByLabel(/Password/i).type('password');
cy.contains(/log in/i).click();
// cy.contains(/admin panel/i);
});

it("Account", () => {
cy.contains(/account/i)
.click();
cy.contains(/log out/i)
.click();
it('Account', () => {
cy.contains(/account/i).click();
cy.contains(/log out/i).click();
cy.contains(/login/i);
});

});
30 changes: 14 additions & 16 deletions cypress/integration/admin.spec.py.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@

describe("Admin", () => {
describe('Admin', () => {
beforeEach(() => {
cy.visit("/");
cy.visit('/');
cy.contains(/Log in/i);
cy.findInputByLabel("Username")
.type("admin");
cy.findInputByLabel("Password")
.type("admin");
cy.contains(/log in/i)
.click();
cy.contains(/Greenstand admin panel/i);
cy.findInputByLabel(/Username/i).type('username');
cy.findInputByLabel(/Password/i).type('password');
cy.contains(/log in/i).click();
});

it('verify menu item', () => {
// cy.visit('/verify');
cy.contains(/verify/i);
});

it("verify", () => {
cy.contains(/verify/i)
.click();
it('verify', () => {
cy.contains(/verify/i).click();
});

it("planter", () => {
cy.contains(/planter/i)
.click();
it('planter', () => {
cy.contains(/planter/i).click();
});
});
115 changes: 58 additions & 57 deletions cypress/integration/login.spec.py.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,83 @@
describe('Login', () => {
before(() => {
cy.visit('/')
cy.contains(/Login/i)
cy.findInputByLabel('userName').type('admin')
cy.findInputByLabel('password').type('admin')
cy.contains(/login/i).click()
})
beforeEach(() => {
cy.visit('/');
cy.contains(/Log in/i);
cy.findInputByLabel(/Username/i).type('testadmin');
cy.findInputByLabel(/Password/i).type('testpwd');
cy.contains(/log in/i).click();
});

it('Login successfully', () => {
cy.contains(/Welcome/i)
})
cy.contains(/Welcome/i);
});

describe('User Manager', () => {
beforeEach(() => {
cy.contains(/user manager/i).click()
})
cy.contains(/user manager/i).click();
});

it.skip('Edit', () => {
// cy.get("button[title=edit]")
// .click();
cy.findRoleByText('listitem', 'admin').find('button[title=edit]').click()
cy.contains('User Detail')
cy.findInputByLabel('First Name').type('Dadior2')
cy.findRoleByText('list', 'Roles').contains('Admin').should('not.visible')
cy.findRoleByText('list', 'Selected').contains('Admin')
cy.findRoleByText('list', 'Roles').contains('Tree Auditor').click()
cy.contains('>').click()
cy.contains(/save/i).click()
cy.contains('User Detail').should('not.visible')
cy.findRoleByText('listitem', 'Dadior2').contains('Tree Auditor').should('not.visible')
})
cy.findRoleByText('listitem', 'admin').find('button[title=edit]').click();
cy.contains('User Detail');
cy.findInputByLabel('First Name').type('Dadior2');
cy.findRoleByText('list', 'Roles')
.contains('Admin')
.should('not.visible');
cy.findRoleByText('list', 'Selected').contains('Admin');
cy.findRoleByText('list', 'Roles').contains('Tree Auditor').click();
cy.contains('>').click();
cy.contains(/save/i).click();
cy.contains('User Detail').should('not.visible');
cy.findRoleByText('listitem', 'Dadior2')
.contains('Tree Auditor')
.should('not.visible');
});

it("Password", () => {
cy.findRoleByText('listitem', 'Dadior').find('button[title=\'generate password\']').click()
cy.findInputByLabel(/please input/i)
.type("admin");
cy.contains("button","Generate")
it('Password', () => {
cy.findRoleByText('listitem', 'Dadior')
.find("button[title='generate password']")
.click();
})
cy.findInputByLabel(/please input/i).type('admin');
cy.contains('button', 'Generate').click();
});

it("Create", () => {
it('Create', () => {
cy.contains(/add user/i).click();
cy.contains(/user detail/i);
cy.findInputByLabel('Username').type('ezra');
cy.findInputByLabel('First Name').type('Ezra');
cy.findInputByLabel('Last Name').type('David');
cy.findInputByLabel('Email').type('[email protected]');
cy.findRoleByText('list', 'Roles').contains('Admin')
.click();
cy.contains('>').click()
cy.contains(/save/i).click()

})
})
})
cy.findRoleByText('list', 'Roles').contains('Admin').click();
cy.contains('>').click();
cy.contains(/save/i).click();
});
});
});

describe.skip('Login with bbb', () => {
before(() => {
cy.visit('/')
cy.contains(/Login/i)
cy.findInputByLabel('userName').type('bbb')
cy.findInputByLabel('password').type('123456')
cy.contains(/login/i).click()
})
cy.visit('/');
cy.contains(/Login/i);
cy.findInputByLabel('userName').type('bbb');
cy.findInputByLabel('password').type('123456');
cy.contains(/login/i).click();
});

it('Login successfully', () => {
cy.contains(/Welcome/i)
})

// it.only("Test api, should be 401 or 200 cuz the role", () => {
// cy.request("GET", "http://localhost:3000/api/trees/count")
// .should(res => {
// expect(res.status).to.eq(200);
// });
// cy.request("GET", "http://localhost:3000/api/planter/count")
// .should(res => {
// expect(res.status).to.eq(401);
// });
// });
cy.contains(/Welcome/i);
});

})
// it.only("Test api, should be 401 or 200 cuz the role", () => {
// cy.request("GET", "http://localhost:3000/api/trees/count")
// .should(res => {
// expect(res.status).to.eq(200);
// });
// cy.request("GET", "http://localhost:3000/api/planter/count")
// .should(res => {
// expect(res.status).to.eq(401);
// });
// });
});
Loading

0 comments on commit 93b7154

Please sign in to comment.