Skip to content

Commit

Permalink
feat: add scheduler page e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam-Zhao committed Dec 1, 2023
1 parent 4ccfc9a commit e952207
Show file tree
Hide file tree
Showing 7 changed files with 739 additions and 57 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/create-cluster.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe('Create cluster', () => {
// Show verification error message.
cy.get('#name-helper-text').should('be.visible').and('contain', 'Fill in the characters, the length is 1-40.');

// Submit form when validation fails
// Submit form when validation fails.
cy.get('#save').click();

// Cluster creation failed, the page is still in cluster/new.
Expand Down
282 changes: 282 additions & 0 deletions cypress/e2e/scheduler.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
import root from '../fixtures/api/role-root.json';
import user from '../fixtures/api/user.json';
import cluster from '../fixtures/api/clusters/cluster/cluster.json';
import schedulers from '../fixtures/api/clusters/cluster/scheduler.json';
import scheduler from '../fixtures/api/scheduler.json';

describe('Scheduler', () => {
beforeEach(() => {
cy.intercept(
{
method: 'GET',
url: '/api/v1/users/1',
},
(req) => {
req.reply({
statusCode: 200,
body: user,
});
},
);
cy.intercept(
{
method: 'GET',
url: '/api/v1/users/1/roles',
},
(req) => {
req.reply({
statusCode: 200,
body: root,
});
},
);
cy.intercept(
{
method: 'GET',
url: '/api/v1/clusters/1',
},
(req) => {
req.reply({
statusCode: 200,
body: cluster,
});
},
);
cy.intercept(
{
method: 'GET',
url: '/api/v1/seed-peers?page=1&per_page=10000000&seed_peer_cluster_id=1',
},
(req) => {
req.reply({
statusCode: 200,
body: [],
});
},
);
cy.intercept(
{
method: 'GET',
url: '/api/v1/schedulers?page=1&per_page=10000000&scheduler_cluster_id=1',
},
(req) => {
req.reply({
statusCode: 200,
body: schedulers,
});
},
);
cy.intercept(
{
method: 'GET',
url: '/api/v1/schedulers/7',
},
(req) => {
req.reply({
statusCode: 200,
body: scheduler,
});
},
);

cy.signin();
cy.visit('/clusters/1/schedulers/7');

cy.viewport(1440, 1080);
});

it('click the hostname', () => {
cy.visit('/clusters/1');

cy.get(
':nth-child(6) > .css-8atqhb > .MuiTable-root > .MuiTableBody-root > :nth-child(1) > :nth-child(2) > .MuiTypography-root',
).should('have.text', 'scheduler-7');

cy.get(
':nth-child(6) > .css-8atqhb > .MuiTable-root > .MuiTableBody-root > :nth-child(1) > :nth-child(2) > .MuiTypography-root',
).click();

// Then I see that the current page is the clusters/1/schedulers/7!
cy.url().should('include', '/clusters/1/schedulers/7');
});

it('click the breadcrumb', () => {
// Check for breadcrumb.
cy.get('.MuiBreadcrumbs-ol > :nth-child(3) > .MuiTypography-root')
.should('be.visible')
.and('contain', 'scheduler-cluster-1');

cy.get('.MuiBreadcrumbs-ol > :nth-child(3) > .MuiTypography-root').click();

// Then I see that the current page is the clusters/1!
cy.url().should('include', '/clusters/1');
});

describe('when data is loaded', () => {
it('can display breadcrumb', () => {
cy.get('.MuiBreadcrumbs-ol > :nth-child(3) > .MuiTypography-root')
.should('be.visible')
.and('contain', 'scheduler-cluster-1');

cy.get(':nth-child(7) > .MuiTypography-root').should('be.visible').and('contain', 'scheduler-7');
});

it('can display active scheduler', () => {
// Show id.
cy.get('.show_container__qetel > :nth-child(1) > .css-1n0qe7k-MuiTypography-root')
.should('be.visible')
.and('contain', '7');

// Show hostname.
cy.get(':nth-child(2) > .css-1n0qe7k-MuiTypography-root').should('be.visible').and('contain', 'scheduler-7');

// Show ip.
cy.get(':nth-child(3) > .css-1n0qe7k-MuiTypography-root').should('be.visible').and('contain', '30.44.98.202');

// Show cluster id.
cy.get('.show_clusterIDContaine__Gvk7F > .css-1n0qe7k-MuiTypography-root')
.should('be.visible')
.and('contain', '1');

// Show port.
cy.get('.show_schedulerContainer__euX4O > :nth-child(1) > .css-1n0qe7k-MuiTypography-root')
.should('be.visible')
.and('contain', '8002');

// Show Active background color.
cy.get(':nth-child(2) > .MuiChip-root')
.should('be.visible')
.and('contain', 'Active')
.and('have.css', 'background-color', 'rgb(46, 143, 121)');

// Show features.
cy.get('.show_schedulerContainer__euX4O > :nth-child(3)')
.should('be.visible')
.and('contain', 'Schedule')
.and('contain', 'Preheat');

// Show created at.
cy.get(':nth-child(4) > .MuiChip-root').should('have.text', '2023-11-09-15:09');

// Show updated at.
cy.get(':nth-child(5) > .MuiChip-root').should('have.text', '2023-11-09-15:09');
});
});

describe('when no data is loaded', () => {
beforeEach(() => {
cy.intercept({ method: 'GET', url: '/api/v1/schedulers/7' }, (req) => {
req.reply({
statusCode: 200,
body: [],
});
});
});

it('unable to display breadcrumb', () => {
cy.get('.MuiBreadcrumbs-ol > :nth-child(3) > .MuiTypography-root')
.should('be.visible')
.and('contain', 'scheduler-cluster-1');

cy.get(':nth-child(7) > .MuiTypography-root').should('be.visible').and('contain', '-');
});

it('scheduler should render empty status', () => {
// Show ID.
cy.get('.show_container__qetel > :nth-child(1) > .css-1n0qe7k-MuiTypography-root').should('contain', '-');

// Show Hostname.
cy.get(':nth-child(2) > .css-1n0qe7k-MuiTypography-root').should('contain', '-');

// Show IP.
cy.get(':nth-child(3) > .css-1n0qe7k-MuiTypography-root').should('contain', '-');

// Show Cluster ID.
cy.get('.show_clusterIDContaine__Gvk7F > .css-1n0qe7k-MuiTypography-root').should('contain', '-');

// Show Port.
cy.get('.show_schedulerContainer__euX4O > :nth-child(1) > .css-1n0qe7k-MuiTypography-root').should(
'contain',
'-',
);

// Show Start.
cy.get('.show_schedulerContainer__euX4O > :nth-child(2)').should('contain', '-');

// Show Features.
cy.get('.show_schedulerContainer__euX4O > :nth-child(3)').should('contain', '-');

// Show Created At.
cy.get(':nth-child(4) > .MuiChip-root').should('not.exist');

// Show Updated At.
cy.get(':nth-child(5) > .MuiChip-root').should('not.exist');
});
});

describe('should handle API error response', () => {
beforeEach(() => {
cy.intercept(
{
method: 'GET',
url: '/api/v1/schedulers/1',
},
(req) => {
req.reply({
forceNetworkError: true,
});
},
);
cy.visit('/clusters/1/schedulers/1');
});

it('show error message', () => {
// Show error message
cy.get('.MuiAlert-message').should('be.visible').and('contain', 'Failed to fetch');

// Close error message.
cy.get('.MuiAlert-action > .MuiButtonBase-root').click();
cy.get('.MuiAlert-message').should('not.exist');
});

it('unable to display breadcrumb', () => {
cy.get('.MuiBreadcrumbs-ol > :nth-child(3) > .MuiTypography-root')
.should('be.visible')
.and('contain', 'scheduler-cluster-1');

cy.get(':nth-child(7) > .MuiTypography-root').should('be.visible').and('contain', '-');
});

it('scheduler should render empty status', () => {
// Show ID.
cy.get('.show_container__qetel > :nth-child(1) > .css-1n0qe7k-MuiTypography-root').should('contain', '-');

// Show Hostname.
cy.get(':nth-child(2) > .css-1n0qe7k-MuiTypography-root').should('contain', '-');

// Show IP.
cy.get(':nth-child(3) > .css-1n0qe7k-MuiTypography-root').should('contain', '-');

// Show Cluster ID.
cy.get('.show_clusterIDContaine__Gvk7F > .css-1n0qe7k-MuiTypography-root').should('contain', '-');

// Show Port.
cy.get('.show_schedulerContainer__euX4O > :nth-child(1) > .css-1n0qe7k-MuiTypography-root').should(
'contain',
'-',
);

// Show Start.
cy.get('.show_schedulerContainer__euX4O > :nth-child(2)').should('contain', '-');

// Show Features.
cy.get('.show_schedulerContainer__euX4O > :nth-child(3)').should('contain', '-');

// Show Created At.
cy.get(':nth-child(4) > .MuiChip-root').should('not.exist');

// Show Updated At.
cy.get(':nth-child(5) > .MuiChip-root').should('not.exist');
});
});
});
26 changes: 26 additions & 0 deletions cypress/fixtures/api/clusters/cluster/cluster.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": 1,
"name": "cluster-1",
"bio": "Cluster-1 is a high-performance computing cluster located in China, specifically in Hangzhou and Beijing data centers.",
"scopes": {
"idc": "Hangzhou|Shanghai|Beijing",
"location": "China|Hang|Zhou",
"cidrs": ["10.0.0.0/8", "192.168.0.0/16", "172.16.0.0/12"]
},
"scheduler_cluster_id": 1,
"seed_peer_cluster_id": 1,
"scheduler_cluster_config": {
"candidate_parent_limit": 4,
"filter_parent_limit": 40
},
"seed_peer_cluster_config": {
"load_limit": 300
},
"peer_cluster_config": {
"load_limit": 51,
"concurrent_piece_count": 4
},
"created_at": "2023-10-31T07:48:35Z",
"updated_at": "2023-10-31T07:48:35Z",
"is_default": true
}
Loading

0 comments on commit e952207

Please sign in to comment.