@operato/context 10.29.70 → 10.29.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@operato/context",
3
3
  "description": "Webcomponent context following open-wc recommendations",
4
4
  "author": "heartyoh",
5
- "version": "10.29.70",
5
+ "version": "10.29.71",
6
6
  "type": "module",
7
7
  "main": "dist/src/index.js",
8
8
  "module": "dist/src/index.js",
@@ -67,12 +67,12 @@
67
67
  },
68
68
  "dependencies": {
69
69
  "@material/web": "^2.0.0",
70
- "@operato/help": "^10.29.70",
71
- "@operato/input": "^10.29.70",
72
- "@operato/layout": "^10.29.70",
73
- "@operato/shell": "^10.29.70",
74
- "@operato/styles": "^10.29.70",
75
- "@operato/utils": "^10.29.69",
70
+ "@operato/help": "^10.29.71",
71
+ "@operato/input": "^10.29.71",
72
+ "@operato/layout": "^10.29.71",
73
+ "@operato/shell": "^10.29.71",
74
+ "@operato/styles": "^10.29.71",
75
+ "@operato/utils": "^10.29.71",
76
76
  "lit": "^3.1.2",
77
77
  "lodash-es": "^4.17.21"
78
78
  },
@@ -108,5 +108,5 @@
108
108
  "prettier --write"
109
109
  ]
110
110
  },
111
- "gitHead": "7451d7242ca5e396bbdeb89fc46470d52c89e8cd"
111
+ "gitHead": "7aaaa24d63c807bb0d45155b58a197e225549352"
112
112
  }
@@ -0,0 +1,200 @@
1
+ import { expect, fixture } from '@open-wc/testing'
2
+ import { html } from 'lit'
3
+
4
+ import '../src/tools/ox-page-action-context-bar.js'
5
+ import '../src/tools/ox-page-action-overlay-template.js'
6
+ import { arrangePageActions, configurePageActions, PageAction, pageActionRunner, roleOf } from '../src/tools/page-action.js'
7
+
8
+ /**
9
+ * The page action contract (FOOTER-BUTTON-REVIEW F01 F02 F04 F05 F09 F10): the bar keeps every action reachable in the
10
+ * room its parent gives, the main action stays, 「더보기」 draws an action as the bar does, and a run is shared.
11
+ */
12
+
13
+ type Bar = HTMLElement & { renderRoot: ShadowRoot; updateComplete: Promise<unknown>; actions: PageAction[]; requestUpdate(): void }
14
+
15
+ const settle = async (el: Bar, rounds = 4) => {
16
+ for (let i = 0; i < rounds; i++) {
17
+ await new Promise(resolve => setTimeout(resolve, 60))
18
+ await el.updateComplete
19
+ }
20
+ }
21
+
22
+ async function barIn(width: number, actions: PageAction[]) {
23
+ const host = await fixture(
24
+ html`<div style="display:flex; justify-content:flex-end; overflow:hidden; width:${width}px"><ox-page-action-context-bar .actions=${actions}></ox-page-action-context-bar></div>`
25
+ )
26
+ const el = host.querySelector('ox-page-action-context-bar') as Bar
27
+ await settle(el)
28
+ return { host: host as HTMLElement, el }
29
+ }
30
+
31
+ const LONG = [
32
+ { title: '차수 관리 열기와 아주 긴 번역 문구', action: () => {} },
33
+ { title: '거래처로 등록', action: () => {} },
34
+ { title: '실적 배분', action: () => {} },
35
+ { title: '저장', icon: 'save', action: () => {}, emphasis: { raised: true } }
36
+ ]
37
+
38
+ describe('동작 줄 — 부모 폭으로 넘침을 잰다 (F01)', () => {
39
+ for (const width of [320, 360, 390, 768]) {
40
+ it(`${width}px: 잘린 단추가 없고 주 동작이 보이며 나머지는 더보기로 닿는다`, async () => {
41
+ const { host, el } = await barIn(width, LONG)
42
+ const box = host.getBoundingClientRect()
43
+ const buttons = Array.from(el.renderRoot.querySelectorAll('[container] > button')) as HTMLElement[]
44
+ const shown = buttons.filter(one => getComputedStyle(one).display !== 'none')
45
+ for (const one of shown) {
46
+ const rect = one.getBoundingClientRect()
47
+ expect(rect.left >= box.left - 0.5, `「${one.textContent?.trim()}」 왼쪽이 잘렸다`).to.equal(true)
48
+ expect(rect.right <= box.right + 0.5, `「${one.textContent?.trim()}」 오른쪽이 잘렸다`).to.equal(true)
49
+ }
50
+ const primary = shown.find(one => one.hasAttribute('raised'))
51
+ expect(primary, '주 동작이 보이지 않는다').to.not.equal(undefined)
52
+ if (shown.length < buttons.length) {
53
+ const more = el.renderRoot.querySelector('[more]') as HTMLElement
54
+ expect(more, '숨은 동작이 있는데 더보기가 없다').to.not.equal(null)
55
+ expect(more.getAttribute('tabindex')).to.equal('0')
56
+ expect(more.getBoundingClientRect().right <= box.right + 0.5).to.equal(true)
57
+ for (const one of shown) expect(one.getBoundingClientRect().right <= more.getBoundingClientRect().left + 0.5).to.equal(true)
58
+ }
59
+ })
60
+ }
61
+
62
+ it('부모가 넓어지면 숨겼던 동작을 다시 보인다', async () => {
63
+ const { host, el } = await barIn(320, LONG)
64
+ host.style.width = '1400px'
65
+ await settle(el, 6)
66
+ expect(el.renderRoot.querySelector('[more]')).to.equal(null)
67
+ expect(el.renderRoot.querySelectorAll('[container] > [overflowed]').length).to.equal(0)
68
+ })
69
+ })
70
+
71
+ describe('동작의 역할과 순서 (F02 F05)', () => {
72
+ afterEach(() => configurePageActions({ arrange: false, exclusive: false }))
73
+
74
+ it('삭제는 raised 여도 위험 보조, 저장은 주 동작이다', () => {
75
+ expect(roleOf({ title: '삭제', emphasis: { raised: true, danger: true } })).to.equal('danger')
76
+ expect(roleOf({ title: '저장', emphasis: { raised: true } })).to.equal('primary')
77
+ expect(roleOf({ title: '상신', priority: 'primary' })).to.equal('primary')
78
+ })
79
+
80
+ it('arrange: 위험 동작은 앞, 주 동작은 오른쪽 끝, 주 동작은 하나', () => {
81
+ configurePageActions({ arrange: true })
82
+ const arranged = arrangePageActions([
83
+ { title: '저장', emphasis: { raised: true } },
84
+ { title: '삭제', emphasis: { raised: true, danger: true } },
85
+ { title: '상신', emphasis: { raised: true } },
86
+ { title: '첨부' }
87
+ ])
88
+ expect(arranged.map(one => `${one.action.title}:${one.role}`)).to.deep.equal(['삭제:danger', '저장:secondary', '첨부:secondary', '상신:primary'])
89
+ })
90
+
91
+ it('기본(arrange 없음)은 선언 순서를 그대로 둔다', () => {
92
+ const arranged = arrangePageActions([{ title: 'a', emphasis: { raised: true } }, { title: 'b', emphasis: { danger: true } }])
93
+ expect(arranged.map(one => one.action.title)).to.deep.equal(['a', 'b'])
94
+ })
95
+ })
96
+
97
+ describe('더보기는 기본 줄과 같은 렌더러로 그린다 (F04)', () => {
98
+ it('주 동작·위험·비활성·이유·아이콘이 같다', async () => {
99
+ const actions: PageAction[] = [
100
+ { title: '삭제', icon: 'delete', emphasis: { danger: true }, action: () => {} },
101
+ { title: '발행', action: () => {}, disabled: true, disabledTitle: '먼저 저장하세요.' },
102
+ { title: '저장', icon: 'save', emphasis: { raised: true }, action: () => {} }
103
+ ]
104
+ const { el } = await barIn(1200, actions)
105
+ const overlay = (await fixture(html`<ox-page-action-overlay-template></ox-page-action-overlay-template>`)) as Bar
106
+ ;(overlay as any)._route = { context: { actions } }
107
+ overlay.requestUpdate()
108
+ await overlay.updateComplete
109
+ const describe = (root: ShadowRoot) =>
110
+ Array.from(root.querySelectorAll('button')).map(b => ({
111
+ text: b.textContent?.replace(/\s+/g, ' ').trim(),
112
+ raised: b.hasAttribute('raised'),
113
+ danger: b.hasAttribute('danger'),
114
+ ariaDisabled: b.getAttribute('aria-disabled'),
115
+ title: b.getAttribute('title')
116
+ }))
117
+ expect(describe(overlay.renderRoot)).to.deep.equal(describe(el.renderRoot))
118
+ expect(overlay.renderRoot.querySelector('md-assist-chip')).to.equal(null)
119
+ })
120
+ })
121
+
122
+ describe('실행 상태는 공유된다 (F09)', () => {
123
+ afterEach(() => configurePageActions({ exclusive: false }))
124
+
125
+ it('같은 동작은 진행 중에 다시 시작하지 않는다 — 기본 줄과 더보기 사이에서도', async () => {
126
+ let runs = 0
127
+ let release!: () => void
128
+ const action: PageAction = { id: 'save', title: '저장', action: () => (runs++, new Promise<void>(resolve => (release = resolve))) }
129
+ const { el } = await barIn(1200, [action])
130
+ const button = el.renderRoot.querySelector('button') as HTMLButtonElement
131
+ button.click()
132
+ await el.updateComplete
133
+ expect(button.getAttribute('aria-busy')).to.equal('true')
134
+ button.click()
135
+ pageActionRunner.run({ ...action })
136
+ expect(runs).to.equal(1)
137
+ release()
138
+ await new Promise(resolve => setTimeout(resolve, 10))
139
+ await el.updateComplete
140
+ expect(button.getAttribute('aria-busy')).to.equal('false')
141
+ })
142
+
143
+ it('끝난 뒤 disabled 를 풀지 않는다 — 진행 중 업무 조건이 바뀌면 그 조건을 따른다', async () => {
144
+ let release!: () => void
145
+ const make = (disabled: boolean): PageAction => ({ id: 'issue', title: '발행', disabled, action: () => new Promise<void>(resolve => (release = resolve)) })
146
+ const { el } = await barIn(1200, [make(false)])
147
+ ;(el.renderRoot.querySelector('button') as HTMLButtonElement).click()
148
+ await el.updateComplete
149
+ el.actions = [make(true)]
150
+ await el.updateComplete
151
+ release()
152
+ await new Promise(resolve => setTimeout(resolve, 10))
153
+ await el.updateComplete
154
+ const button = el.renderRoot.querySelector('button') as HTMLButtonElement
155
+ expect(button.disabled || button.getAttribute('aria-disabled') === 'true').to.equal(true)
156
+ })
157
+
158
+ it('exclusive: 한 동작이 도는 동안 다른 동작은 시작하지 않는다', async () => {
159
+ configurePageActions({ exclusive: true })
160
+ let release!: () => void
161
+ let submitted = 0
162
+ const save: PageAction = { id: 'save', title: '저장', action: () => new Promise<void>(resolve => (release = resolve)) }
163
+ const submit: PageAction = { id: 'submit', title: '상신', action: () => void submitted++ }
164
+ const { el } = await barIn(1200, [save, submit])
165
+ const [saveButton, submitButton] = Array.from(el.renderRoot.querySelectorAll('button')) as HTMLButtonElement[]
166
+ saveButton.click()
167
+ await el.updateComplete
168
+ expect(submitButton.disabled).to.equal(true)
169
+ submitButton.click()
170
+ expect(submitted).to.equal(0)
171
+ release()
172
+ await new Promise(resolve => setTimeout(resolve, 10))
173
+ await el.updateComplete
174
+ expect(submitButton.disabled).to.equal(false)
175
+ })
176
+
177
+ it('group: 같은 묶음끼리만 막는다', async () => {
178
+ let release!: () => void
179
+ const a: PageAction = { id: 'a', title: 'A', group: 'change', action: () => new Promise<void>(resolve => (release = resolve)) }
180
+ const b: PageAction = { id: 'b', title: 'B', group: 'change', action: () => {} }
181
+ const c: PageAction = { id: 'c', title: 'C', action: () => {} }
182
+ pageActionRunner.run(a)
183
+ expect(pageActionRunner.mayRun(b)).to.equal(false)
184
+ expect(pageActionRunner.mayRun(c)).to.equal(true)
185
+ release()
186
+ await new Promise(resolve => setTimeout(resolve, 10))
187
+ expect(pageActionRunner.mayRun(b)).to.equal(true)
188
+ })
189
+
190
+ it('이유가 있는 비활성 동작은 초점을 받고 누르면 실행하지 않는다', async () => {
191
+ let runs = 0
192
+ const { el } = await barIn(1200, [{ title: '발행', disabled: true, disabledTitle: '먼저 저장하세요.', action: () => void runs++ }])
193
+ const button = el.renderRoot.querySelector('button') as HTMLButtonElement
194
+ expect(button.disabled).to.equal(false)
195
+ expect(button.getAttribute('aria-disabled')).to.equal('true')
196
+ expect(button.title).to.equal('먼저 저장하세요.')
197
+ button.click()
198
+ expect(runs).to.equal(0)
199
+ })
200
+ })
@@ -13,7 +13,9 @@ const ACTIONS = ['edit', 'read status', 'remind again', 'withdraw post', 'duplic
13
13
  type Bar = HTMLElement & { renderRoot: ShadowRoot; updateComplete: Promise<unknown> }
14
14
 
15
15
  async function barOf(width: number) {
16
- const el = (await fixture(html`<ox-page-action-context-bar style="width:${width}px" .actions=${ACTIONS}></ox-page-action-context-bar>`)) as Bar
16
+ /* The bar sits in a toolbar part as wide as the room left (ox-context-toolbar #center); it measures that room. */
17
+ const host = await fixture(html`<div style="display:flex; justify-content:flex-end; width:${width}px"><ox-page-action-context-bar .actions=${ACTIONS}></ox-page-action-context-bar></div>`)
18
+ const el = host.querySelector('ox-page-action-context-bar') as Bar
17
19
  /* the measure runs on the next frame, throttled; then 「더보기」 renders and the marks are taken again */
18
20
  for (let i = 0; i < 4; i++) {
19
21
  await new Promise(resolve => setTimeout(resolve, 150))
@@ -32,7 +34,7 @@ describe('하단 동작 줄이 넘칠 때', () => {
32
34
  expect(more, '넘치는데 「더보기」가 없다').to.not.equal(null)
33
35
 
34
36
  const buttons = Array.from(el.renderRoot.querySelectorAll('[container] > button'))
35
- const shown = buttons.filter(one => getComputedStyle(one).visibility !== 'hidden')
37
+ const shown = buttons.filter(one => getComputedStyle(one).display !== 'none')
36
38
  expect(shown.length, '보이는 단추가 없다').to.be.greaterThan(0)
37
39
  expect(shown.length, '모두 보인다 - 넘침을 재지 못했다').to.be.lessThan(buttons.length)
38
40
  for (const one of shown) {