mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
overhauling steps 4-6, part 1
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { TestMe } from './TestMe';
|
||||
|
||||
describe('TestMe Component', () => {
|
||||
it('should render correctly when hovered', () => {
|
||||
// TODO:
|
||||
// 1. mount a <TestMe> Component here
|
||||
// 2. use enzyme wrapper's find() method to retrieve the #innerMe element
|
||||
// 3. simulate a hover with "mouseover" event via the simulate() API
|
||||
// 4. make assertions with expect on the text() of the #innerMe element
|
||||
});
|
||||
});
|
||||
@@ -1,37 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
export interface TestMeProps {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface TestMeState {
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export const TestMe = (props: TestMeProps) => {
|
||||
return (
|
||||
<div id="testMe">
|
||||
<InnerMe name={props.name} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export class InnerMe extends React.Component<TestMeProps, TestMeState> {
|
||||
state = {
|
||||
enabled: false
|
||||
};
|
||||
|
||||
onMouseOver = () => {
|
||||
this.setState({ enabled: true });
|
||||
};
|
||||
|
||||
render() {
|
||||
return !this.state.enabled ? (
|
||||
<div onMouseOver={this.onMouseOver} id="innerMe">
|
||||
Hello {this.props.name}, Hover Over Me
|
||||
</div>
|
||||
) : (
|
||||
<div id="innerMe">Enabled</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export { Stack } from './stack';
|
||||
export { TestMe } from './TestMe';
|
||||
@@ -1,18 +0,0 @@
|
||||
// TODO: Import the stack here
|
||||
|
||||
describe('Stack', () => {
|
||||
it('should push item to the top of the stack', () => {
|
||||
// TODO: implement test here:
|
||||
// 1. Instantiate a new Stack - i.e. const stack = new Stack<number>();
|
||||
// 2. Use stack push calls to add some items to the stack
|
||||
// 3. Write assertions via the expect() API
|
||||
});
|
||||
|
||||
it('should pop the item from the top of stack', () => {
|
||||
// TODO: implement test here:
|
||||
// 1. Instantiate a new Stack - i.e. const stack = new Stack<number>();
|
||||
// 2. Use stack push calls to add some items to the stack
|
||||
// 3. pop a few items off the stack
|
||||
// 4. write assertions via the expect() API
|
||||
});
|
||||
});
|
||||
@@ -1,27 +0,0 @@
|
||||
export class Stack<T> {
|
||||
private _items: T[] = [];
|
||||
|
||||
/** Add an item to the top of the stack. */
|
||||
push(item: T) {
|
||||
this._items.push(item);
|
||||
}
|
||||
|
||||
/** Remove the top item from the stack and return it. */
|
||||
pop(): T {
|
||||
if (this._items.length > 0) {
|
||||
return this._items.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/** Return the top item from the stack without removing it. */
|
||||
peek(): T {
|
||||
if (this._items.length > 0) {
|
||||
return this._items[this._items.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the number of items in the stack/ */
|
||||
get count(): number {
|
||||
return this._items.length;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user