Skip to content

Commit

Permalink
Add linter for cypress tests (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
aShelist authored Aug 2, 2021
1 parent a184a26 commit 9fd317e
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 51 deletions.
2 changes: 2 additions & 0 deletions frontend-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ set -e -x
npm run graphqlgen --prefix=webui
npm run flow --prefix=webui
npm run test_once --prefix=webui
npm run lint --prefix=webui
npm run lint:test --prefix=webui
5 changes: 3 additions & 2 deletions webui/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "react-app",
"extends": ["react-app", "plugin:cypress/recommended"],
"overrides": [],
"settings": {
"react": {
Expand All @@ -9,7 +9,8 @@
},
"parser": "babel-eslint",
"plugins": [
"flowtype"
"flowtype",
"cypress"
],
"rules": {
"no-trailing-spaces": ["warn"],
Expand Down
26 changes: 14 additions & 12 deletions webui/cypress/integration/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('Auth', () => {
_G.cluster:start()
return true
`}).should('deep.eq', [true]);
`
}).should('deep.eq', [true]);
});

after(() => {
Expand All @@ -46,9 +47,9 @@ describe('Auth', () => {
////////////////////////////////////////////////////////////////////
cy.get('.meta-test__LoginBtn').click();
cy.get('.meta-test__LoginForm input[name="username"]')
.should('have.value', '');
.should('have.value', '');
cy.get('.meta-test__LoginForm input[name="password"]')
.should('have.value', '');
.should('have.value', '');
cy.get('.meta-test__LoginFormBtn').click();
cy.get('.meta-test__LoginForm').contains('username is a required field');
cy.get('.meta-test__LoginForm').contains('password is a required field');
Expand All @@ -59,9 +60,9 @@ describe('Auth', () => {
////////////////////////////////////////////////////////////////////
cy.get('.meta-test__LoginBtn').click();
cy.get('.meta-test__LoginForm input[name="username"]')
.should('have.value', '');
.should('have.value', '');
cy.get('.meta-test__LoginForm input[name="password"]')
.type('test-cluster-cookie');
.type('test-cluster-cookie');
cy.get('.meta-test__LoginFormBtn').click();
cy.get('.meta-test__LoginForm').contains('username is a required field');
cy.get('.meta-test__LoginForm button[type="button"]').contains('Cancel').click();
Expand All @@ -71,10 +72,10 @@ describe('Auth', () => {
////////////////////////////////////////////////////////////////////
cy.get('.meta-test__LoginBtn').click();
cy.get('.meta-test__LoginForm input[name="username"]')
.type('admin')
.should('have.value', 'admin');
.type('admin')
.should('have.value', 'admin');
cy.get('.meta-test__LoginForm input[name="password"]')
.should('have.value', '');
.should('have.value', '');
cy.get('.meta-test__LoginFormBtn').click();
cy.get('.meta-test__LoginForm').contains('password is a required field');
cy.get('.meta-test__LoginForm button[type="button"]').contains('Cancel').click();
Expand All @@ -97,10 +98,10 @@ describe('Auth', () => {
////////////////////////////////////////////////////////////////////
cy.get('.meta-test__LoginBtn').click();
cy.get('.meta-test__LoginForm input[name="username"]')
.type('admin')
.should('have.value', 'admin');
.type('admin')
.should('have.value', 'admin');
cy.get('.meta-test__LoginForm input[name="password"]')
.type('incorrect password');
.type('incorrect password');
cy.get('.meta-test__LoginFormBtn').click();
cy.get('.meta-test__LoginForm').contains('Authentication failed');
//check button X in the auth form
Expand Down Expand Up @@ -153,7 +154,8 @@ describe('Auth', () => {
_G.cluster.main_server.command = helpers.entrypoint('srv_woauth')
_G.cluster.main_server:start()
return true
`}).should('deep.eq', [true]);
`
}).should('deep.eq', [true]);
cy.get('a[href="/admin/cluster/dashboard"]').click();
cy.reload();

Expand Down
4 changes: 3 additions & 1 deletion webui/cypress/integration/bootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ describe('Replicaset configuration & Bootstrap Vshard', () => {
cy.get('[data-cy=meta-test__replicaSetSection]').eq(0).contains('healthy');
cy.get('.ServerLabelsHighlightingArea').eq(0).contains('healthy');

cy.get('span:contains(GraphQL error) + span:contains(No remotes with role "vshard-router" available) + button + svg').click();
cy.get('span:contains(GraphQL error) + ' +
'span:contains(No remotes with role "vshard-router" available) + button + svg')
.click();

////////////////////////////////////////////////////////////////////
cy.log('Configure vshard-router');
Expand Down
6 changes: 4 additions & 2 deletions webui/cypress/integration/change-advertise-uri.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('Change advertise uri', () => {
_G.cluster.main_server.net_box_uri = 'localhost:13312'
_G.cluster.main_server:start()
return true
`}).should('deep.eq', [true]);
`
}).should('deep.eq', [true]);
});

after(() => {
Expand Down Expand Up @@ -70,7 +71,8 @@ describe('Change advertise uri', () => {
cy.get('.meta-test__ClusterSuggestionsPanel').find('button:contains(Review changes)').click();

cy.get('.meta-test__AdvertiseURISuggestionModal').contains('Change advertise URI');
cy.get('.meta-test__AdvertiseURISuggestionModal').contains('One or more servers were restarted with a new advertise uri');
cy.get('.meta-test__AdvertiseURISuggestionModal')
.contains('One or more servers were restarted with a new advertise uri');
cy.get('.meta-test__AdvertiseURISuggestionModal').contains('localhost:13301 -> localhost:13312');
cy.get('.meta-test__AdvertiseURISuggestionModal').find('button:contains(Update)').click();
cy.get('.meta-test__AdvertiseURISuggestionModal').should('not.exist');
Expand Down
3 changes: 2 additions & 1 deletion webui/cypress/integration/demo-panel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('Demo panel', () => {
_G.cluster:start()
return true
`}).should('deep.eq', [true]);
`
}).should('deep.eq', [true]);
});

after(() => {
Expand Down
6 changes: 4 additions & 2 deletions webui/cypress/integration/disable-server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ describe('Disable server', () => {
////////////////////////////////////////////////////////////////////
cy.log('Kill servers 2 and 3');
////////////////////////////////////////////////////////////////////
cy.task('tarantool', { code: `
cy.task('tarantool', {
code: `
_G.cluster:server('dummy-2').process:kill('KILL')
_G.cluster:server('dummy-3').process:kill('KILL')
_G.cluster:server('dummy-2').process = nil
_G.cluster:server('dummy-3').process = nil
` });
`
});

////////////////////////////////////////////////////////////////////
cy.log('Inspect suggestion panel');
Expand Down
3 changes: 2 additions & 1 deletion webui/cypress/integration/filtering.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ describe('Replicaset filtering', () => {
_G.server:start()
return true
`}).should('deep.eq', [true])
`
}).should('deep.eq', [true])
});

after(() => {
Expand Down
19 changes: 11 additions & 8 deletions webui/cypress/integration/global-401-handler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ describe('Global 401 handler', () => {
_G.cluster:start()
return _G.cluster.datadir
`}).then((resp) => {
const workdir = resp[0];
expect(workdir).to.be.a('string');
cy.task('tarantool', {
host: 'unix/', port: workdir + '/control.sock',
code: `
`
}).then(resp => {
const workdir = resp[0];
expect(workdir).to.be.a('string');
cy.task('tarantool', {
host: 'unix/',
port: workdir + '/control.sock',
code: `
local fun = require('fun')
local cartridge = require('cartridge')
local httpd = cartridge.service_get('httpd')
Expand All @@ -45,8 +47,9 @@ describe('Global 401 handler', () => {
end
return true
`}).should('deep.eq', [true]);
});
`
}).should('deep.eq', [true]);
});
});

after(() => {
Expand Down
3 changes: 2 additions & 1 deletion webui/cypress/integration/network-error-splash.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe('Network error panel', () => {
_G.cluster:start()
return true
`}).should('deep.eq', [true]);
`
}).should('deep.eq', [true]);
});

after(() => {
Expand Down
12 changes: 8 additions & 4 deletions webui/cypress/integration/plugin.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
describe('Test the plugin', () => {

it('return result', () => {
cy.task('tarantool', {code: `
cy.task('tarantool', {
code: `
print('Hello, Tarantool!')
return 1, 2, 3
`}).should('deep.eq', [1, 2, 3]);
`
}).should('deep.eq', [1, 2, 3]);
});

it.skip('tarantool raises', () => {
Expand All @@ -14,8 +16,10 @@ describe('Test the plugin', () => {
});

it.skip('connection refused', () => {
cy.task('tarantool', {host: 'unix/', port: '/dev/null', code: `
cy.task('tarantool', {
host: 'unix/', port: '/dev/null', code: `
return true
`});
`
});
});
});
7 changes: 4 additions & 3 deletions webui/cypress/integration/probe-server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('Probe server', () => {
_G.cluster:start()
return true
`}).should('deep.eq', [true]);
`
}).should('deep.eq', [true]);
});

after(() => {
Expand Down Expand Up @@ -48,8 +49,8 @@ describe('Probe server', () => {
//Try to enter empty and press Enter
cy.get('.meta-test__ProbeServerBtn').click();
cy.get('.ProbeServerModal input[name="uri"]')
.should('be.focused')
.should('have.attr', 'placeholder', 'Server URI, e.g. localhost:3301');
.should('be.focused')
.should('have.attr', 'placeholder', 'Server URI, e.g. localhost:3301');
cy.get('.ProbeServerModal input[name="uri"]').type('{selectall}{backspace}').type(' ');
cy.get('.ProbeServerModal input[name="uri"]').type('{enter}');
cy.get('.ProbeServerModal_error').contains('Probe " " failed: parse error');
Expand Down
6 changes: 4 additions & 2 deletions webui/cypress/integration/restart-replication.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ describe('Disable server', () => {
////////////////////////////////////////////////////////////////////
cy.log('Add issue');
////////////////////////////////////////////////////////////////////
cy.task('tarantool', { code: `
cy.task('tarantool', {
code: `
_G.cluster:server('dummy-2').net_box:call('box.cfg', {{replication = box.NULL}})
` });
`
});

////////////////////////////////////////////////////////////////////
cy.log('Inspect suggestion panel');
Expand Down
3 changes: 2 additions & 1 deletion webui/cypress/integration/server-details.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe('Server details', () => {
{{failover_timeout = 0}}
)
return true
`}).should('deep.eq', [true]);
`
}).should('deep.eq', [true]);
});

after(() => {
Expand Down
7 changes: 4 additions & 3 deletions webui/cypress/integration/sigstop.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('Checking for situations when a connection is lost using SIGSTOP', () =
{{failover_timeout = 0}}
)
return true
`}).should('deep.eq', [true]);
`
}).should('deep.eq', [true]);
});

after(() => {
Expand Down Expand Up @@ -56,9 +57,9 @@ describe('Checking for situations when a connection is lost using SIGSTOP', () =
//Check Issue
cy.get('.meta-test__ClusterIssuesButton').contains('Issues: 1');
cy.get('.meta-test__ClusterIssuesButton').click();
cy.get('.meta-test__ClusterIssuesModal').contains("critical");
cy.get('.meta-test__ClusterIssuesModal').contains('critical');
cy.get('.meta-test__ClusterIssuesModal')
.contains("Replication from localhost:13302 (dummy-2) to localhost:13301 (dummy-1)");
.contains('Replication from localhost:13302 (dummy-2) to localhost:13301 (dummy-1)');
cy.get('.meta-test__ClusterIssuesModal button[type="button"]').click();

//Check buckets
Expand Down
3 changes: 2 additions & 1 deletion webui/cypress/integration/switchover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ describe('Leader promotion tests', () => {
leaderFlag('13303').should('not.exist');

dropdownMenu('13303').contains('Promote a leader').click();
cy.get('span:contains(Leader promotion error) + span:contains(PromoteLeaderError: There is no active coordinator) + button + svg')
cy.get('span:contains(Leader promotion error) + ' +
'span:contains(PromoteLeaderError: There is no active coordinator) + button + svg')
.click();

cy.get('.meta-test__ClusterIssuesButton').should('be.enabled');
Expand Down
6 changes: 3 additions & 3 deletions webui/cypress/integration/uninitialized.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ describe('Uninitialized', () => {
cy.log('Redirects are enabled');
////////////////////////////////////////////////////////////////////

let checkRedirect = (response) => {
let checkRedirect = response => {
expect(response.status).to.be.equal(302)
expect(response.headers['location']).to.be.equal('/xyz/admin')
}
cy.request({url: '/', followRedirect: false}).then(checkRedirect);
cy.request({url: '/xyz', followRedirect: false}).then(checkRedirect);
cy.request({ url: '/', followRedirect: false }).then(checkRedirect);
cy.request({ url: '/xyz', followRedirect: false }).then(checkRedirect);

////////////////////////////////////////////////////////////////////
cy.log('Code without bootstrap');
Expand Down
9 changes: 5 additions & 4 deletions webui/cypress/integration/users.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ describe('Users', () => {
{{failover_timeout = 0}}
)
return _G.cluster.datadir
`});
`
});
});

after(() => {
Expand All @@ -59,7 +60,7 @@ describe('Users', () => {
cy.get('button:contains(Add user)').should('be.enabled');

cy.get('thead th').each((tHeadRow, index) => {
const headings = ["Username", "Full name", "E-mail", "Actions"];
const headings = ['Username', 'Full name', 'E-mail', 'Actions'];
cy.wrap(tHeadRow).should('contain', headings[index]);
});

Expand Down Expand Up @@ -119,7 +120,7 @@ describe('Users', () => {
cy.get('tbody tr[role="row"]').should('have.length', 2);

//checks for new user in list:
cy.get('a:contains(TestUserName)').parents('tr').then((TestUserRow) => {
cy.get('a:contains(TestUserName)').parents('tr').then(TestUserRow => {
cy.wrap(TestUserRow).find('td').eq(0).find('a:contains(TestUserName)');
cy.wrap(TestUserRow).find('td').eq(2).contains('[email protected]');
cy.wrap(TestUserRow).find('td').eq(3).find('button').eq(0).should('be.enabled');
Expand Down Expand Up @@ -174,7 +175,7 @@ describe('Users', () => {
.type('{selectall}{del}Edited Full Name');
cy.get('button:contains(Save)').click();

cy.get('a:contains(TestUserName)').parents('tr').then((TestUserRow) => {
cy.get('a:contains(TestUserName)').parents('tr').then(TestUserRow => {
cy.wrap(TestUserRow).find('td').eq(1).contains('Edited Full Name');
cy.wrap(TestUserRow).find('td').eq(2).contains('[email protected]');
cy.wrap(TestUserRow).find('td').eq(3).find('button').eq(0).should('be.enabled');
Expand Down
Loading

0 comments on commit 9fd317e

Please sign in to comment.