Skip to content

Commit 5e5035f

Browse files
committed
Add tests for the various counter-based stories
1 parent 8445717 commit 5e5035f

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

tests/html.test.tsx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,87 @@ const storyTests: Record<string, (result: RenderResult) => void | Promise<void>>
7777
expect(secondTableBodyAfter?.innerHTML).toContain('Cell 2');
7878
expect(secondTableBodyAfter?.innerHTML).toContain('Cell 3');
7979
},
80+
'PersistComponentStateWhilstMoving': async ({ container, getByText }) => {
81+
expect(container.textContent).toContain('Count is 0');
82+
83+
const incrementButton = getByText('+1');
84+
incrementButton.click();
85+
await wait(10);
86+
87+
expect(container.textContent).toContain('Count is 1');
88+
89+
const moveButton = getByText('Click to move the OutPortal');
90+
moveButton.click();
91+
await wait(10);
92+
93+
expect(container.textContent).toContain('Count is 1');
94+
95+
incrementButton.click();
96+
await wait(10);
97+
98+
expect(container.textContent).toContain('Count is 2');
99+
},
100+
'CanSetPropsRemotelyWhilstMoving': async ({ container, getAllByText }) => {
101+
expect(container.textContent).toContain('Count is 0');
102+
103+
const counterDiv = container.querySelector('div[style*="background-color"]');
104+
expect(counterDiv?.style.backgroundColor).toBe('rgb(170, 255, 170)');
105+
106+
const incrementButton = counterDiv?.querySelector('button');
107+
expect(incrementButton).not.toBeNull();
108+
incrementButton!.click();
109+
await wait(10);
110+
111+
expect(container.textContent).toContain('Count is 1');
112+
113+
const moveButtons = getAllByText('Click to move the OutPortal');
114+
moveButtons[1].click();
115+
await wait(10);
116+
117+
expect(container.textContent).toContain('Count is 1');
118+
119+
const counterDivAfter = container.querySelector('div[style*="background-color"]');
120+
expect(counterDivAfter?.style.backgroundColor).toBe('rgb(170, 170, 255)');
121+
122+
const incrementButtonAfter = counterDivAfter?.querySelector('button');
123+
incrementButtonAfter!.click();
124+
await wait(10);
125+
126+
expect(container.textContent).toContain('Count is 2');
127+
},
128+
'CanSwitchBetweenPortalsSafely': async ({ container, getByText }) => {
129+
expect(container.textContent).toContain('Count is 0');
130+
131+
const incrementButtons = container.querySelectorAll('button');
132+
const incrementButton = Array.from(incrementButtons).find(btn => btn.textContent === '+1');
133+
expect(incrementButton).not.toBeNull();
134+
135+
incrementButton!.click();
136+
await wait(10);
137+
138+
expect(container.textContent).toContain('Count is 1');
139+
140+
const swapButton = getByText('Click to swap the portal shown');
141+
swapButton.click();
142+
await wait(10);
143+
144+
expect(container.textContent).toContain('Count is 0');
145+
146+
const incrementButtonAfterSwap = Array.from(container.querySelectorAll('button')).find(
147+
btn => btn.textContent === '+1'
148+
);
149+
incrementButtonAfterSwap!.click();
150+
await wait(10);
151+
incrementButtonAfterSwap!.click();
152+
await wait(10);
153+
154+
expect(container.textContent).toContain('Count is 2');
155+
156+
swapButton.click();
157+
await wait(10);
158+
159+
expect(container.textContent).toContain('Count is 1');
160+
},
80161
};
81162

82163
// Skipped for now, until we have full test coverage of the stories:

0 commit comments

Comments
 (0)