Skip to content

Commit

Permalink
Tests.Add: MissionUnpack #93.A
Browse files Browse the repository at this point in the history
  • Loading branch information
CookingWithCale committed Jan 1, 2024
1 parent ea06e0b commit c79ddbf
Show file tree
Hide file tree
Showing 25 changed files with 15,446 additions and 4,352 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: "12"

# Speed up subsequent runs with caching
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
# Install packages.
- name: Install
run: npm install

# Build project.
- name: Build
run: npm run build

# Run tests.
- name: Test
run: npm run test
2 changes: 2 additions & 0 deletions Extension/Ctlr/Background.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright AStartup; license at https://github.com/AStarStartup/AStartupMCC

import { ModelCommandStructureDefault, ModelCommandStructureSet,
ModelSessionDefault, ModelSessionSet,
ModelIssuesClosedSet,
Expand Down
2 changes: 2 additions & 0 deletions Extension/Ctlr/Content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Copyright AStartup; license at https://github.com/AStarStartup/AStartupMCC

101 changes: 92 additions & 9 deletions Extension/Model/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright AStartup; license at https://github.com/AStarStartup/AStartupMCC

export const UsernameDefault = 'CookingWithCale'

/* Data model options that do not get synced with the server. */
Expand All @@ -11,12 +13,91 @@ export interface ModelOptions {
modal_state: number //< State of the modal.
content_scripts: boolean //< Content scripts enabled.
// Options
username?: string //< AStartup username.
metric_units?: boolean //< Standard (true) or Imperial units.
crew: string //< Default crew.
session?: string //< Current session number.
project?: string //< Current project name.
mission?: string //< Current mission number.
username?: string //< Username.
session?: number //< Current session number.
account?: string //< Current account.
repo?: string //< Current repo.
mission: number //< Current mission number.
child_mission?: string //< Current child mission.
crew?: string //< Default string of crew members.
}

// Unpacks the account/repo#MissionNumber.ChildMission from the input string.
export function MissionStringUnpack(input: string) {
let state = 0
let account = ''
let repo = ''
let mission_number = ''
let child_mission = ''
let i = 0
let c: string | undefined = input[i++]
let o = '\nParsing input:"' + input + '"'
while (c != undefined) {
switch(state) {
case 0: { // Parsing org
o += '\naccount:"' + account + '" c:' + c + ' i:' + i;
if(c == '/') {
c = input[i++]
state = 1
break
}
account += c
c = input[i++]
break
}
case 1: { // Parsing repo
o += '\nrepo:"' + repo + '" c:' + c + ' i:' + i;
if(c == '#') {
c = input[i++]
state = 2
break
}
repo += c
c = input[i++]
break
}
case 2: { // Parsing mission number.
o += '\nmission_number:"' + mission_number + '" c:' + c + ' i:'
+ i;
if(c == '.') {
c = input[i++]
state = 3
break
}
if(c < '0' || c > '9') {
console.assert(c > '', 'ERROR: invalid child mission at i:'
+ i + ' c:' + c.charCodeAt(0) + ' i:' + i)
c = undefined
break
}
mission_number += c
c = input[i++]
break
}
case 3: { // Parsing Child Mission
o += '\nchild_mission:"' + child_mission + '" c:' + c + ' i:' + i;
if(c <= ' ') {
console.assert(c > '', 'ERROR: invalid child mission at i:'
+ i + ' c:' + c.charCodeAt(0))
c = undefined
break
}
child_mission += c
c = input[i++]
break
}
default: {
c = undefined
break
}
}
}
o += '\nFound account:"' + account + '" repo:"' + repo
+ '" mission_number:"' + mission_number
+ '" child_mission:"' + child_mission + '"'
console.log(o)
return [ account, repo, parseInt(mission_number), child_mission ]
}

const SessionFocusLengthMax = 100 //< Max length of a session focus heading.
Expand Down Expand Up @@ -120,15 +201,17 @@ export interface ACommandStructure {
export type ModelKeys = keyof Model

export const ModelOptionsDefault: ModelOptions = {
username: UsernameDefault,
modal_visible: false,
modal_state: 0,
content_scripts: false,
metric_units: true,
username: UsernameDefault,
session: 0,
account: '',
repo: '',
mission: 0,
child_mission: '',
crew: UsernameDefault,
session: '',
mission: '',
project: '',
}

export const ModelCommandStructureDefault = {
Expand Down
2 changes: 2 additions & 0 deletions Extension/View/Icons.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright AStartup; license at https://github.com/AStarStartup/AStartupMCC

import React from 'react'

export function IconGear() {
Expand Down
2 changes: 2 additions & 0 deletions Extension/View/OptionsEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright AStartup; license at https://github.com/AStarStartup/AStartupMCC

import { ModelAppState, ModelOptions } from '../Model'
import React, { Dispatch, useState } from "react";

Expand Down
14 changes: 9 additions & 5 deletions Extension/View/Popup.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright AStartup; license at https://github.com/AStarStartup/AStartupMCC

import React, { useEffect, useState, useReducer } from 'react';
import { createRoot } from 'react-dom/client';
import { ModelOptions, ModelOptionsDefault, ModelOptionsGet } from '../Model';
Expand All @@ -8,7 +10,7 @@ const Popup = () => {
ModelOptionsDefault);
const [IsSaving, IsSavingSet] = useState(false);
if (Options == null) return <div>Options == null</div>
let { mission, project, session, username } = Options;
let { username, session, account, repo, mission, child_mission } = Options;

useEffect(() => {
console.log('[useEffect]');
Expand All @@ -27,16 +29,18 @@ const Popup = () => {
<div className="flex">
<input type="button"value="Log In" onClick={LogInOutHandle} />
<br/>
<h1 className="Popup">{username}</h1>
<h1>{username}</h1>
<h2>Session #{session}</h2>
<h3>{account}</h3>
<h4>{repo}</h4>
<h5>{mission}</h5>
<h6>{child_mission}</h6>
<input placeholder=
"Enter the focus of the session in less than 100 characters..."
value={ Options.username }
onChange={ (event) => SessionFocusChange(event.target.value) }
disabled={ IsSaving }
/>
<h2>Session #{session}</h2>
<h3 className="Popup">{project}</h3>
<h4 className="Popup">Mission #{mission}</h4>
</div>
)
}
Expand Down
2 changes: 2 additions & 0 deletions Extension/env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright AStartup; license at https://github.com/AStarStartup/AStartupMCC

module.exports = {
NODE_ENV: process.env.NODE_ENV || 'development',
PORT: process.env.PORT || 3000,
Expand Down
15 changes: 15 additions & 0 deletions Test/TestUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright AStartup; license at https://github.com/AStarStartup/AStartupMCC

import { expect, test } from '@jest/globals';
import { MissionStringUnpack } from '../Extension/Model';

test('Utils.Tests', () => {
const Account = 'CookingWithCale'
const Repo = 'AStartupMCC'
const Mission = 420
const ChildMission = 'A'
const MissionString = Account + '/' + Repo + '#' + Mission + '.'
+ ChildMission;
let expected = [Account, Repo, Mission, ChildMission];
expect(MissionStringUnpack(MissionString)).toStrictEqual(expected);
})
Loading

0 comments on commit c79ddbf

Please sign in to comment.