Skip to content

Commit 51791b3

Browse files
author
Antoine de Chevigné
committed
frontend tests
1 parent 75080bc commit 51791b3

File tree

3 files changed

+7481
-1
lines changed

3 files changed

+7481
-1
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import ExplorerOrbitSettings from '@/components/ExplorerOrbitSettings.vue';
2+
3+
describe('ExplorerOrbitSettings.vue', () => {
4+
const mockOrbitConfig = {
5+
id: 1,
6+
parentChainRpcServer: 'https://mainnet.infura.io/v3/test',
7+
rollupContract: '0x1234567890123456789012345678901234567890',
8+
bridgeContract: '0x2345678901234567890123456789012345678901',
9+
inboxContract: '0x3456789012345678901234567890123456789012',
10+
sequencerInboxContract: '0x4567890123456789012345678901234567890123',
11+
outboxContract: '0x5678901234567890123456789012345678901234',
12+
l1GatewayRouter: '0x6789012345678901234567890123456789012345',
13+
l1Erc20Gateway: '0x7890123456789012345678901234567890123456',
14+
l1WethGateway: '0x8901234567890123456789012345678901234567',
15+
l1CustomGateway: '0x9012345678901234567890123456789012345678',
16+
l2GatewayRouter: '0x0123456789012345678901234567890123456789',
17+
l2Erc20Gateway: '0x1234567890123456789012345678901234567890',
18+
l2WethGateway: '0x2345678901234567890123456789012345678901',
19+
l2CustomGateway: '0x3456789012345678901234567890123456789012',
20+
challengeManagerContract: '0x4567890123456789012345678901234567890123',
21+
validatorWalletCreatorContract: '0x5678901234567890123456789012345678901234',
22+
stakeToken: '0x6789012345678901234567890123456789012345',
23+
parentMessageCountShift: 0
24+
};
25+
26+
beforeEach(() => {
27+
vi.spyOn(server, 'getOrbitConfig').mockResolvedValueOnce({ data: { orbitConfig: mockOrbitConfig } });
28+
vi.spyOn(server, 'createOrbitConfig').mockResolvedValueOnce({ data: { config: mockOrbitConfig } });
29+
vi.spyOn(server, 'updateOrbitConfig').mockResolvedValueOnce({ data: { config: mockOrbitConfig } });
30+
});
31+
32+
it('Should display the component with existing configuration', async () => {
33+
const wrapper = mount(ExplorerOrbitSettings, {
34+
props: { explorerId: 1 }
35+
});
36+
await flushPromises();
37+
38+
expect(wrapper.html()).toMatchSnapshot();
39+
});
40+
41+
it('Should display the component without existing configuration', async () => {
42+
vi.spyOn(server, 'getOrbitConfig').mockResolvedValueOnce({ data: { orbitConfig: {} } });
43+
44+
const wrapper = mount(ExplorerOrbitSettings, {
45+
props: { explorerId: 1 }
46+
});
47+
await flushPromises();
48+
49+
expect(wrapper.html()).toMatchSnapshot();
50+
});
51+
52+
it('Should display the component with SSO enabled', async () => {
53+
const wrapper = mount(ExplorerOrbitSettings, {
54+
props: {
55+
explorerId: 1,
56+
sso: true
57+
}
58+
});
59+
await flushPromises();
60+
61+
expect(wrapper.html()).toMatchSnapshot();
62+
});
63+
64+
it('Should show success message after creating configuration', async () => {
65+
vi.spyOn(server, 'getOrbitConfig').mockResolvedValueOnce({ data: { orbitConfig: {} } });
66+
67+
const wrapper = mount(ExplorerOrbitSettings, {
68+
props: { explorerId: 1 }
69+
});
70+
await flushPromises();
71+
72+
// Fill in required fields using the component's data
73+
wrapper.vm.config.parentChainRpcServer = 'https://mainnet.infura.io/v3/test';
74+
wrapper.vm.config.rollupContract = '0x1234567890123456789012345678901234567890';
75+
wrapper.vm.config.bridgeContract = '0x2345678901234567890123456789012345678901';
76+
wrapper.vm.config.inboxContract = '0x3456789012345678901234567890123456789012';
77+
wrapper.vm.config.sequencerInboxContract = '0x4567890123456789012345678901234567890123';
78+
wrapper.vm.config.outboxContract = '0x5678901234567890123456789012345678901234';
79+
wrapper.vm.config.l1GatewayRouter = '0x6789012345678901234567890123456789012345';
80+
wrapper.vm.config.l1Erc20Gateway = '0x7890123456789012345678901234567890123456';
81+
wrapper.vm.config.l1WethGateway = '0x8901234567890123456789012345678901234567';
82+
wrapper.vm.config.l1CustomGateway = '0x9012345678901234567890123456789012345678';
83+
wrapper.vm.config.l2GatewayRouter = '0x0123456789012345678901234567890123456789';
84+
wrapper.vm.config.l2Erc20Gateway = '0x1234567890123456789012345678901234567890';
85+
wrapper.vm.config.l2WethGateway = '0x2345678901234567890123456789012345678901';
86+
wrapper.vm.config.l2CustomGateway = '0x3456789012345678901234567890123456789012';
87+
88+
// Submit form
89+
await wrapper.find('form').trigger('submit');
90+
await flushPromises();
91+
92+
expect(wrapper.html()).toMatchSnapshot();
93+
});
94+
95+
it('Should show success message after updating configuration', async () => {
96+
const wrapper = mount(ExplorerOrbitSettings, {
97+
props: { explorerId: 1 }
98+
});
99+
await flushPromises();
100+
101+
// Update a field
102+
wrapper.vm.config.parentChainRpcServer = 'https://mainnet.infura.io/v3/updated';
103+
104+
// Submit form
105+
await wrapper.find('form').trigger('submit');
106+
await flushPromises();
107+
108+
expect(wrapper.html()).toMatchSnapshot();
109+
});
110+
111+
it('Should show error message when creating configuration fails', async () => {
112+
vi.spyOn(server, 'createOrbitConfig').mockRejectedValueOnce({ response: { data: 'Configuration failed' } });
113+
vi.spyOn(server, 'getOrbitConfig').mockResolvedValueOnce({ data: { orbitConfig: {} } });
114+
115+
const wrapper = mount(ExplorerOrbitSettings, {
116+
props: { explorerId: 1 }
117+
});
118+
await flushPromises();
119+
120+
// Fill in required fields using the component's data
121+
wrapper.vm.config.parentChainRpcServer = 'https://mainnet.infura.io/v3/test';
122+
wrapper.vm.config.rollupContract = '0x1234567890123456789012345678901234567890';
123+
wrapper.vm.config.bridgeContract = '0x2345678901234567890123456789012345678901';
124+
wrapper.vm.config.inboxContract = '0x3456789012345678901234567890123456789012';
125+
wrapper.vm.config.sequencerInboxContract = '0x4567890123456789012345678901234567890123';
126+
wrapper.vm.config.outboxContract = '0x5678901234567890123456789012345678901234';
127+
wrapper.vm.config.l1GatewayRouter = '0x6789012345678901234567890123456789012345';
128+
wrapper.vm.config.l1Erc20Gateway = '0x7890123456789012345678901234567890123456';
129+
wrapper.vm.config.l1WethGateway = '0x8901234567890123456789012345678901234567';
130+
wrapper.vm.config.l1CustomGateway = '0x9012345678901234567890123456789012345678';
131+
wrapper.vm.config.l2GatewayRouter = '0x0123456789012345678901234567890123456789';
132+
wrapper.vm.config.l2Erc20Gateway = '0x1234567890123456789012345678901234567890';
133+
wrapper.vm.config.l2WethGateway = '0x2345678901234567890123456789012345678901';
134+
wrapper.vm.config.l2CustomGateway = '0x3456789012345678901234567890123456789012';
135+
136+
// Submit form
137+
await wrapper.find('form').trigger('submit');
138+
await flushPromises();
139+
140+
expect(wrapper.html()).toMatchSnapshot();
141+
});
142+
143+
it('Should show error message when updating configuration fails', async () => {
144+
vi.spyOn(server, 'updateOrbitConfig').mockRejectedValueOnce({ response: { data: 'Update failed' } });
145+
146+
const wrapper = mount(ExplorerOrbitSettings, {
147+
props: { explorerId: 1 }
148+
});
149+
await flushPromises();
150+
151+
// Update a field
152+
wrapper.vm.config.parentChainRpcServer = 'https://mainnet.infura.io/v3/updated';
153+
154+
// Submit form
155+
await wrapper.find('form').trigger('submit');
156+
await flushPromises();
157+
158+
expect(wrapper.html()).toMatchSnapshot();
159+
});
160+
});

0 commit comments

Comments
 (0)