-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from shutter-network/staging
Staging
- Loading branch information
Showing
10 changed files
with
218 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import SlotProgression from '../../src/modules/SlotProgression'; | ||
import { mount } from "cypress/react18"; | ||
import React from 'react'; | ||
import { ThemeProvider as MUIThemeProvider } from '@mui/material/styles'; | ||
import { ThemeProvider as StyledThemeProvider } from 'styled-components'; | ||
import { muiTheme, customTheme } from '../../src/theme'; | ||
|
||
describe('<SlotProgression />', () => { | ||
const gnosisGenesisTime = 1638993340; | ||
const slotDuration = 5; | ||
const slotsPerEpoch = 16; | ||
|
||
it('verifies slot states using explicit class names with controlled time', () => { | ||
const currentTime = Date.now(); | ||
cy.clock(currentTime); | ||
cy.stub(Date, 'now').returns(currentTime); | ||
const currentSlot = Math.floor((currentTime / 1000 - gnosisGenesisTime) / slotDuration); | ||
|
||
const mockSlots = Array.from({ length: slotsPerEpoch * 3 }, (_, i) => ({ | ||
Slot: currentSlot - slotsPerEpoch + i, | ||
ValidatorIndex: 1000 + i, | ||
IsRegisteration: i % 2 == 0, | ||
})); | ||
|
||
cy.intercept('GET', '/api/slot/top_5_epochs', { | ||
statusCode: 200, | ||
body: { | ||
message: mockSlots, | ||
}, | ||
}).as('getSlotData'); | ||
|
||
mount( | ||
<MUIThemeProvider theme={muiTheme}> | ||
<StyledThemeProvider theme={customTheme}> | ||
<MemoryRouter> | ||
<SlotProgression /> | ||
</MemoryRouter> | ||
</StyledThemeProvider> | ||
</MUIThemeProvider> | ||
); | ||
|
||
cy.wait('@getSlotData').then(({ response }) => { | ||
if (!response?.body?.message) { | ||
throw new Error('API response is undefined or improperly structured'); | ||
} | ||
|
||
const slotsData = response.body.message; | ||
|
||
cy.get('.slot-visualizer').should('exist').then(() => { | ||
cy.get('.slot-visualizer').find('.slot-block').each(($slot, index) => { | ||
const slotData = slotsData[index]; | ||
cy.wrap($slot).as(`slot-${index}`); | ||
|
||
if (slotData.Slot == currentSlot) { | ||
cy.get(`@slot-${index}`).should('have.class', 'active'); | ||
} else if (slotData.Slot < currentSlot) { | ||
cy.get(`@slot-${index}`).should('have.class', 'passed'); | ||
} | ||
|
||
if (slotData.IsRegisteration) { | ||
cy.get(`@slot-${index}`).should('have.class', 'shutterized'); | ||
cy.get(`@slot-${index}`).find('svg').should('exist'); | ||
} | ||
}); | ||
}); | ||
|
||
cy.tick(slotDuration * 1000); | ||
const newCurrentSlot = currentSlot + 1; | ||
|
||
cy.get('.slot-visualizer').find('.slot-block').each(($slot, index) => { | ||
const slotData = slotsData[index]; | ||
cy.wrap($slot).as(`slot-${index}`); | ||
|
||
if (slotData.Slot === newCurrentSlot) { | ||
cy.get(`@slot-${index}`).should('have.class', 'active'); | ||
} else if (slotData.Slot < newCurrentSlot) { | ||
cy.get(`@slot-${index}`).should('have.class', 'passed'); | ||
} | ||
|
||
if (slotData.IsRegisteration) { | ||
cy.get(`@slot-${index}`).should('have.class', 'shutterized'); | ||
cy.get(`@slot-${index}`).find('svg').should('exist'); | ||
} | ||
}); | ||
|
||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.