diff --git a/scripts/course/course.toml b/scripts/course/course.toml index c43ea0b4..06781f85 100644 --- a/scripts/course/course.toml +++ b/scripts/course/course.toml @@ -118,7 +118,12 @@ label = "1.4" slug = "a-work-orders-day" title = "Work orders — make this many of that, this way" one_line = "Released to the floor, station to station; its good count is the last step's, not the sum." -scene = "scripts/scenes/04-work-orders-and-routings.toml" +outcomes = [ + "Say what a work order is: this many of a material, made along its routing, from release to finish.", + "Create and release an order on the Orders page, and find it in the first machine's queue on its station screen.", + "Read an order's count as its last step's, and say why it stays open past its number until a person finishes it.", +] +scene = "scripts/scenes/course/02-04-a-work-orders-day.toml" # ------------------------------------------------------------------ tier 2 [[module]] diff --git a/scripts/record-scene.py b/scripts/record-scene.py index 23854350..1301ae02 100644 --- a/scripts/record-scene.py +++ b/scripts/record-scene.py @@ -677,11 +677,17 @@ def clear_of_caption(self, selector: str) -> None: pressed. When the thing is under the bar, room is added once below the page's last row and the thing is put in the middle of the window. A thing already clear is left where it is, so no other take moves. + + The thing is found the way the click will find it, by Playwright's + own locator: a scene's selector may say `:has-text("Release")`, which + `document.querySelector` refuses as no selector at all (the first take + of class 1.4 stopped on its Release button for that reason). """ - self.page.evaluate( - """([selector, bar]) => { - const node = document.querySelector(selector); - if (!node) return; + found = self.page.locator(selector) + if not found.count(): + return + found.first.evaluate( + """(node, bar) => { const box = node.getBoundingClientRect(); if (box.bottom <= window.innerHeight - bar) return; if (!document.getElementById('fs-scene-room')) { @@ -692,7 +698,7 @@ def clear_of_caption(self, selector: str) -> None: } node.scrollIntoView({ block: 'center', behavior: 'instant' }); }""", - [selector, CAPTION_HEIGHT * 2], + CAPTION_HEIGHT * 2, ) def wait_for(self, step: dict, timeout: float) -> None: diff --git a/scripts/scenes/course/02-04-a-work-orders-day.toml b/scripts/scenes/course/02-04-a-work-orders-day.toml new file mode 100644 index 00000000..e94ef3e9 --- /dev/null +++ b/scripts/scenes/course/02-04-a-work-orders-day.toml @@ -0,0 +1,449 @@ +# Class 1.4 of the course, *Work orders — make this many of that, this way*: +# an order is released to the floor, runs station to station, and is finished +# by a person, not by its count. +# +# It starts from the card a bin carries on a floor, names the four words of an +# order's life (order, release, dispatch, finish), types a new order for forks +# into the Orders page and releases it, finds it in the mould's queue on its +# station screen, and reads the plant's own fork order step by step, its good +# count the last step's. Then what an order refuses: it has passed its number +# and is still open, because reaching the quantity is not being finished +# (decision 0029). A person finishes it, and the confirmation for the office is +# in the outbox. Filmed on a scratch cutlery plant, every screen as the product +# draws it. + +name = "a-work-orders-day" +title = "Work orders — make this many of that, this way" +lesson = "1.4" +take_is = "lesson" +part = "hook" +base = "http://127.0.0.1:8040" +badge = "pre-alpha · simulated plant · v{version}" +# Four to six minutes, as the outline says this class runs. +budget_seconds = 360 +gif_skip_seconds = 2.0 +width = 1280 +height = 720 +# Creating, releasing and finishing an order are writes, and they are the story. +allow_writes = true +what_is_written = "which is how the class creates and releases its order and finishes the plant's: Create, Release and each Finish step are real `POST`s to the take's own scratch plant, made with the product's own buttons, and its audit trail names the person signed in as having made them." + +notes = [ + "The plant was started from the cutlery pack at ten times wall clock. The camera waited, off camera, until the pack's own released fork order, WO-FORK1-0001 for 2,778 forks, had booked 2,400 of them, so that by the time the class reaches it the line has run past its number on camera's side of the cut.", + "The simulated floor was told `MES_OPS_FINISH_ORDERS=false`. Its simulated shift supervisor otherwise finishes an order soon after the line has made its number and releases the next one himself: he would have finished, off camera, the very order this class shows a person finishing. The switch belongs to the simulated floor (it is the one `fsmes lab` uses for its over-run experiment); the MES is configured as anybody installs it.", + "The order typed in is WO-FORK1-0100 for 11,000 forks of UT-FORK, a code the pack does not have, outside the planner's own sequence (it continues WO-FORK1-0003, 0004, ...). 11,000 is about one eight-hour shift of the fork line, which the pack rates at a little over twenty-three forks a minute; the pack's own orders are for two hours, 2,778. The form has no routing or line to choose: the order's steps are copied from the material's first routing, RT-FORK1, which is the fork line's.", + "The order is created with the form's Release box unticked, so that release is its own press on camera, the Release button, rather than a side effect of Create.", + "The finish beat is filmed on the plant's own WO-FORK1-0001, which was released when the plant started and was far along when the camera rolled; the order typed in the class would take hours at this speed. The person finishes its three steps one by one with the orders page's Finish step button.", + "The outbox is opened right after the order completes, so that its confirmation is among the newest twenty messages the panel draws; the rest are the machines' state changes, which are most of what a plant sends.", + "At any speed but 1x every 2D page carries the product's REPLAY 10× banner across its top. It is filmed as the product draws it.", + "The opening beat is a plain card with words on it. There is no artwork of a card, a bin, a machine or a person.", +] + +honesty = [ + "the order typed in is not the one finished: finishing is filmed on the plant's own fork order, WO-FORK1-0001, released when the plant started and far along when the camera rolled, because an order for a shift does not run out in a five-minute class", + "the form chooses no routing: a new order takes its material's first routing, and for forks that is RT-FORK1, the fork line's; the class says the steps were copied from the fork line's routing, not that the planner picked a line", + "the simulated floor was told not to finish orders itself (MES_OPS_FINISH_ORDERS=false), so the order on camera stays open past its number until the person on camera finishes it; on a plant left to itself the simulated supervisor would have closed it", + "the outbox panel draws the newest twenty messages, most of them machine state changes; the confirmation is in view only because the class opens the panel seconds after the order completes; the card already open about that panel stands", + "the plant is a scratch plant a few minutes old, replaying at ten times wall clock, which is the banner across the top of the 2D pages", +] + +[plant] +pack = "labs/cutlery" +speed = 10 +env = { MES_OPS_FINISH_ORDERS = "false" } +roll_when_timeout_seconds = 1800 + +# Short of its 2,778, so the count passes the number while the class is on it. +[[plant.roll_when_order]] +code = "WO-FORK1-0001" +booked = 2400 + +# ----------------------------------------------------------------- the hook + +[[step]] +do = "slide" +name = "the-card-on-the-bin" +title = "The card clipped to a bin" +lines = [ + "Make: forks, UT-FORK", + "How many: 2,778", + "This way: Mold, then Degate, then Mark", + "Done when somebody signs it off", +] +hold = 1.5 + +[[step]] +do = "say" +line = "On a floor, a bin of work carries a card. It says what to make, how many, and which way." + +[[step]] +do = "say" +line = "Every station the bin passes reads the card, and writes down beside its own step how many good it made." + +[[step]] +do = "say" +line = "The card never counts itself done. At the end, somebody signs it off. That card is a work order." + +[[step]] +do = "mark" +name = "the-card-on-the-bin" + +# ----------------------------------------------------------------- the idea + +[[step]] +part = "idea" +do = "slide" +name = "four-words" +title = "Four words" +lines = [ + "Order: make this many of that material, this way (its routing)", + "Release: the order may now go to the floor", + "Dispatch: each machine's queue shows the work it has next", + "Finish: a person says a step, and then the order, is done", +] +hold = 1.5 + +[[step]] +do = "say" +line = "Four words. An order says make this many of that material, this way. This way is its routing, the road from the last class." + +[[step]] +do = "say" +line = "Release means the order may now go to the floor. Until then it is a plan, and no machine works on it." + +[[step]] +do = "say" +line = "Dispatch is each machine's queue: the work it has next, in order. And finish is a person saying a step is done, and then the order." + +[[step]] +do = "mark" +name = "four-words" + +# ------------------------------------------------------------ on the screen + +[[step]] +part = "screen" +do = "goto" +url = "/dashboard/orders" +settle = 2 + +[[step]] +do = "wait_for" +js = "document.querySelector('#new-order-form').classList.contains('hidden') && document.querySelectorAll('#order-list tbody tr').length > 0" + +[[step]] +do = "say" +line = "This is the Orders page. Every order on the plant, its status, what was ordered and what has been booked." + +[[step]] +do = "mark" +name = "the-orders-page" + +[[step]] +do = "say" +line = "A planner makes a new one. New order: a code, the material, and how many." + +[[step]] +do = "click" +selector = "#new-order" + +[[step]] +do = "fill" +selector = "#no-code" +text = "WO-FORK1-0100" + +[[step]] +do = "choose" +selector = "#no-material" +value = "UT-FORK" + +[[step]] +do = "fill" +selector = "#no-qty" +text = "11000" + +[[step]] +do = "say" +line = "Forks, UT-FORK. Eleven thousand: about one shift of the fork line, at some twenty-three forks a minute." + +[[step]] +do = "click" +selector = "#no-release" + +[[step]] +do = "say" +line = "We leave release unticked, so the order is only planned for now. Create." + +[[step]] +do = "mark" +name = "the-new-order-form" + +[[step]] +do = "click" +selector = "#no-create" + +[[step]] +do = "wait_for" +js = "document.querySelector('#detail-code').innerText === 'WO-FORK1-0100' && document.querySelector('#d-status').innerText === 'planned' && document.querySelectorAll('#ops tbody tr').length === 3" +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "Planned. Its steps were copied from the fork line's routing: Mold, Degate, Mark, each on its machine." + +[[step]] +do = "mark" +name = "planned-with-its-steps" + +[[step]] +do = "say" +line = "Now release it to the floor." + +[[step]] +do = "click" +selector = "#order-actions button:has-text(\"Release\")" + +[[step]] +do = "wait_for" +selector = "#d-status" +text = "released" + +[[step]] +do = "say" +line = "Released. Nothing has been made against it yet. Where does it show up? At the first machine of its road." + +[[step]] +do = "mark" +name = "released" + +[[step]] +do = "goto" +url = "/dashboard/station?m=FORK1_Mold" +settle = 3 + +[[step]] +do = "wait_for" +selector = "#queue" +text = "WO-FORK1-0100" +scroll_to = "#queue" +scroll_block = "start" +scroll_offset = 260 + +[[step]] +do = "say" +line = "The station screen of the fork mould, FORK1_Mold. Its queue: the order it is running now, and ours behind it, nothing made yet." + +[[step]] +do = "say" +line = "That is dispatch. The operator does not hunt for paper: the machine's screen says what is next." + +[[step]] +do = "say" +line = "Each line of the queue says how many good of how many ordered. The next machine, the degating press, gets our order the same way." + +[[step]] +do = "mark" +name = "in-the-moulds-queue" + +[[step]] +do = "goto" +url = "/dashboard/orders?q=WO-FORK1-0001" +settle = 2 + +[[step]] +do = "click" +selector = "#order-list tbody tr:has-text(\"WO-FORK1-0001\")" + +[[step]] +do = "wait_for" +js = "document.querySelector('#detail-code').innerText === 'WO-FORK1-0001' && document.querySelector('#d-status').innerText === 'running' && document.querySelectorAll('#ops tbody tr').length === 3" +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "The order in front of ours, WO-FORK1-0001, for 2,778 forks, released when the plant started. It is running." + +[[step]] +do = "mark" +name = "the-running-order" + +[[step]] +do = "wait_for" +selector = "#ops tbody" +text = "Mark" +scroll_to = "#ops" +scroll_block = "start" +scroll_offset = 230 + +[[step]] +do = "say" +line = "Each step books what its own machine counted. Mold has made the most, then Degate, then Mark, the last." + +[[step]] +do = "say" +line = "The order's booked count is the last step's, not the sum. A fork moulded but not yet marked is not a finished fork." + +[[step]] +do = "mark" +name = "each-step-its-own-count" + +# -------------------------------------------------------------- it refuses + +[[step]] +part = "refuses" +do = "wait_for" +js = "Number((document.querySelector('#d-good').innerText || '').replace(/[^0-9.]/g, '')) > Number((document.querySelector('#d-qty').innerText || '').replace(/[^0-9.]/g, ''))" +timeout = 240 +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "Now what it refuses. The order has booked past its 2,778, the over-run says by how many, and it is still running." +hold = 1.0 + +[[step]] +do = "mark" +name = "past-its-number-still-open" + +[[step]] +do = "say" +line = "An order does not finish itself when the count is reached. A line that has made its number is often still running." + +[[step]] +do = "say" +line = "So every fork it makes past the number is booked to this order, and the over-run is the true one. A person closes it." + +[[step]] +do = "say" +line = "Here that person finishes each step. Mold first." + +[[step]] +do = "click" +selector = "#ops tbody tr:has-text(\"Mold\") button:has-text(\"Finish step\")" + +[[step]] +do = "wait_for" +js = "[...document.querySelectorAll('#ops tbody tr')].some(r => r.innerText.includes('Mold') && r.innerText.toLowerCase().includes('done'))" + +[[step]] +do = "say" +line = "Mold is done. The mould's next fork books to the order behind it in its queue, ours." + +[[step]] +do = "click" +selector = "#ops tbody tr:has-text(\"Degate\") button:has-text(\"Finish step\")" + +[[step]] +do = "wait_for" +js = "[...document.querySelectorAll('#ops tbody tr')].some(r => r.innerText.includes('Degate') && r.innerText.toLowerCase().includes('done'))" + +[[step]] +do = "click" +selector = "#ops tbody tr:has-text(\"Mark\") button:has-text(\"Finish step\")" + +[[step]] +do = "wait_for" +selector = "#d-status" +text = "completed" +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "Degate, then Mark. Completed." + +[[step]] +do = "mark" +name = "finished-by-a-person" + +# The outbox draws its newest twenty messages and the machines send about two +# state changes a second, so it is opened at once, before anything is said +# about the order: twenty seconds later the confirmation has scrolled off the +# panel (the third take). A step scrolls before it waits, so the row is waited +# for first and scrolled to by a second wait that finds it already there. +[[step]] +do = "goto" +url = "/dashboard/ops" +settle = 0.5 + +[[step]] +do = "wait_for" +selector = "#erp-table tbody" +text = "WO-FORK1-0001" +timeout = 15 + +[[step]] +do = "wait_for" +selector = "#erp-table tbody" +text = "WO-FORK1-0001" +scroll_to = "#erp-table tr" +scroll_text = "WO-FORK1-0001" +scroll_offset = 300 + +[[step]] +do = "mark" +name = "the-confirmation-in-the-outbox" + +[[step]] +do = "say" +line = "And the news goes up. In the outbox, a confirmation for the office, among the machines' state changes: WO-FORK1-0001, waiting to be sent." + +[[step]] +do = "say" +line = "It was written when a person finished the order, not when the count passed the number. So the office hears the number the line really made." + +[[step]] +do = "goto" +url = "/dashboard/orders?q=WO-FORK1-0001" +settle = 2 + +[[step]] +do = "click" +selector = "#order-list tbody tr:has-text(\"WO-FORK1-0001\")" + +[[step]] +do = "wait_for" +js = "document.querySelector('#detail-code').innerText === 'WO-FORK1-0001' && document.querySelector('#d-status').innerText === 'completed'" +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "Back on the order: completed. The over-run beside the ordered number is every fork made past 2,778, still on the order that made them." + +[[step]] +do = "mark" +name = "completed-with-its-over-run" + +# ------------------------------------------------------------ you now know + +[[step]] +part = "know" +do = "slide" +name = "you-now-know" +title = "You now know how to" +lines = [ + "Say what a work order is: this many of a material, made along its routing, from release to finish.", + "Create and release an order on the Orders page, and find it in the first machine's queue on its station screen.", + "Read an order's count as its last step's, and say why it stays open past its number until a person finishes it.", +] + +[[step]] +do = "say" +line = "That is a work order's day: planned, released, dispatched, counted step by step, and finished by a person. You now know how to do three things." + +[[step]] +do = "mark" +name = "you-now-know" + +[[step]] +do = "hold" +seconds = 3 diff --git a/tests/test_a_scene_brings_a_button_named_by_its_words_clear_of_the_caption_bar.py b/tests/test_a_scene_brings_a_button_named_by_its_words_clear_of_the_caption_bar.py new file mode 100644 index 00000000..96334697 --- /dev/null +++ b/tests/test_a_scene_brings_a_button_named_by_its_words_clear_of_the_caption_bar.py @@ -0,0 +1,69 @@ +"""A button a scene names by its words is brought out from under the caption bar before it is pressed. + +Before a click, fill or choose the recorder moves the thing out from under +the caption bar (class 1.3's "Add operation"). Scenes name buttons by their +words, `#order-actions button:has-text("Release")`, which only Playwright's +own locator reads: the first take of class 1.4 stopped on its Release button +because the move looked the selector up with `document.querySelector`. This +drives the runner's own stage in Chromium against a page of that shape; no +plant is needed. +""" + +from __future__ import annotations + +import importlib.util +from pathlib import Path + +import pytest + +pytestmark = [pytest.mark.slow, pytest.mark.browser] + +REPO = Path(__file__).resolve().parents[1] +RUNNER = REPO / "scripts" / "record-scene.py" + +VIEWPORT = {"width": 800, "height": 600} +# The Release button at the very foot of a page too short to scroll it higher. +PAGE = ( + "
the order
" + "
" +) + + +@pytest.fixture(scope="module") +def runner(): + spec = importlib.util.spec_from_file_location("record_scene_clear_of_caption", RUNNER) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def test_a_button_named_with_has_text_at_the_foot_of_a_page_ends_up_above_the_caption_bar(runner, tmp_path): + from playwright.sync_api import sync_playwright + + with sync_playwright() as pw: + browser = pw.chromium.launch() + page = browser.new_page(viewport=VIEWPORT) + page.set_content(PAGE) + button = page.locator('#order-actions button:has-text("Release")') + clear = VIEWPORT["height"] - runner.CAPTION_HEIGHT * 2 + assert button.bounding_box()["y"] + button.bounding_box()["height"] > clear + + runner.BrowserStage(page, tmp_path, 0.0).clear_of_caption('#order-actions button:has-text("Release")') + + box = button.bounding_box() + assert box["y"] + box["height"] <= clear + browser.close() + + +def test_a_selector_that_matches_nothing_yet_is_left_for_the_step_itself_to_wait_on(runner, tmp_path): + from playwright.sync_api import sync_playwright + + with sync_playwright() as pw: + browser = pw.chromium.launch() + page = browser.new_page(viewport=VIEWPORT) + page.set_content(PAGE) + + runner.BrowserStage(page, tmp_path, 0.0).clear_of_caption('#order-actions button:has-text("Close")') + + assert page.evaluate("document.getElementById('fs-scene-room')") is None + browser.close() diff --git a/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py b/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py new file mode 100644 index 00000000..ff5c763d --- /dev/null +++ b/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py @@ -0,0 +1,277 @@ +"""Class 1.4 releases a work order to the floor and a person, not its count, finishes one, on a scratch cutlery plant. + +*Work orders — make this many of that, this way* is the second class of the +core: the card a bin carries, the four words of an order's life (order, +release, dispatch, finish), a new fork order typed into the Orders page and +released, the same order in the mould's queue on its station screen, the +plant's own fork order read step by step with its count the last step's, and +the thing an order refuses: it does not finish itself at its quantity +(decision 0029), so a person finishes it and the confirmation goes to the +outbox. This file holds the scene file to what the outline asks of it. No +plant and no browser: the scene is loaded and walked the way the recorder +walks it. +""" + +from __future__ import annotations + +import importlib.util +import json +import re +from pathlib import Path +from urllib.parse import urlparse + +import pytest + +from fsmes import modules + +REPO = Path(__file__).resolve().parents[1] +RUNNER = REPO / "scripts" / "record-scene.py" +SCENE = REPO / "scripts" / "scenes" / "course" / "02-04-a-work-orders-day.toml" +PACK = REPO / "labs" / "cutlery" / "masterdata" + +# The lab fleet, the public demo and the stock demo ports: a class is never +# filmed on a plant somebody else is looking at. +NOT_OURS = {8090, 8110, 8120, 8140, 9030, 5433, 5434, 4944, 4945} + +# What no caption, card or note may carry: a calendar date, a year, a month's +# name. The class is about any plant on any day. +A_DATE = re.compile( + r"\b(19|20)\d\d\b|\b\d{1,2}/\d{1,2}/\d{2,4}\b|" + r"\b(January|February|March|April|May|June|July|August|September|October|November|December)\b" +) + + +@pytest.fixture(scope="module") +def runner(): + """`scripts/record-scene.py`, imported by path because of the hyphen.""" + spec = importlib.util.spec_from_file_location("record_scene_class_1_4", RUNNER) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +@pytest.fixture(scope="module") +def scene(runner): + return runner.load_scene(SCENE) + + +def pack(kind: str) -> list[dict]: + return json.loads((PACK / f"{kind}.json").read_text(encoding="utf-8")) + + +def everything_written(scene: dict) -> list[str]: + """Every sentence a viewer or a reader of the folder will see.""" + written = [scene["title"], scene["what_is_written"], *scene["notes"], *scene["honesty"]] + for step in scene["step"]: + if step["do"] == "say": + written.append(step["line"]) + if step["do"] == "slide": + written += [step["title"], *step["lines"]] + if step["do"] == "fill": + written.append(step["text"]) + return written + + +def typed(scene: dict, part: str) -> list[str]: + return [step["text"] for step in scene["step"] if step["part"] == part and step["do"] == "fill"] + + +def chosen(scene: dict, part: str) -> list[str]: + return [step["value"] for step in scene["step"] if step["part"] == part and step["do"] == "choose"] + + +def steps_of(scene: dict, part: str) -> list[dict]: + return [step for step in scene["step"] if step["part"] == part] + + +def fork_routing() -> dict: + return next(r for r in pack("routings") if r["code"] == "RT-FORK1") + + +def test_the_scene_is_a_full_take_of_class_1_4_named_by_its_label_that_runs_four_to_six_minutes(runner, scene): + assert scene["lesson"] == "1.4" and scene["take_is"] == "lesson" + assert (scene["width"], scene["height"]) == (1280, 720) + planned = runner.planned_seconds(scene) + # Page loads and waits add to the plan; the finished take is measured. + assert 240 <= planned <= scene["budget_seconds"] <= 360, planned + print(f"planned {planned} s against a {scene['budget_seconds']} s budget") + + +def test_it_films_into_the_work_orders_folder_of_the_core_and_leaves_the_draft_one_scene_alone(runner, scene): + course = runner.load_course(REPO / "scripts" / "course" / "course.toml") + _, lesson = runner.find_lesson(course, scene["lesson"]) + + assert lesson["path"] == "02-the-core/04-a-work-orders-day" + assert lesson["scene"] == SCENE.relative_to(REPO).as_posix() + # The draft-1 teaser's scene stays on disk, filming into its own folder. + old = runner.load_scene(REPO / "scripts" / "scenes" / "04-work-orders-and-routings.toml") + assert old["take_is"] == "teaser" + + +def test_the_scene_walks_the_five_parts_in_order(runner, scene): + order = [] + for step in scene["step"]: + if not order or order[-1] != step["part"]: + order.append(step["part"]) + + assert order == list(runner.PARTS) + + +def test_the_hook_is_a_card_of_what_a_bin_carries_in_the_fork_lines_steps_short_enough_for_the_teaser(runner, scene): + hook = steps_of(scene, "hook") + order = next(o for o in pack("work_orders") if o["code"] == "WO-FORK1-0001") + + assert hook[0]["do"] == "slide" and hook[0]["name"] == "the-card-on-the-bin" + card = " ".join(hook[0]["lines"]) + assert all(op["name"] in card for op in fork_routing()["operations"]) + assert f"{order['quantity']:,}" in card and order["material"] in card + assert not [step for step in hook if step["do"] == "goto"] + assert runner.planned_seconds(dict(scene, step=hook)) - scene["gif_skip_seconds"] <= 30 + + +def test_the_idea_card_names_order_release_dispatch_and_finish(scene): + cards = [step for step in steps_of(scene, "idea") if step["do"] == "slide"] + + assert len(cards) == 1 + assert [line.split(":")[0] for line in cards[0]["lines"]] == ["Order", "Release", "Dispatch", "Finish"] + + +def test_the_order_typed_in_is_not_in_the_pack_is_for_the_plants_forks_and_is_about_a_shift_of_the_line(scene): + screen_typed, screen_chosen = typed(scene, "screen"), chosen(scene, "screen") + code, quantity = screen_typed + orders = {o["code"]: o for o in pack("work_orders")} + materials = {m["code"] for m in pack("materials")} + + assert code.startswith("WO-FORK1-") and code not in orders + assert screen_chosen == ["UT-FORK"] and "UT-FORK" in materials + # The pack's own orders are two hours of the line; a shift is eight. + shift = orders["WO-FORK1-0001"]["quantity"] * 4 + assert abs(int(quantity) - shift) / shift < 0.05, (quantity, shift) + + +def test_the_order_is_created_planned_and_released_by_its_own_button(scene): + screen = steps_of(scene, "screen") + clicks = [step["selector"] for step in screen if step["do"] == "click"] + create = next(i for i, step in enumerate(screen) if step["do"] == "click" and step["selector"] == "#no-create") + release = next(i for i, step in enumerate(screen) if step["do"] == "click" and "Release" in step["selector"]) + + # The form's Release box is unticked before Create, so release is a press of its own. + assert clicks.index("#no-release") < clicks.index("#no-create") + assert "'planned'" in screen[create + 1]["js"] + assert screen[release + 1] == {**screen[release + 1], "selector": "#d-status", "text": "released"} + + +def test_the_released_order_is_found_in_the_queue_of_the_first_machine_on_its_routing(scene): + screen = steps_of(scene, "screen") + first = min(fork_routing()["operations"], key=lambda op: op["seq"])["equipment"] + code = typed(scene, "screen")[0] + station = next(i for i, step in enumerate(screen) if step["do"] == "goto" and "/station" in step["url"]) + + assert screen[station]["url"] == f"/dashboard/station?m={first}" + assert screen[station + 1]["selector"] == "#queue" and screen[station + 1]["text"] == code + + +def test_the_order_finished_is_the_packs_own_fork_order_and_the_floor_is_told_not_to_finish_it(scene): + order = next(o for o in pack("work_orders") if o["code"] == "WO-FORK1-0001") + (wanted,) = scene["plant"]["roll_when_order"] + + assert order["release"] and order["material"] == fork_routing()["material"] + assert wanted["code"] == order["code"] and 0 < wanted["booked"] < order["quantity"] + assert scene["plant"]["env"] == {"MES_OPS_FINISH_ORDERS": "false"} + + +def test_what_it_refuses_is_finishing_at_the_count_so_a_person_finishes_every_step_and_the_outbox_has_it(scene): + refuses = steps_of(scene, "refuses") + said = " ".join(step["line"] for step in refuses if step["do"] == "say") + finished = [step["selector"] for step in refuses if step["do"] == "click" and "Finish step" in step["selector"]] + + # It opens on the count past the ordered quantity with the order still open. + assert refuses[0]["do"] == "wait_for" and "#d-good" in refuses[0]["js"] and "#d-qty" in refuses[0]["js"] + assert "does not finish itself" in said and "A person closes it" in said + assert finished == [ + f'#ops tbody tr:has-text("{op["name"]}") button:has-text("Finish step")' + for op in sorted(fork_routing()["operations"], key=lambda op: op["seq"]) + ] + # The outbox is opened right after the last step is finished, before the + # confirmation scrolls off its newest twenty; the row is waited for, then + # scrolled to, because a step scrolls before it waits. + outbox = next(i for i, step in enumerate(refuses) if step["do"] == "goto" and step["url"] == "/dashboard/ops") + assert finished[-1] in [step.get("selector") for step in refuses[outbox - 4 : outbox]] + assert [(w["selector"], w["text"], bool(w.get("scroll_to"))) for w in refuses[outbox + 1 : outbox + 3]] == [ + ("#erp-table tbody", "WO-FORK1-0001", False), + ("#erp-table tbody", "WO-FORK1-0001", True), + ] + # And the order is seen completed afterwards, its over-run beside it. + assert any("'completed'" in step.get("js", "") for step in refuses[outbox:]) + + +def test_the_you_now_know_card_says_the_classs_own_outcomes_word_for_word(runner, scene): + course = runner.load_course(REPO / "scripts" / "course" / "course.toml") + _, lesson = runner.find_lesson(course, scene["lesson"]) + know = [step for step in steps_of(scene, "know") if step["do"] == "slide"] + + assert len(lesson["outcomes"]) == 3 + assert len(know) == 1 and know[0]["lines"] == lesson["outcomes"] + + +def test_every_page_it_visits_is_a_screen_the_app_serves(scene): + served = [page.path for module in modules.REGISTRY for page in module.pages] + patterns = [re.compile("^" + re.sub(r"\{[^}]+\}", "[^/]+", path) + "$") for path in served] + visited = {urlparse(step["url"]).path for step in scene["step"] if step["do"] == "goto"} + + unserved = sorted(path for path in visited if not any(p.match(path) for p in patterns)) + assert unserved == [], f"{len(unserved)} of {len(visited)} pages are not served: {unserved}" + + +def test_every_frame_carries_the_pre_alpha_simulated_plant_badge(scene): + assert scene["badge"] == "pre-alpha · simulated plant · v{version}" + + +def test_no_caption_card_note_or_typed_word_carries_a_date(scene): + dated = [line for line in everything_written(scene) if A_DATE.search(line)] + + assert dated == [], f"{len(dated)} lines carry a date: {dated}" + + +def test_it_is_filmed_on_a_scratch_cutlery_plant_on_loopback_and_never_on_one_somebody_else_runs(runner, scene): + base = urlparse(scene["base"]) + + assert scene["plant"]["pack"] == "labs/cutlery" + assert base.hostname == "127.0.0.1" + assert base.port not in NOT_OURS + # It writes, so it must be refused anywhere but loopback. + assert scene["allow_writes"] + runner.refuse_to_write_off_this_box(scene) + with pytest.raises(SystemExit): + runner.refuse_to_write_off_this_box(dict(scene, base="http://100.64.0.1:8040")) + + +def test_the_borrowed_order_the_floor_switch_the_outbox_and_the_replay_are_owned_up_to(scene): + honesty = " ".join(scene["honesty"]).lower() + + assert "wo-fork1-0001" in honesty + assert "mes_ops_finish_orders=false" in honesty + assert "newest twenty" in honesty + assert "first routing" in honesty + assert "ten times" in honesty + + +def test_no_screen_of_people_is_filmed_and_admin_is_not_opened(scene): + urls = [step["url"] for step in scene["step"] if step["do"] == "goto"] + + assert not [url for url in urls if "people" in url or "/admin" in url] + + +def test_the_recorder_plays_every_step_of_it(runner, scene): + handed: list[str] = [] + + class Stage: + def __getattr__(self, verb): + return lambda *args: handed.append(verb) + + runner.play(scene, Stage()) + + for verb in ("goto", "click", "fill", "choose"): + assert handed.count(verb) == sum(1 for step in scene["step"] if step["do"] == verb), verb + assert handed.count("scroll_to") == sum(1 for step in scene["step"] if step.get("scroll_to")) + assert handed.count("slide") == 3 and "terminal" not in handed